1 | <?php |
||
11 | class DotFunc extends DesmondFunction |
||
12 | { |
||
13 | use ArgumentHelper; |
||
14 | use TypeHelper; |
||
15 | |||
16 | 314 | public function id() |
|
20 | |||
21 | 7 | public function run(array $args) |
|
22 | { |
||
23 | 7 | $this->expectArguments( |
|
24 | 7 | '.func', |
|
25 | 7 | [0 => ['Symbol', 'String']], |
|
26 | 7 | $args |
|
27 | ); |
||
28 | 6 | $function = self::getFunction($args); |
|
29 | 5 | $args = self::getArgs($args); |
|
30 | |||
31 | // This is to capture warnings when you call PHP functions without all their args. |
||
32 | 5 | set_error_handler(function($errno, $errstr, $errfile, $errline) { |
|
33 | 1 | throw new RuntimeException($errstr); |
|
34 | 5 | }); |
|
35 | |||
36 | try { |
||
37 | 5 | $value = $function(...$args); |
|
38 | 2 | } catch (RuntimeException $error) { |
|
39 | 1 | throw new ArgumentException("\".func\": Too few arguments passed to $function."); |
|
40 | 1 | } catch (ArgumentCountError $error) { |
|
41 | 1 | throw new ArgumentException("\".func\": Too few arguments passed to $function."); |
|
42 | } |
||
43 | 3 | restore_error_handler(); |
|
44 | 3 | return self::fromPhpType($value); |
|
45 | } |
||
46 | |||
47 | 5 | private static function getArgs($args) |
|
56 | |||
57 | 6 | private static function getFunction(array $args) |
|
66 | } |
||
67 |