$invoker = new Invoker(function () { }); var_dump($invoker->canAccess()); class A { static function test1() { } private static function test2() { } static function test3() { return new Invoker('A::test2'); } } $invoker = new Invoker('A::test1'); var_dump($invoker->canAccess()); $invoker = A::test3(); var_dump($invoker->canAccess()); $invoker(); $invoker = new Invoker('A::test2'); ?> --EXPECTF-- bool(true) bool(true) bool(true) bool(false) Recoverable error: Argument 1 passed to php\lang\Invoker::__construct() must be of the type callable, string given, called in %s on line %d, position %d and defined in Unknown on line %d, position %d
--FILE-- <?php use php\lang\Invoker; $invoker = Invoker::of('var_dump'); var_dump($invoker->getDescription()); $invoker = Invoker::of(function ($a, array $b, callable $c, Invoker $d, $f = 'foobar') { }); var_dump($invoker->getDescription()); function test($x, $y) { } $invoker = Invoker::of('test'); var_dump($invoker->getDescription()); class A { function test(array $x) { } } $invoker = Invoker::of('A::test'); var_dump($invoker->getDescription()); $invoker = Invoker::of([new A(), 'test']); var_dump($invoker->getDescription()); ?> --EXPECTF-- string(20) "var_dump(<internal>)" string(69) "Closure::__invoke($a, array $b, callable $c, php\lang\Invoker $d, $f)" string(12) "test($x, $y)" string(17) "A::test(array $x)" string(17) "A::test(array $x)"
$invoker = new Invoker('var_dump'); echo "--check-named-function\n"; var_dump($invoker->isClosure(), $invoker->isDynamicCall(), $invoker->isNamedFunction(), $invoker->isStaticCall()); class A { static function foo() { } function bar() { } } $invoker = new Invoker(['A', 'foo']); echo "--check-static-call\n"; var_dump($invoker->isClosure(), $invoker->isDynamicCall(), $invoker->isNamedFunction(), $invoker->isStaticCall()); $invoker = new Invoker([new A(), 'bar']); echo "--check-dynamic-call\n"; var_dump($invoker->isClosure(), $invoker->isDynamicCall(), $invoker->isNamedFunction(), $invoker->isStaticCall()); ?> --EXPECT-- --check-closure bool(true) bool(false) bool(false) bool(false) --check-named-function bool(false) bool(false) bool(true) bool(false) --check-static-call
<?php use php\lang\Invoker; $invoker = Invoker::of('unknown'); var_dump($invoker); $invoker = Invoker::of('var_dump'); var_dump($invoker); class A { private static function test1() { echo "success\n"; } public static function test2(Invoker $invoker) { $invoker(); } } $invoker = Invoker::of('A::test1'); var_dump($invoker); var_dump("can_access=" . ($invoker->canAccess() ? 'true' : 'false')); A::test2($invoker); ?> --EXPECTF-- NULL object(php\lang\Invoker)#%d (0) { } object(php\lang\Invoker)#%d (0) { } string(16) "can_access=false" success
--TEST-- Invoker basic test getArgumentCount() --FILE-- <?php use php\lang\Invoker; $invoker = new Invoker(function ($a, $b, $c = 20) { }); var_dump($invoker->getArgumentCount()); function test($a, $b) { } $invoker = new Invoker('test'); var_dump($invoker->getArgumentCount()); class foobar { function test($a, $b, $c) { } } $invoker = new Invoker(['foobar', 'test']); var_dump($invoker->getArgumentCount()); ?> --EXPECT-- int(3) int(2) int(3)