2017 © Pedro Peláez
 

library tactician-container-selfhandling

Container-Aware Self-Handling commands for Tactician Command Bus

image

spekkionu/tactician-container-selfhandling

Container-Aware Self-Handling commands for Tactician Command Bus

  • Saturday, December 23, 2017
  • by spekkionu
  • Repository
  • 1 Watchers
  • 1 Stars
  • 199 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 197 % Grown

The README.md

Tactician Container-Aware Self-Handling Commands

Latest Stable Version Build Status License Code Coverage Scrutinizer Code Quality SensioLabsInsight, (*1)

Install

Via Composer, (*2)

``` bash $ composer require spekkionu/tactician-container-selfhandling, (*3)


If you want to use the container aware commands you will also need to install `league/container` ## Usage ### Add MiddleWare ``` php use League\Tactician\CommandBus; use Spekkionu\Tactician\SelfExecuting\SelfExecutionMiddleware; $commandBus = new CommandBus([ // any other pre-execution middleware new SelfExecutionMiddleware(), // other middleware to handle non-self-executing commands // any other post-execution middleware ]);

Create a Command

Your commands must implement Spekkionu\Tactician\SelfExecuting\SelfExecutingCommand and have a handle() method., (*4)

The handle method must have no parameters., (*5)

``` php use Spekkionu\Tactician\SelfExecuting\SelfExecutingCommand;, (*6)

/** * Class ExampleSelfExecutingCommand */ class ExampleSelfExecutingCommand implements SelfExecutingCommand { /** * @return string */ public function handle() { // do work here } }, (*7)


### Run Command ``` php $commandBus->handle(new ExampleSelfExecutingCommand());

Container-Aware Self-Executing Commands

Container aware commands will have dependencies injected into the handle() method from league/container., (*8)

``` php use League\Container\Container; use League\Tactician\CommandBus; use Spekkionu\Tactician\SelfExecuting\SelfExecutionMiddleware;, (*9)

// Setup the Container $container = new Container(); $container->delegate( new \League\Container\ReflectionContainer ); $container->add('Logger', function() { return new Logger(); });, (*10)

// Setup the command bus $commandBus = new CommandBus([ // any other pre-execution middleware new ContainerAwareSelfExecutionMiddleware($container), // other middleware to handle non-self-executing commands // any other post-execution middleware ]);, (*11)


``` php use Spekkionu\Tactician\SelfExecuting\SelfExecutingCommand; /** * Class ExampleSelfExecutingCommand */ class ExampleSelfExecutingCommand implements SelfExecutingCommand { /** * The logger will be injected automatically * @return string */ public function handle(Logger $logger) { $logger->log('log message'); } }

``` php $commandBus->handle(new ExampleSelfExecutingCommand());, (*12)


## Testing ``` bash $ composer test

License

The MIT License (MIT). Please see License File for more information., (*13)

The Versions

23/12 2017

dev-master

9999999-dev

Container-Aware Self-Handling commands for Tactician Command Bus

  Sources   Download

MIT

The Requires

 

The Development Requires

22/12 2016

1.0.1

1.0.1.0

Container-Aware Self-Handling commands for Tactician Command Bus

  Sources   Download

MIT

The Requires

 

The Development Requires

26/10 2016

1.0.0

1.0.0.0

Container-Aware Self-Handling commands for Tactician Command Bus

  Sources   Download

MIT

The Requires

 

The Development Requires