kodcube / invoker
Build and Invoke Classes
0.1.1
2016-07-19 08:54 UTC
Requires
- php: >=7.0.0
- container-interop/container-interop: ~1.1
- kodcube/helpers: ^0.1
Requires (Dev)
- phpunit/phpunit: ~4.5
This package is not auto-updated.
Last update: 2024-12-20 23:30:13 UTC
README
This can construct & call a method on a passed passed classname::method string.
This library is great for command bus, event bus or message bus processing, where by just passing a class name and method as a string can be instanciated and executed.
Usage & Examples
Construct
$invoker = new KodCube\Invoker\Invoker();
Callable Object
$invoker = new KodCube\Invoker\Invoker(); $result = $invoker('MyClass');
is the same as
$class = new MyClass(); $result = $class();
Public Method on Object
$invoker = new KodCube\Invoker\Invoker(); $result = $invoker('MyClass::myMethod');
is the same as
$class = new MyClass(); $result = $class->myMethod();
Public Method on Object with constructor arguments
$invoker = new KodCube\Invoker\Invoker(); $result = $invoker('MyClass::myMethod',null,['arg1','arg2']);
is the same as
$class = new MyClass('arg1','arg2'); $result = $class->myMethod();
Public Method on Object with method arguments
$invoker = new KodCube\Invoker\Invoker(); $result = $invoker('MyClass::myMethod',['arg1','arg2']);
is the same as
$class = new MyClass(); $result = $class->myMethod('arg1','arg2');
Public Static Method
$invoker = new KodCube\Invoker\Invoker(); $result = $invoker('MyClass::myMethod');
is the same as
$result = MyClass::myMethod();