Laravel Brussels Meetup July 2015
Laravel Brussels Meetup July 2015
Jonathan Van Belle
aka
@Grummfy
Laravel Brussels Meetup July 2015
Laravel Brussels Meetup July 2015
What's command bus pattern
Laravel Brussels Meetup July 2015
What's command bus pattern
Laravel Brussels Meetup July 2015
What's command bus pattern
Bus
Command
Handlers
Bus : handle this command
Laravel Brussels Meetup July 2015
Advantages
Laravel Brussels Meetup July 2015
Drawback
Laravel Brussels Meetup July 2015
Alternative to this pattern
Laravel Brussels Meetup July 2015
Existing solution
Laravel Brussels Meetup July 2015
Existing solution
<?php
class CommandBus
{
protected $_handlers = array();
public function __construct($handlers)
{
$this->_handlers = $handlers;
}
public function handle($command)
{
$name = get_class($command);
if (!isset($this->_handlers[ $name ]))
{
throw new UnexpectedException('No handler for the given command ' . $name);
}
$this->_handlers[ $name ]->handle($command);
// only one => use decorator to make onion
}
}
Laravel Brussels Meetup July 2015
Existing solution
Laravel Brussels Meetup July 2015
With decorator (make an onion of handlers)
Laravel Brussels Meetup July 2015
Demo time
Laravel Brussels Meetup July 2015
Laravel Brussels Meetup July 2015