experus / commands
This package is abandoned and no longer maintained.
No replacement package was suggested.
A fluent and elegant way of using the command pattern in Laravel 5
1.0.0
2016-10-28 12:18 UTC
Requires
- php: >=5.5.9
- illuminate/contracts: >=5.1.0
- illuminate/support: >=5.1
Requires (Dev)
- phpunit/phpunit: ^5.3
This package is not auto-updated.
Last update: 2020-03-09 21:19:01 UTC
README
A fluent and elegant way of using the command pattern in Laravel 5.
Installation
-
Require the package from composer.
composer require experus/commands
-
Register your implementation of
Experus\Commands\Providers\CommandServiceProvider
. -
Add the
Experus\Commands\DispatchesCommands
trait to your controller or theApp\Http\Controllers\Controller
.
Usage
-
First create an implementation of the
Experus\Commands\Providers\CommandServiceProvider
.<?php namespace App\Providers; use Experus\Commands\Providers\CommandServiceProvider as ServiceProvider class CommandServiceProvider extends ServiceProvider { /** * @var array */ protected $mappings = [ \Foo\Command::class => \Foo\Bar\Handler::class, ]; }
-
Then in the class where you use the
Experus\Commands\DispatchesCommands
trait.public function __construct(Experus\Commands\Contracts\DispatcherInterface $dispatcher) { $this->setDispatcher($dispatcher); }
-
You can now dispatch commands like this
$this->execute(new \Foo\Command('Hello World!'));