コード例 #1
0
ファイル: ConsoleListener.php プロジェクト: fwk/core
 /**
  *
  * @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);
     }
 }
コード例 #2
0
ファイル: ResultTypeListener.php プロジェクト: fwk/core
 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);
 }
コード例 #3
0
ファイル: UrlRewriterListener.php プロジェクト: fwk/core
 public function onDescriptorLoaded(DescriptorLoadedEvent $event)
 {
     $results = array();
     $map = $this->xmlRewritesMapFactory($event->getDescriptor());
     foreach ($event->getDescriptor()->getSourcesXml() as $xml) {
         $parse = $map->execute($xml);
         $res = isset($parse['rewrites']) ? $parse['rewrites'] : array();
         $results = array_merge($results, $res);
     }
     $rewriter = $event->getApplication()->getServices()->get($this->serviceName);
     $it = 0;
     foreach ($results as $url) {
         $it++;
         $roote = new Route($event->getDescriptor()->propertizeString($url['action']), $event->getDescriptor()->propertizeString($url['route']));
         foreach ($url['params'] as $paramName => $param) {
             $required = $param['required'];
             $regex = $param['regex'];
             $default = $param['value'];
             if ($required == 'true' || $required == '1' || empty($required)) {
                 $required = true;
             } elseif ($required == 'false' || $required == '0') {
                 $required = false;
             }
             $roote->addParameter(new RouteParameter($paramName, $default, $regex, $required));
         }
         $rewriter->addRoute($roote);
     }
 }