Install from composer:
composer require zhikiri/command-handler
Usage example here:
$handler = new Handler(); $handler->group('main/', function () { $this->add('command, function () { // some stuff here }); });
This initialization make available action path:
main/command
Notice: Sub groups also available
Initialize commands group with some middleware actions:
$handler = new Handler(); $handler->middleware( [ function () { // middleware will execute before command }, ], function () { // group and command initialization here }, [ function () { // middleware will execute after command }, ], );
Add new middleware:
$middleware = new Middleware(); $middleware->your_middleware = function () { // your middleware action code here }; $handler = new Handler(); $handler->middleware( [ $middleware->your_middleware ], function () { $this-add('command', function () { // this action will execute after middleware `your_middleware` }); }, [] );