Skip to content

Instantly share code, notes, and snippets.

@petersuhm
Created March 1, 2015 18:39
Show Gist options
  • Save petersuhm/82332482b770531dcb76 to your computer and use it in GitHub Desktop.
Save petersuhm/82332482b770531dcb76 to your computer and use it in GitHub Desktop.
Command handler locator for Tactician (http://tactician.thephpleague.com/).
<?php
namespace WpShipper\Handlers\Commands;
use Illuminate\Foundation\Application;
use League\Tactician\Command;
use League\Tactician\Handler\Locator\HandlerLocator;
class LaravelHandlerLocator implements HandlerLocator
{
/**
* @var Application
*/
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Retrieves the handler for a specified command
*
* @param Command $command
* @return mixed
*/
public function getHandlerForCommand(Command $command)
{
$commandClass = get_class($command);
$handlerClass = str_replace('Commands', 'Handlers\Commands', $commandClass) . 'Handler';
return $this->app->make($handlerClass);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment