/** * Set request route * * Takes an array of URI segments as input and sets the callable method * to be called. * * @access private * @param array $segments URI segments * @return object */ protected function setRequest($segments = array()) { if (!static::isBlocked()) { $method = $this->x_default_view; if (!empty($segments)) { if (is_array($segments) && is_callable(reset($segments))) { $method = reset($segments); } elseif (is_callable($segments)) { $method = $segments; } } if ($this->x_is_no_match) { Response::setStatus(404); $method = $this->x_default_notfound; } if (!is_callable($method)) { Response::setStatus(500); $method = $this->x_default_500; } } else { // blocked is same as 404 Response::setStatus(404); static::setNotfound(); $method = $this->x_default_blocked; } $this->x_method = $method; // end benchmark Benchmark::set('route', 'end'); return $this; }
/** * Default error 500 output Handler */ public static function error500() { $args_ = func_get_args(); $template = Template::singleton(); $template_dir = $template->getActiveTemplateDirectory(); static::$x_is_fatal = true; if ($template_dir && $template->x_500_file && is_string($template->x_500_file)) { if (is_file("{$template_dir}/{$template->x_500_file}")) { $message = (array) reset($args_); // using callback to prevent direct access return call_user_func(function ($a) use($message) { ob_start(); require $a; $content = ob_get_clean(); Response::setBody($content); static::displayRender(); exit(1); // and then exit here }, "{$template_dir}/{$template->x_500_file}"); } } /** * Body container * @var string */ $body = "<h1 class=\"big\">500</h1>\n"; if (Config::get('debug', true)) { $args_ = current($args_); $strlen_doc_root = strlen(Path::documentRoot()); // safe output show replaced document root to {DOCUMENT ROOT} $args_['file'] = substr_replace($args_['file'], '<span class="x_error_doc_root">{DOCUMENT ROOT}</span>', 0, $strlen_doc_root); $body .= " <div class=\"x_error_section\">\n" . " <table class=\"x_error_table\">\n" . " <tr class=\"x_error_type\">\n" . " <td class=\"x_error_label\"><span>Error Type</span></td>\n" . " <td class=\"x_error_value\"><span><span class=\"x_error_type_code\">{$args_['type']}</span>" . "<span class=\"x_error_type_string\">{$args_['type_string']}</span></span></td>\n" . " </tr>\n" . " <tr class=\"x_error_message\">\n" . " <td class=\"x_error_label\"><span>Error Message</span></td>\n" . " <td class=\"x_error_value\"><span>{$args_['message']}</span></td>\n" . " </tr>\n" . " <tr class=\"x_error_file\">\n" . " <td class=\"x_error_label\"><span>Error File</span></td>\n" . " <td class=\"x_error_value\"><span>{$args_['file']}</span></td>\n" . " </tr>\n" . " <tr class=\"x_error_line\">\n" . " <td class=\"x_error_label\"><span>Error Line</span></td>\n" . " <td class=\"x_error_value\"><span>{$args_['line']}</span></td>\n" . " </tr>\n" . " </table>\n" . " </div>\n"; } else { $body .= "<h2 class=\"desc\">Internal Server Error</h2>\n" . "<p>We are sorry for inconvenience</p>"; } /** * Set Body */ Response::setBody(Html::create('Internal Server Error', $body, array('style' => "body{font-size: 14px;font-family: helvetica, arial, sans-serif;color: #555;line-height: normal;background: #f1f1f1;}\n" . ".wrap{margin: 0 auto;max-width: 700px;text-align: center;}\n" . (Config::get('debug', false) ? ".x_error_section{display:block;padding: 10px;background: #fff;border: 1px solid #ddd;}\n" . ".x_error_table{border-collapse: collapse;border:0;border-spacing:0;}\n" . ".x_error_label{padding: 5px 10px;text-align: left;border-right: 2px solid #bbb;}\n" . ".x_error_value{padding: 5px 10px;text-align: left;border-right: 0px solid #ddd;}\n" . ".x_error_type .x_error_type_string{background: #f18181;padding: 3px 5px;color:#fff;font-weight: bold;margin-left:0px;}\n" . ".x_error_type .x_error_type_code{background: #4359fe;margin-right: 0px;padding: 3px 6px;color:#fff;font-weight: bold;}\n" : '') . ".big{font-size: 180px;margin: .7em 0 20px;}\n.desc{font-size: 28px;margin: .3em 0 0;}"))); // doing display static::displayRender(); exit(1); // and then exit here }
/** * Set HTTP cookie to be sent with the HTTP response * * @param string $name The cookie name * @param string $value The cookie value * @param int|string $expires The duration of the cookie; * If integer, should be UNIX timestamp; * If string, converted to UNIX timestamp with `strtotime`; * @param string $path The path on the server in which the cookie will be available on * @param string $domain The domain that the cookie is available to * @param bool $secure Indicates that the cookie should only be transmitted over a secure * HTTPS connection to/from the client * @param bool $httponly When TRUE the cookie will be made accessible only through the HTTP protocol * @param bool $encrypted When TRUE the cookie will be made as encrypted */ public static function set($name, $value, $expires = null, $path = null, $domain = null, $secure = null, $httponly = null, $encrypted = null) { $settings = array('value' => $value, 'expires' => is_null($expires) ? Config::get('cookie_lifetime') : $expires, 'path' => is_null($path) ? Config::get('cookie_path', '/') : $path, 'domain' => is_null($domain) ? Config::get('cookie_domain', null) : $domain, 'secure' => is_null($secure) ? Config::get('cookie_secure', false) : $secure, 'httponly' => is_null($httponly) ? Config::get('cookie_httponly', false) : $httponly, 'encrypted' => $encrypted); $cookies = Response::cookies(); $cookies->set($name, $settings); }
/** * PHP5 Constructor */ public function __construct() { parent::__construct(); $this->cookies = new Collector\Collector(Response::parseCookieHeader(Header::get('HTTP_COOKIE'))); }