/** * Builds an standard Sifo url. * * @param string $hostname The hostname of the url to be built. Must be a key in the url.config. * @param string $controller The controller part of the url as defined in the router. Must be a key in the url.config. * @param array $actions An array of parameters that will be available in the $params['path_parts'] array. * @param array $params Url parameters that will be available in the $params['params'] array. * @return string A sifo url. */ public static function buildUrl($hostname, $controller, array $actions = array(), array $params = array()) { $url = Urls::getUrl($hostname) . '/'; $callback = function ($a) { return urlencode($a); }; $actions = array_map($callback, $actions); array_unshift($actions, Urls::getUrl($controller)); $url .= implode(self::$url_definition['context_separator'], $actions); if (array() !== $params) { $url .= self::$url_definition['params_separator']; } $url .= implode(self::$url_definition['params_separator'], $params); return $url; }
/** * Dispatches an error after an exception. * * @param Exception $e * * @return output buffer */ private static function _dispatchErrorController($e) { if (!isset($e->http_code)) { $e->http_code = 503; $e->http_code_msg = 'Exception!'; $e->redirect = false; } header('HTTP/1.0 ' . $e->http_code . ' ' . $e->http_code_msg); // Execute ErrorCommonController when an exception is captured. $ctrl2 = self::invokeController('error/common'); // Set params: $ctrl2->addParams(array('code' => $e->http_code, 'code_msg' => $e->http_code_msg, 'msg' => $e->getMessage(), 'trace' => $e->getTraceAsString())); // All the SEO_Exceptions with need of redirection have this attribute: if ($e->redirect) { // Path is passed via message: $path = trim($e->getMessage(), '/'); $new_location = ''; // Check if the URL for the redirection has already a protocol, like http:// , https://, ftp://, etc.. if (false !== strpos($path, '://')) { // Absolute path passed: $new_location = $path; } else { // Relative path passed, use path as the key in url.config.php file: $new_location = Urls::getUrl($path); } if (empty($new_location) || false == $new_location) { trigger_error("Exception " . $e->http_code . " raised with an empty location " . $e->getTraceAsString()); header('HTTP/1.0 500 Internal Server Error'); exit; } if (!Domains::getInstance()->getDebugMode()) { header("Location: " . $new_location, true, $e->http_code); } else { $ctrl2->addParams(array('url_redirect' => $new_location)); $ctrl2->dispatch(); self::invokeController('debug/index')->dispatch(); return; } } $result = $ctrl2->dispatch(); // Load the debug in case you have enabled the has debug flag. if (Domains::getInstance()->getDebugMode()) { self::invokeController('debug/index')->dispatch(); } return $result; }