txiki / callback
Simple callback manager for PHP
0.1.0
2015-02-26 17:16 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-12-21 17:48:38 UTC
README
Simple callback manager for PHP
Install
Via Composer
$ composer require txiki/callback
Requirements
The following versions of PHP are supported by this version.
- PHP 5.4
- PHP 5.5
- PHP 5.6
- HHVM
Documentation
Simple examples:
require '../vendor/autoload.php'; use Txiki\Callback\Call; use Txiki\Callback\CallableObject; class DummyClass{ public function myMethod($foo, $bar) { return 'Out '.$foo.' - '.$bar; } } $cObject = new CallableObject( 'DummyClass::myMethod' , ['foor', 'bar']); // return 'Out foo - bar'; echo $result = Call::dispatch($cObject);
$a = 'extra'; $cObject = new CallableObject( function($foo, $bar) use ($a) { return 'Out '.$foo.' - '.$bar.' - '.$a; } , ['foor', 'bar'] ); // return 'Out foor - bar - extra'; echo $result = Call::dispatch($cObject);
Implements ICallable interface to convert your own object on a CallableObject:
use Txiki\Callback\ICallable; class MyObject implements ICallable { public function myMethod() { } public function getCallable() { return function($id){ echo 'ok '.$id; }; } public function getParams() { return [999]; } } // return 'ok 999' echo Call::dispatch(new MyObject());
Testing
$ vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.