Beispiel #1
0
 public function onComponentConfigRegistration(Kernel $kernel, ConfigInterface $config, $sourceComponentName, $targetComponentName, array $registeredConfig)
 {
     // Makes no sense to register commands on a SAPI different than the CLI
     if (php_sapi_name() !== 'cli') {
         return;
     }
     if (isset($registeredConfig['commands'])) {
         if (!is_array($registeredConfig['commands'])) {
             throw InvalidConfigException::create('commands', 'an array of commands configurations.');
         }
         $config->merge('components.ironedge/cli.commands', $registeredConfig['commands'], []);
     }
 }
Beispiel #2
0
 /**
  * Application constructor.
  *
  * @param array $applicationOptions - Application Options.
  *
  * @throws InvalidConfigException
  */
 public function __construct(array $applicationOptions = [])
 {
     if ($this->isKernelComponentInstalled()) {
         $kernel = $this->getKernel();
         $appName = $kernel->getComponentConfigParam('ironedge/cli', 'application.name');
         $appVersion = $kernel->getComponentConfigParam('ironedge/cli', 'application.version');
     } else {
         $appName = 'Default Application';
         $appVersion = '0.1';
     }
     $this->_applicationOptions = array_replace_recursive(['applicationName' => $appName, 'applicationVersion' => $appVersion, 'commands' => []], $applicationOptions);
     parent::__construct($this->_applicationOptions['applicationName'], $this->_applicationOptions['applicationVersion']);
     $this->addCommands($this->_applicationOptions['commands']);
     if ($this->isKernelComponentInstalled()) {
         $kernel = $this->getKernel();
         $this->setDispatcher($kernel->getEventDispatcher());
         $commands = $kernel->getComponentConfigParam('ironedge/cli', 'commands', []);
         foreach ($commands as $commandData) {
             $command = null;
             if (isset($commandData['disabled']) && $commandData['disabled']) {
                 continue;
             }
             if (isset($commandData['serviceId'])) {
                 if (!is_string($commandData['serviceId'])) {
                     throw InvalidConfigException::create('serviceId', 'a string. This parameter is the service ID of the command.');
                 }
                 $command = $kernel->getContainerService($commandData['serviceId']);
             } else {
                 if (isset($commandData['class'])) {
                     if (!is_string($commandData['class'])) {
                         throw InvalidConfigException::create('class', 'a string. This parameter is the class of the command.');
                     }
                     $commandClass = $commandData['class'];
                     $command = new $commandClass();
                 }
             }
             if (!$command) {
                 throw InvalidConfigException::create(null, null, 'You must enter, for each command, a parameter "class" or "serviceId".');
             }
             $this->add($command);
         }
     }
 }