Beispiel #1
0
 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);
     }
 }
Beispiel #2
0
 public function loadServices(Container $container)
 {
     // the ViewHelper
     $defViewHelper = new ClassDefinition('Nitronet\\Fwk\\Assetic\\AssetViewHelper', array($this->cfg('serviceName', 'assetic'), 'url', $this->cfg('debug', false), $this->cfg('action')));
     $container->set('assetic.ViewHelper', $defViewHelper, true);
     // filter manager
     $defFilterManager = new ClassDefinition('Assetic\\FilterManager');
     $container->set('assetic.FilterManager', $defFilterManager, true);
     // cssrewrite filter
     if ($this->cfg('cssrewrite', true) === true) {
         $defCssRewriteFilter = new ClassDefinition('Nitronet\\Fwk\\Assetic\\Filters\\CssRewriteFilter', array('@assetic.ViewHelper'));
         $container->set('assetic.CssRewriteFilter', $defCssRewriteFilter, true);
         $defFilterManager->addMethodCall('set', array('cssrewrite', '@assetic.CssRewriteFilter'));
     }
     // asset factory
     $defAssetFactory = new ClassDefinition('Assetic\\Factory\\AssetFactory', array($this->cfg('directory', null), $this->cfg('debug', false)));
     $defAssetFactory->addMethodCall('setFilterManager', array('@assetic.FilterManager'));
     $container->set('assetic.AssetFactory', $defAssetFactory, true);
     // service
     $defService = new ClassDefinition('Nitronet\\Fwk\\Assetic\\AssetsService', array('@assetic.AssetFactory'));
     $defService->addMethodCall('addShortcuts', array($this->shortcuts));
     $container->set($this->cfg('serviceName', 'assetic'), $defService, true);
     // caching
     if ($this->cfg('cache', false) === true) {
         $defFilesystemCache = new ClassDefinition('Assetic\\Cache\\FilesystemCache', array($this->cfg('cacheDir', sys_get_temp_dir())));
         $container->set('assetic.FilesystemCache', $defFilesystemCache, true);
         $defCacheBustingWorker = new ClassDefinition('Assetic\\Factory\\Worker\\CacheBustingWorker', array($this->cfg('cacheStrategy', 'content')));
         $container->set('assetic.CacheBustingWorker', $defCacheBustingWorker, true);
         $defAssetFactory->addMethodCall('addWorker', array('@assetic.CacheBustingWorker'));
         $defService->addArgument('@assetic.FilesystemCache');
         $defService->addArgument($this->cfg('cacheDir', sys_get_temp_dir()));
     }
     $container->setProperty('asseticServiceName', $this->cfg('serviceName', 'assetic'));
 }
Beispiel #3
0
 /**
  *
  * @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);
     }
 }
Beispiel #4
0
 /**
  * Apply Plugin's services to the existing Container
  *
  * @param Container $container App's Services Container
  *
  * @return void
  */
 public function loadServices(Container $container)
 {
     $definition = new ClassDefinition('\\Fwk\\Core\\Components\\ResultType\\ResultTypeService', array(), true);
     foreach ($this->types as $name => $type) {
         $definition->addMethodCall('addType', array($name, $type));
     }
     $container->set(self::SERVICE_NAME, $definition, true);
 }
Beispiel #5
0
 /**
  * Apply Plugin's services to the existing Container
  *
  * @param Container $container App's Services Container
  *
  * @return void
  */
 public function loadServices(Container $container)
 {
     $definition = new ClassDefinition('\\Fwk\\Core\\Components\\ViewHelper\\ViewHelperService', array($this->propName, $this->throwExceptions), true);
     foreach ($this->helpers as $name => $helper) {
         $definition->addMethodCall('add', array($name, $helper));
     }
     $container->set(self::SERVICE_NAME, $definition, true);
 }
Beispiel #6
0
 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);
 }
Beispiel #7
0
 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;
 }