Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
Inheritance: extends Config
Ejemplo n.º 1
0
 public static function addConfiguration(ApplicationConfig $config, AssetPlugin $plugin)
 {
     $config->beginCommand('asset')->setDescription('Manage web assets')->setHandler(function () use($plugin) {
         return new AssetCommandHandler($plugin->getAssetManager(), $plugin->getInstallationManager(), $plugin->getInstallTargetManager());
     })->beginSubCommand('map')->addArgument('path', Argument::REQUIRED, 'The resource path')->addArgument('web-path', Argument::REQUIRED, 'The path in the web directory')->addOption('target', 't', Option::REQUIRED_VALUE | Option::PREFER_LONG_NAME, 'The name of the installation target', InstallTarget::DEFAULT_TARGET)->addOption('force', 'f', Option::NO_VALUE, 'Map even if the target does not exist')->setHandlerMethod('handleMap')->end()->beginSubCommand('update')->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the mapping')->addOption('path', null, Option::REQUIRED_VALUE, 'The resource path')->addOption('web-path', null, Option::REQUIRED_VALUE, 'The path in the web directory')->addOption('target', 't', Option::REQUIRED_VALUE | Option::PREFER_LONG_NAME, 'The name of the installation target', InstallTarget::DEFAULT_TARGET)->addOption('force', 'f', Option::NO_VALUE, 'Update even if the target does not exist')->setHandlerMethod('handleUpdate')->end()->beginSubCommand('remove')->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the mapping')->setHandlerMethod('handleRemove')->end()->beginSubCommand('list')->markDefault()->setHandlerMethod('handleList')->end()->beginSubCommand('install')->addArgument('target', Argument::OPTIONAL, 'The target to install. By default, all targets are installed')->setHandlerMethod('handleInstall')->end()->end()->beginCommand('target')->setDescription('Manage the install targets of your web resources')->setHandler(function () use($plugin) {
         return new TargetCommandHandler($plugin->getInstallTargetManager());
     })->beginSubCommand('list')->markDefault()->setHandlerMethod('handleList')->end()->beginSubCommand('add')->addArgument('name', Argument::REQUIRED, 'The name of the added target')->addArgument('location', Argument::REQUIRED, 'The location where the web resources are installed')->addOption('installer', null, Option::REQUIRED_VALUE, 'The name of the used installer', 'symlink')->addOption('url-format', null, Option::REQUIRED_VALUE, 'The format of the generated resource URLs', InstallTarget::DEFAULT_URL_FORMAT)->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Additional parameters to store with the target')->setHandlerMethod('handleAdd')->end()->beginSubCommand('update')->addArgument('name', Argument::REQUIRED, 'The name of the updated target')->addOption('location', null, Option::REQUIRED_VALUE, 'The location where the web resources are installed')->addOption('installer', null, Option::REQUIRED_VALUE, 'The name of the used installer', 'symlink')->addOption('url-format', null, Option::REQUIRED_VALUE, 'The format of the generated resource URLs', InstallTarget::DEFAULT_URL_FORMAT)->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Additional parameters to store with the target')->addOption('unset-param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Parameters to remove from the target')->setHandlerMethod('handleUpdate')->end()->beginSubCommand('remove')->addArgument('name', Argument::REQUIRED, 'The name of the target to remove')->setHandlerMethod('handleRemove')->end()->beginSubCommand('set-default')->addArgument('name', Argument::REQUIRED, 'The name of the default target')->setHandlerMethod('handleSetDefault')->end()->beginSubCommand('get-default')->setHandlerMethod('handleGetDefault')->end()->end()->beginCommand('installer')->setDescription('Manage the installers used to install web resources')->setHandler(function () use($plugin) {
         return new InstallerCommandHandler($plugin->getInstallerManager());
     })->beginSubCommand('list')->markDefault()->addOption('long', 'l', Option::NO_VALUE, 'Print the fully-qualified class name')->setHandlerMethod('handleList')->end()->beginSubCommand('add')->addArgument('name', Argument::REQUIRED, 'The name of the installer')->addArgument('class', Argument::REQUIRED, 'The fully-qualified class name of the installer')->addOption('description', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'The description of the installer')->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Additional installer parameters')->setHandlerMethod('handleAdd')->end()->beginSubCommand('remove')->addArgument('name', Argument::REQUIRED, 'The name of the installer to remove')->setHandlerMethod('handleRemove')->end()->end();
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function run(RawArgs $args = null, InputStream $inputStream = null, OutputStream $outputStream = null, OutputStream $errorStream = null)
 {
     // Render errors to the preliminary IO until the final IO is created
     $io = $this->preliminaryIo;
     try {
         if (null === $args) {
             $args = new ArgvArgs();
         }
         $ioFactory = $this->config->getIOFactory();
         if (null === $ioFactory) {
             throw new LogicException('The IO factory must be set.');
         }
         /** @var IO $io */
         $io = call_user_func($ioFactory, $this, $args, $inputStream, $outputStream, $errorStream);
         $resolvedCommand = $this->resolveCommand($args);
         $command = $resolvedCommand->getCommand();
         $parsedArgs = $resolvedCommand->getArgs();
         $statusCode = $command->handle($parsedArgs, $io);
     } catch (Exception $e) {
         if (!$this->config->isExceptionCaught()) {
             throw $e;
         }
         $trace = new ExceptionTrace($e);
         $trace->render($io);
         $statusCode = $this->exceptionToExitCode($e->getCode());
     }
     if ($this->config->isTerminatedAfterRun()) {
         exit($statusCode);
     }
     return $statusCode;
 }
