-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathArrayOfCallable.php
49 lines (43 loc) · 1.8 KB
/
ArrayOfCallable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
/**
* This file is part of the Linna Typed ArrayObject.
*
* @author Sebastian Rapetti <sebastian.rapetti@tim.it>
* @copyright (c) 2018, Sebastian Rapetti
* @license http://opensource.org/licenses/MIT MIT License
*/
namespace Linna\TypedArrayObject;
use ArrayIterator;
use InvalidArgumentException;
/**
* Provide a way to create an array of callable typed elements with php.
*
* @link https://www.php.net/manual/en/functions.first_class_callable_syntax.php
*/
class ArrayOfCallable extends AbstractArray
{
/**
* It overrides parent message.
*
* @var string Exception message.
*/
protected string $exceptionMessage = 'Elements passed must be of the type <callable>.';
/**
* Class Contructor.
*
* @param array<callable> $input Array of values, every value must be a <code>callable</code>.
* @param int $flags Flags to control the behaviour of the <code>ArrayObject</code> object,
* see <code>ArrayObject</code> on php site.
* @param class-string $iterator_class Specify the class that will be used for iteration of the <code>ArrayObject</code>
* object, the class must implement <code>ArrayIterator</code>.
*
* @throws InvalidArgumentException If elements in the optional array parameter aren't of the configured type.
*/
public function __construct(array $input = [], int $flags = 0, string $iterator_class = ArrayIterator::class)
{
// first argument is the php8.1 method to pass function reference as closure.
// check https://www.php.net/manual/en/functions.first_class_callable_syntax.php
parent::__construct(is_callable(...), $input, $flags, $iterator_class);
}
}