public function resolve(Command $command)
    {
        $commandName = get_class($command);

        // Find the CommandHandler if it has been manually defined using pushHandler()
        foreach ($this->handlers as $handlerCommand => $handler) {
            if ($handlerCommand == $commandName) {
                return $handler;
            }
        }

        // If the Command also implements CommandHandler, then it can handle() itself
        if ($command instanceof CommandHandler) {
            return $command;
        }

        // Try and guess the handler's name in the same namespace with suffix "Handler"
        $class = $commandName . 'Handler';
        if (class_exists($class)) {
            return $this->container->make($class);
        }

        // Try and guess the handler's name in nested "Handlers" namespace with suffix "Handler"
        $classParts = explode('\\', $commandName);
        $commandNameWithoutNamespace = array_pop($classParts);
        $class = implode('\\', $classParts) . '\\Handlers\\' . $commandNameWithoutNamespace . 'Handler';
        if (class_exists($class)) {
            return $this->container->make($class);
        }

        throw new UnresolvableCommandHandlerException('Could not resolve a handler for [' . get_class($command) . ']');
    }
public function resolve(Command $command)
    {
        $commandName = get_class($command);

        // Find the CommandHandler if it has been manually defined using pushHandler()
        foreach ($this->handlers as $handlerCommand => $handler) {
            if ($handlerCommand == $commandName) {
                return $handler;
            }
        }

        // If the Command also implements CommandHandler, then it can handle() itself
        if ($command instanceof CommandHandler) {
            return $command;
        }

        // Try and guess the handler's name in the same namespace with suffix "Handler"
        $class = $commandName . 'Handler';
        if (class_exists($class)) {
            return $this->container->make($class);
        }

        // Try and guess the handler's name in nested "Handlers" namespace with suffix "Handler"
        $classParts = explode('\\', $commandName);
        $commandNameWithoutNamespace = array_pop($classParts);
        $class = implode('\\', $classParts) . '\\Handlers\\' . $commandNameWithoutNamespace . 'Handler';
        if (class_exists($class)) {
            return $this->container->make($class);
        }

        throw new UnresolvableCommandHandlerException('Could not resolve a handler for [' . get_class($command) . ']');
    }
public function resolve ( Command $ command ) { $ commandName = get_class ( $ command ) ; // Find the CommandHandler if it has been manually defined using pushHandler() foreach ( $ this -> handlers as $ handlerCommand => $ handler ) { if ( $ handlerCommand == $ commandName ) { return $ handler ; } } // If the Command also implements CommandHandler, then it can handle() itself if ( $ command instanceof CommandHandler ) { return $ command ; } // Try and guess the handler's name in the same namespace with suffix "Handler" $ class = $ commandName . 'Handler' ; if ( class_exists ( $ class ) ) { return $ this -> container -> make ( $ class ) ; } // Try and guess the handler's name in nested "Handlers" namespace with suffix "Handler" $ classParts = explode ( '\\' , $ commandName ) ; $ commandNameWithoutNamespace = array_pop ( $ classParts ) ; $ class = implode ( '\\' , $ classParts ) . '\\Handlers\\' . $ commandNameWithoutNamespace . 'Handler' ; if ( class_exists ( $ class ) ) { return $ this -> container -> make ( $ class ) ; } throw new UnresolvableCommandHandlerException ( 'Could not resolve a handler for [' . get_class ( $ command ) . ']' ) ; }
Retrieve a CommandHandler for a given Command

@param Command $command
@return CommandHandler
@throws UnresolvableCommandHandlerException
Retrieve a CommandHandler for a given Command