Ejemplo n.º 3
0
 public function testLenientArgsParsingDefaultsToApplicationValue()
 {
     $this->applicationConfig->enableLenientArgsParsing();
     $this->assertTrue($this->config->isLenientArgsParsingEnabled());
     $this->applicationConfig->disableLenientArgsParsing();
     $this->assertFalse($this->config->isLenientArgsParsingEnabled());
 }
Ejemplo n.º 4
0
 public function testDoNotRethrowParseErrorIfLenient()
 {
     $config = ApplicationConfig::create()->beginCommand('package')->enableLenientArgsParsing()->end();
     $application = new ConsoleApplication($config);
     $command = $application->getCommand('package');
     $rawArgs = new StringArgs('package --foo');
     $resolvedCommand = $this->resolver->resolveCommand($rawArgs, $application, true);
     $args = new Args($command->getArgsFormat(), $rawArgs);
     $this->assertSame($command, $resolvedCommand->getCommand());
     $this->assertEquals($args, $resolvedCommand->getArgs());
 }
Ejemplo n.º 5
0
 public function testDispatchConfigEvent()
 {
     $config = $this->config;
     $dispatched = false;
     $this->config->addEventListener(ConsoleEvents::CONFIG, function (ConfigEvent $event) use($config, &$dispatched) {
         PHPUnit_Framework_Assert::assertSame($config, $event->getConfig());
         $dispatched = true;
     });
     $this->assertFalse($dispatched);
     new ConsoleApplication($this->config);
     $this->assertTrue($dispatched);
 }
Ejemplo n.º 6
0
 public function testCreate()
 {
     $config = ApplicationConfig::create()->setName('test-bin')->setDisplayName('Test Name')->setVersion('1.2.3')->setHelperSet($helperSet = new HelperSet())->beginCommand('command')->end();
     $application = new ConsoleApplication($config);
     $adapter = new ApplicationAdapter($application);
     $this->assertSame('Test Name', $adapter->getName());
     $this->assertSame('1.2.3', $adapter->getVersion());
     $this->assertSame('<info>Test Name</info> version <comment>1.2.3</comment>', $adapter->getLongVersion());
     $this->assertSame('<info>Test Name</info> version <comment>1.2.3</comment>', $adapter->getHelp());
     $this->assertSame($helperSet, $adapter->getHelperSet());
     $this->assertSame(array(), $adapter->getNamespaces());
     $this->assertEquals(new ArgsFormatInputDefinition($application->getGlobalArgsFormat()), $adapter->getDefinition());
     $commandAdapter = new CommandAdapter($application->getCommand('command'), $adapter);
     $commandAdapter->setApplication($adapter);
     $commandAdapter->setHelperSet($helperSet);
     $this->assertEquals($commandAdapter, $adapter->get('command'));
 }
Ejemplo n.º 7
0
    public function testRenderOptionCommandWithPreferredLongName()
    {
        $config = ApplicationConfig::create()->setName('test-bin')->beginCommand('command')->beginOptionCommand('add', 'a')->setDescription('Description of "add"')->setPreferLongName()->end()->end();
        $application = new ConsoleApplication($config);
        $help = new CommandHelp($application->getCommand('command'));
        $help->render($this->io);
        $expected = <<<'EOF'
USAGE
      test-bin command
  or: test-bin command --add

COMMANDS
  --add (-a)
    Description of "add"


EOF;
        $this->assertSame($expected, $this->io->fetchOutput());
    }
Ejemplo n.º 8
0
 public function testHasCommandConfigs()
 {
     $this->assertFalse($this->config->hasCommandConfigs());
     $this->config->addCommandConfig($config = new CommandConfig());
     $this->assertTrue($this->config->hasCommandConfigs());
 }
Ejemplo n.º 9
0
    public function testRenderDescription()
    {
        $config = ApplicationConfig::create()->setHelp('The help');
        $application = new ConsoleApplication($config);
        $help = new ApplicationHelp($application);
        $help->render($this->io);
        $expected = <<<'EOF'
Console Tool

USAGE
  console <command> [<arg1>] ... [<argN>]

ARGUMENTS
  <command>  The command to execute
  <arg>      The arguments of the command

DESCRIPTION
  The help


EOF;
        $this->assertSame($expected, $this->io->fetchOutput());
    }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 protected function getDefaultLenientArgsParsing()
 {
     return $this->applicationConfig ? $this->applicationConfig->isLenientArgsParsingEnabled() : parent::getDefaultLenientArgsParsing();
 }