Returns the application configuration.
public getConfig ( ) : |
||
return | The application configuration. |
public static function setUpBeforeClass() { while (false === @mkdir(self::$tempDir = sys_get_temp_dir() . '/puli-cli/AbstractCommandHandlerTest' . rand(10000, 99999), 0777, true)) { } self::$application = new ConsoleApplication(new PuliApplicationConfig(new Puli(self::$tempDir))); self::$formatter = new PlainFormatter(self::$application->getConfig()->getStyleSet()); }
public static function setUpBeforeClass() { while (false === @mkdir(self::$tempDir = sys_get_temp_dir() . '/puli-web-plugin/AbstractCommandHandlerTest' . rand(10000, 99999), 0777, true)) { } $puli = new Puli(self::$tempDir); $config = new PuliApplicationConfig($puli); $plugin = new AssetPlugin(); $plugin->activate($puli); self::$application = new ConsoleApplication($config); self::$formatter = new PlainFormatter(self::$application->getConfig()->getStyleSet()); }
/** * @param Application $application * @param RawArgs $args * @param InputStream|null $inputStream * @param OutputStream|null $outputStream * @param OutputStream|null $errorStream * * @return ConsoleIO */ public function createIO(Application $application, RawArgs $args, InputStream $inputStream = null, OutputStream $outputStream = null, OutputStream $errorStream = null) { $inputStream = $inputStream ?: new StandardInputStream(); $outputStream = $outputStream ?: new StandardOutputStream(); $errorStream = $errorStream ?: new ErrorOutputStream(); $styleSet = $application->getConfig()->getStyleSet(); if ($args->hasToken('--no-ansi')) { $outputFormatter = $errorFormatter = new PlainFormatter($styleSet); } elseif ($args->hasToken('--ansi')) { $outputFormatter = $errorFormatter = new AnsiFormatter($styleSet); } else { $outputFormatter = $outputStream->supportsAnsi() ? new AnsiFormatter($styleSet) : new PlainFormatter($styleSet); $errorFormatter = $errorStream->supportsAnsi() ? new AnsiFormatter($styleSet) : new PlainFormatter($styleSet); } $io = new ConsoleIO(new Input($inputStream), new Output($outputStream, $outputFormatter), new Output($errorStream, $errorFormatter)); if ($args->hasToken('-vvv') || $this->isDebug()) { $io->setVerbosity(IO::DEBUG); } elseif ($args->hasToken('-vv')) { $io->setVerbosity(IO::VERY_VERBOSE); } elseif ($args->hasToken('-v')) { $io->setVerbosity(IO::VERBOSE); } if ($args->hasToken('--quiet') || $args->hasToken('-q')) { $io->setQuiet(true); } if ($args->hasToken('--no-interaction') || $args->hasToken('-n')) { $io->setInteractive(false); } return $io; }
public function testHandleDispatchesEvent() { $args = new Args(new ArgsFormat()); $io = $this->getMockBuilder('Webmozart\\Console\\Api\\IO\\IO')->disableOriginalConstructor()->getMock(); $handler = $this->getMock('stdClass', array('handle')); $this->application->getConfig()->addEventListener(ConsoleEvents::PRE_HANDLE, function (PreHandleEvent $event) { $event->setHandled(true); $event->setStatusCode(123); }); $config = new CommandConfig('command'); $config->setHandler($handler); $command = new Command($config, $this->application); $handler->expects($this->never())->method('handle'); $this->assertSame(123, $command->handle($args, $io)); }
/** * Renders the "Usage" section. * * @param BlockLayout $layout The layout. * @param Application $application The application to describe. * @param ArgsFormat $argsFormat The format of the console arguments. */ protected function renderUsage(BlockLayout $layout, Application $application, ArgsFormat $argsFormat) { $appName = $application->getConfig()->getName(); $layout->add(new Paragraph('<b>USAGE</b>')); $layout->beginBlock(); $this->renderSynopsis($layout, $argsFormat, $appName); $layout->endBlock(); $layout->add(new EmptyLine()); }
/** * {@inheritdoc} */ protected function getDefaultHelperSet() { return $this->adaptedApplication->getConfig()->getHelperSet(); }
/** * Creates a new command. * * @param CommandConfig $config The command configuration. * @param Application $application The console application. * @param Command $parentCommand The parent command. * * @throws LogicException If the name of the command configuration is not set. */ public function __construct(CommandConfig $config, Application $application = null, Command $parentCommand = null) { if (!$config->getName()) { throw new LogicException('The name of the command config must be set.'); } $this->name = $config->getName(); $this->shortName = $config instanceof OptionCommandConfig ? $config->getShortName() : null; $this->aliases = $config->getAliases(); $this->config = $config; $this->application = $application; $this->parentCommand = $parentCommand; $this->subCommands = new CommandCollection(); $this->namedSubCommands = new CommandCollection(); $this->defaultSubCommands = new CommandCollection(); $this->argsFormat = $config->buildArgsFormat($this->getBaseFormat()); $this->dispatcher = $application ? $application->getConfig()->getEventDispatcher() : null; foreach ($config->getSubCommandConfigs() as $subConfig) { $this->addSubCommand($subConfig); } }
private function getPageName(Application $application, Args $args) { if ($args->isArgumentSet('command')) { $command = $application->getCommand($args->getArgument('command')); return $this->commandPagePrefix . $command->getName(); } if ($this->applicationPage) { return $this->applicationPage; } return $application->getConfig()->getName(); }