| 1 | <?php |
||
| 6 | |||
| 7 | final class FixedArityFn implements FixedArityInterface |
||
| 8 | { |
||
| 9 | private int $arity; |
||
|
|
|||
| 10 | |||
| 11 | /** |
||
| 12 | * @var callable |
||
| 13 | */ |
||
| 14 | private $fn; |
||
| 15 | |||
| 16 | private function __construct(int $arity, callable $fn) |
||
| 17 | { |
||
| 18 | $this->arity = $arity; |
||
| 19 | $this->fn = $fn; |
||
| 20 | } |
||
| 21 | |||
| 22 | public function getArity(): int |
||
| 23 | { |
||
| 24 | return $this->arity; |
||
| 25 | } |
||
| 26 | |||
| 27 | public static function of(int $arity, callable $fn): self |
||
| 28 | { |
||
| 29 | return new static($arity, $fn); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param array<int, mixed> ...$args |
||
| 34 | * @return mixed |
||
| 35 | */ |
||
| 36 | public function __invoke(...$args) |
||
| 37 | { |
||
| 38 | return call_user_func_array($this->fn, array_slice($args, 0, $this->arity)); |
||
| 39 | } |
||
| 41 |