public static function exceptionHandler(\Exception $e) { $fullTrace = $e->getTrace(); if (is_callable(array($e, 'postAction'))) { $e->postAction($e->getMessage(), $e->getCode()); } if (!DC::getProjectConfig('devMode')) { DC::getLogger()->add('Exception: ' . $e->getMessage(), 'exception'); die; } $content = '<div style="font-size: 13px; font-family: Consolas, Menlo, Monaco, monospace;white-space: pre-wrap;">'; $htmlTrace = "<b>\nLast arguments(" . count($fullTrace[0]['args']) . "):</b>\n" . dumpAsString($fullTrace[0]['args']) . "<b>\n\nCall stack:</b>\n<table style='font-size: 13px;'>"; foreach ($fullTrace as $item) { $info = self::compileShortCallee($item); $htmlTrace .= '<tr><td style="color:#666;padding-right:10px;">' . $info['file'] . '</td><td>' . $info['call'] . '</td></tr>'; } $htmlTrace .= '</table>'; $content .= '<div style="background:#c00;color:white;font-weight:bold;padding:5px;margin-bottom: 5px; ">' . $e->getMessage() . '</div>'; $content .= $htmlTrace; $content .= '</div>'; if (DC::getRouter()->getExecutionMode() == Request::MODE_CONSOLE) { $content = strip_tags(str_replace('</td><td>', "\n", $content)) . "\n"; } echo $content; die; }
public function forwardToRoute($routeName, $vars = null) { if ($route = DC::getRouter()->getRoute($routeName)) { DC::getRouter()->setCurrentRoute($route)->getCurrentRequest()->setUri($route->buildUri($vars)); $route = new ApplicationRoute($route); DC::getApplication()->setRoute($route); ControllerService::processControllerAction($route->getControllerName(), $route->getActionName()); } }
public function onKernelReady(BaseEvent $event) { $this->onEnvironmentUpdate($event); if ($webRoot = DC::getProjectConfig('webRoot')) { DC::getEnvironment()->setWebRoot($webRoot); } $databaseConfig = DC::getDatabaseConfig(); $request = DC::getRouter()->getCurrentRequest(); if ($profiles = $databaseConfig->get('profiles')) { foreach ($profiles as $profileName => $profileInfo) { DatabaseService::configProfile($profileInfo, $profileName); } if (empty($request) || $request && !$request->isConsoleRequest()) { ModelOperator::getInstance(DC::getEnvironment()->getUserClassesRoot() . 'db/'); if ($databaseConfig->get('autoUpdateAll')) { ModelOperator::getInstance()->generateAllModelClasses()->updateDBForAllModels(); } } } }
public function detectApplication() { DC::getEventDispatcher()->dispatchEvent('route.buildRequest', Request::getIncomeRequest()); /** * @var ArrayStorage $appList */ $appList = DC::getProjectConfig('applications'); if (empty($appList)) { throw new \Exception('Empty application list'); } $defaultAppName = DC::getProjectConfig('defaultApplication', 'frontend'); $this->_name = $defaultAppName; $uri = (string) Request::getIncomeRequest()->getUri(); $uriParts = explode('/', $uri); $webRoot = DC::getRouter()->getWebRoot(); if (strlen($webRoot) > 1) { if (strpos($uri, substr($webRoot, 1)) === 0) { $uriParts = explode('/', substr($uri, strlen($webRoot))); } } if (!empty($uriParts) && (count($uriParts) > 0 && $uriParts[0] != '/')) { foreach ($appList as $appName => $appParams) { if ($appName == $defaultAppName) { continue; } $appUri = !empty($appParams['uri']) ? $appParams['uri'] : $appName; if (strpos($uriParts[0], $appUri) === 0) { array_shift($uriParts); Request::getIncomeRequest()->setUri((strlen($webRoot) > 1 ? $webRoot . '/' : '') . implode('/', $uriParts)); $this->_name = $appName; break; } } } $this->_config = DC::getProjectConfig('applications/' . $this->_name); if (!is_array($this->_config)) { $this->_config = array('uri' => $this->_name); } if (empty($this->_config['path'])) { $this->_config['path'] = Inflector::camelize($this->_name) . '/'; } $this->_namespace = Inflector::camelize($this->_name); $this->_root = DC::getEnvironment()->getApplicationRoot() . $this->_config['path']; DC::getAutoloader()->registerNamespacePath($this->_namespace, DC::getEnvironment()->getApplicationRoot()); ControllerService::setActiveNamespace($this->_namespace); return $this->_name; }
public static function onUnauthenticated(BaseEvent $event) { DC::getRouter()->redirectToRelativeUri('admin/'); }
public function getCombinedVars($format = null) { if (!$format) { $format = $this->_responseFormat; } $combinedVars = new ArrayStorage($this->_vars); if ($this->_formatVars->has($format)) { $combinedVars->extendDeepValue($this->_formatVars->get($format)); } if ($format == View::FORMAT_HTML) { $combinedVars['_baseUri'] = DC::getRouter()->getBaseUri(); } return $combinedVars; }