/** * Test for isMember method. */ public function testIsMember() { $application = new Application(); $mainCommand = new HelloCommand(); $mainCommand->setApplication($application); $application->add($mainCommand); $memberCommand = new HiCommand(); $memberCommand->setApplication($application); $application->add($memberCommand); $this->manager->init($application); static::assertEquals(true, $this->manager->isMember('bar:hi')); static::assertEquals(false, $this->manager->isMember('foo:hello')); static::assertEquals(false, $this->manager->isMember('some:other')); }
/** * Disabling runs members of chains and launching chains of commands. * * @param ConsoleCommandEvent $event */ public function onConsoleCommand(ConsoleCommandEvent $event) { $command = $event->getCommand(); $commandName = $command->getName(); $application = $command->getApplication(); if (!$this->manager->isInitialized()) { $this->manager->init($application); } if ($this->manager->isMember($commandName)) { $event->disableCommand(); $event->stopPropagation(); $mainCommands = $this->manager->getMainCommands($commandName); $event->getOutput()->writeln(sprintf('<error>Error: "%s" command is a member of %s command%s chain and cannot be executed on its own.</error>', $commandName, implode(', ', array_map(function ($name) { return '"' . $name . '"'; }, $mainCommands)), count($mainCommands) > 1 ? 's' : '')); } if ($this->manager->hasChains($commandName)) { $this->manager->runChain($command, $event->getInput()); $event->disableCommand(); $event->stopPropagation(); } }