Webmozart\Console\ConsoleApplication::resolveCommand PHP Method

resolveCommand() public method

public resolveCommand ( Webmozart\Console\Api\Args\RawArgs $args )
$args Webmozart\Console\Api\Args\RawArgs
    public function resolveCommand(RawArgs $args)
    {
        if ($this->dispatcher && $this->dispatcher->hasListeners(ConsoleEvents::PRE_RESOLVE)) {
            $event = new PreResolveEvent($args, $this);
            $this->dispatcher->dispatch(ConsoleEvents::PRE_RESOLVE, $event);
            if ($resolvedCommand = $event->getResolvedCommand()) {
                return $resolvedCommand;
            }
        }
        return $this->config->getCommandResolver()->resolveCommand($args, $this);
    }

Usage Example

 public function testResolveCommandDispatchesEvent()
 {
     $args = new StringArgs('');
     $resolver = $this->getMock('Webmozart\\Console\\Api\\Resolver\\CommandResolver');
     $resolvedCommand = $this->getMockBuilder('Webmozart\\Console\\Api\\Resolver\\ResolvedCommand')->disableOriginalConstructor()->getMock();
     $this->config->setCommandResolver($resolver);
     $this->config->addEventListener(ConsoleEvents::PRE_RESOLVE, function (PreResolveEvent $event) use($resolvedCommand) {
         $event->setResolvedCommand($resolvedCommand);
     });
     $application = new ConsoleApplication($this->config);
     $resolver->expects($this->never())->method('resolveCommand');
     $this->assertSame($resolvedCommand, $application->resolveCommand($args));
 }