Neos\Flow\Cli\CommandManager::getCommandByIdentifier PHP Méthode

getCommandByIdentifier() public méthode

If no Command could be found a CommandNotFoundException is thrown If more than one Command matches an AmbiguousCommandIdentifierException is thrown that contains the matched Commands
public getCommandByIdentifier ( string $commandIdentifier ) : Command
$commandIdentifier string command identifier in the format foo:bar:baz
Résultat Command
    public function getCommandByIdentifier($commandIdentifier)
    {
        $commandIdentifier = strtolower(trim($commandIdentifier));
        if ($commandIdentifier === 'help') {
            $commandIdentifier = 'neos.flow:help:help';
        }
        if ($commandIdentifier === 'sys') {
            $commandIdentifier = 'neos.flow:cache:sys';
        }
        $matchedCommands = $this->getCommandsByIdentifier($commandIdentifier);
        if (count($matchedCommands) === 0) {
            throw new NoSuchCommandException('No command could be found that matches the command identifier "' . $commandIdentifier . '".', 1310556663);
        }
        if (count($matchedCommands) > 1) {
            throw new AmbiguousCommandIdentifierException('More than one command matches the command identifier "' . $commandIdentifier . '"', 1310557169, null, $matchedCommands);
        }
        return current($matchedCommands);
    }

Usage Example

 /**
  * @test
  */
 public function ifCommandCantBeResolvedTheHelpScreenIsShown()
 {
     // The following call is only made to satisfy PHPUnit. For some weird reason PHPUnit complains that the
     // mocked method ("getObjectNameByClassName") does not exist _if the mock object is not used_.
     $this->mockObjectManager->getObjectNameByClassName('Acme\\Test\\Command\\DefaultCommandController');
     $this->mockCommandManager->getCommandByIdentifier('acme.test:default:list');
     $mockCommandManager = $this->createMock(Cli\CommandManager::class);
     $mockCommandManager->expects($this->any())->method('getCommandByIdentifier')->with('test:default:list')->will($this->throwException(new NoSuchCommandException()));
     $this->requestBuilder->injectCommandManager($mockCommandManager);
     $request = $this->requestBuilder->build('test:default:list');
     $this->assertSame(HelpCommandController::class, $request->getControllerObjectName());
 }
All Usage Examples Of Neos\Flow\Cli\CommandManager::getCommandByIdentifier