public function onDispatch(DispatchEvent $event) { if (!$this->isCli()) { return; } $container = $event->getApplication()->getServices(); $cmsService = $event->getApplication()->getServices()->get($this->cmsService); $cfg = $cmsService->getSiteConfig(); if (!isset($cfg['commands']) || !is_array($cfg['commands'])) { return; } $app = $this->getConsoleApplication($container); $cmsService->initClassLoader(); foreach ($cfg['commands'] as $command) { $def = new ClassDefinition($command); $cmd = $def->invoke($container); if ($cmd instanceof ContextAware) { $cmd->setContext($event->getContext()); } if ($cmd instanceof ServicesAware) { $cmd->setServices($container); } if ($cmd instanceof Preparable) { call_user_func_array(array($cmd, Preparable::PREPARE_METHOD)); } $app->add($cmd); } }
/** * * @param CoreEvent $event * * @see AppEvents::DISPATCH * @return void */ public function onDescriptorLoaded(DescriptorLoadedEvent $event) { if (!$this->isCli()) { return; } $commands = array(); $map = $this->getCommandsXmlMap(); foreach ($event->getDescriptor()->getSourcesXml() as $xml) { $parse = $map->execute($xml); $res = isset($parse['commands']) ? $parse['commands'] : array(); $commands = array_merge($commands, $res); } $app = $this->getConsoleApplication($event->getApplication()->getServices()); foreach ($commands as $name => $command) { $def = new ClassDefinition($event->getDescriptor()->propertizeString($command['class']), array($name)); $cmd = $def->invoke($event->getApplication()->getServices()); if ($cmd instanceof ContextAware) { $cmd->setContext($event->getContext()); } if ($cmd instanceof ServicesAware) { $cmd->setServices($event->getApplication()->getServices()); } if ($cmd instanceof Preparable) { call_user_func_array(array($cmd, Preparable::PREPARE_METHOD)); } $app->add($cmd); } }
public function onDescriptorLoaded(DescriptorLoadedEvent $event) { $this->descriptor = $event->getDescriptor(); $service = $event->getApplication()->getServices()->get($this->serviceName); $types = array(); $map = $this->xmlResultsTypesMapFactory(); foreach ($event->getDescriptor()->getSourcesXml() as $xml) { $this->descriptor->set('packageDir', dirname($xml->getRealPath())); $parse = $map->execute($xml); $res = isset($parse['types']) ? $parse['types'] : array(); $types = array_merge($types, $res); } foreach ($types as $typeName => $type) { $def = new ClassDefinition($event->getDescriptor()->propertizeString($type['class']), array($type['params'])); $service->addType($typeName, $def->invoke($event->getApplication()->getServices())); } $this->descriptor->set('packageDir', null); }
public function loadPlugins(Container $container) { $plugins = array(); $xml = array(); $map = $this->xmlPluginsMapFactory(); foreach ($this->sources as $source) { $parse = $map->execute($this->getSourceXml($source)); $res = isset($parse['plugins']) ? $parse['plugins'] : array(); $xml = array_merge($xml, $res); } foreach ($xml as $data) { $finalParams = array(); foreach ($data['params'] as $paramData) { $finalParams[$paramData['name']] = $paramData['value']; } if (isset($data['class']) && !empty($data['class'])) { $def = new ClassDefinition($this->propertizeString($data['class']), $finalParams); $plugins[] = $def->invoke($container); } elseif (isset($data['service']) && !empty($data['service'])) { $plugins[] = $container->get($data['service']); } else { throw new Exception('You must specify attribute "class" or "service" for plugin'); } } return $plugins; }