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); } }
public function onDispatch(DispatchEvent $event) { $request = $event->getContext()->getRequest(); $baseUri = $request->getBaseUrl(); $uri = $request->getRequestUri(); if (!empty($baseUri) && \strpos($uri, $baseUri) === 0) { $uri = \substr($uri, strlen($baseUri)); } if (strpos($uri, '?') !== false) { list($uri, ) = explode('?', $uri); } elseif (empty($uri)) { $uri = '/'; } $route = $event->getApplication()->getServices()->get($this->serviceName)->getRoute($uri); if (!$route instanceof Route) { return; } $actionName = $route->getActionName(); if (!$event->getApplication()->exists($actionName)) { throw new Exception(sprintf("Unknown action '%s'", $actionName)); } foreach ($route->getParameters() as $param) { $request->query->set($param->getName(), $param->getValueOrDefault()); } $event->getContext()->setActionName($actionName); }