Menu


Commands


EventBus


Other Packages

Papertrail

Handler Resolving


The handler resolver takes the name of the handler from the command bus translator and builds an instance of it.

interface CommandHandlerResolver
{
    /**
     * @param string $className     The command handler class name
     * @return mixed                Instance of the command Handler
     */
    public function make($className);
}

The command bus relies on a implementation of the CommandHandlerResolver interface. Which simple takes the handlers name and build an instance of it.

This is a perfect place for a Inversion of control (IoC) container to build an instance.

Example


Simple Method

We Have provided a very simple handler build but this is mainly for demonstrates as it lakes any ability for dependency injection. SmoothPhp\CommandBus\SimpleCommandHandlerResolver

public function make($className){
    return new $className;
}

Laravel Method

A more useful implementation would be to have an IOC resolve the handler. A quick example of the laravel one

    public function make($className)
    {
        return app($className);
    }

The actually laravel implementation can be seen here LaravelCommandBusHandlerResolver.php