/** * Router * * Requests are not made to methods directly The request will be for an "object". * this simply maps the object and method to the correct Controller method. * * @param string * @param array */ public function router($resource, array $arguments) { \Config::load('rest', true); // If no (or an invalid) format is given, auto detect the format if (is_null($this->format) or !array_key_exists($this->format, $this->_supported_formats)) { // auto-detect the format $this->format = array_key_exists(\Input::extension(), $this->_supported_formats) ? \Input::extension() : $this->_detect_format(); } //Check method is authorized if required if (\Config::get('rest.auth') == 'basic') { $valid_login = $this->_prepare_basic_auth(); } elseif (\Config::get('rest.auth') == 'digest') { $valid_login = $this->_prepare_digest_auth(); } //If the request passes auth then execute as normal if (\Config::get('rest.auth') == '' or $valid_login) { // If they call user, go to $this->post_user(); $controller_method = strtolower(\Input::method()) . '_' . $resource; // Fall back to action_ if no rest method is provided if (!method_exists($this, $controller_method)) { $controller_method = 'action_' . $resource; } // If method is not available, set status code to 404 if (method_exists($this, $controller_method)) { return call_user_func_array(array($this, $controller_method), $arguments); } else { $this->response->status = $this->no_method_status; return; } } else { $this->response(array('status' => 0, 'error' => 'Not Authorized'), 401); } }
public function action_index() { $ext = Input::extension(); Log::info('500:' . Input::uri() . '.' . $ext); $this->response_status = 500; $this->template->content = View_Smarty::forge('500'); }
public function action_file($size = null, $file_cate = null, $split_num = null, $file_name = null) { $file_name = sprintf('%s.%s', $file_name, Input::extension()); $config = array('type' => 'file', 'file_cate' => $file_cate, 'split_num' => $split_num, 'size' => $size, 'file_name' => $file_name); $file = new Site_FileMaker($config); if (!($data = $file->get_data())) { throw new HttpNotFoundException(); } $ext = $file->get_extension(); $accept_exts = conf('upload.types.file.accept_format'); return Response::forge($data, 200, array('Content-Type' => $accept_exts[$ext])); }
public function action_index() { $ext = Input::extension(); Log::info('404:' . Input::uri() . '.' . $ext); // コンテンツの場合は404を返す $ext = Input::extension(); if (in_array($ext, array('png', 'jpg', 'jpeg', 'gif', 'js', 'css', 'aspx', 'xml', 'json'))) { header('HTTP/1.1 404 Not Found'); exit; } $this->response_status = 404; $this->template->content = View_Smarty::forge('404'); }
/** * Routes controller requests. * * Differences from parent: fixes a bug for custom auth method and adds custom no auth error. * * @param string $resource Controller action name. * @param array $arguments Arguments. * * @return mixed */ public function router($resource, $arguments) { \Config::load('rest', true); // If no (or an invalid) format is given, auto detect the format if (is_null($this->format) or !array_key_exists($this->format, $this->_supported_formats)) { // auto-detect the format $this->format = array_key_exists(\Input::extension(), $this->_supported_formats) ? \Input::extension() : $this->_detect_format(); } // Get the configured auth method if none is defined $this->auth === null and $this->auth = \Config::get('rest.auth'); //Check method is authorized if required, and if we're authorized if ($this->auth == 'basic') { $valid_login = $this->_prepare_basic_auth(); } elseif ($this->auth == 'digest') { $valid_login = $this->_prepare_digest_auth(); } elseif (method_exists($this, $this->auth)) { $valid_login = $this->{$this->auth}(); if ($valid_login instanceof \Response) { return $valid_login; } } else { $valid_login = false; } // If the request passes auth then execute as normal if (empty($this->auth) or $valid_login) { // If they call user, go to $this->post_user(); $controller_method = strtolower(\Input::method()) . '_' . $resource; // Fall back to action_ if no rest method is provided if (!method_exists($this, $controller_method)) { $controller_method = 'action_' . $resource; } // If method is not available, set status code to 404 if (method_exists($this, $controller_method)) { return call_user_func_array(array($this, $controller_method), $arguments); } else { $this->response->status = $this->no_method_status; return; } } else { $this->response(array('message' => 'Missing or Invalid Authorization'), 401); } }
/** * Parses a route match and returns the controller, action and params. * * @access public * @param string The matched route * @return object $this */ public function matched($uri = '', $named_params = array()) { // Clean out all the non-named stuff out of $named_params foreach ($named_params as $key => $val) { if (is_numeric($key)) { unset($named_params[$key]); } } $this->named_params = $named_params; if ($this->translation instanceof \Closure) { $this->callable = $this->translation; } else { $path = $this->translation; if ($uri != '') { if ($this->strip_extension) { strpos($uri, $ext = \Input::extension()) === false or $uri = substr($uri, 0, -(strlen($ext) + 1)); } if ($this->case_sensitive) { $path = preg_replace('#^' . $this->search . '$#uD', $this->translation, $uri); } else { $path = preg_replace('#^' . $this->search . '$#uiD', $this->translation, $uri); } } $this->segments = explode('/', trim($path, '/')); } return $this; }
/** * Parses a route match and returns the controller, action and params. * * @access public * @param string The matched route * @return object $this */ public function matched($uri = '', $named_params = array()) { // Clean out all the non-named stuff out of $named_params foreach ($named_params as $key => $val) { if (is_numeric($key)) { unset($named_params[$key]); } } $this->named_params = $named_params; if ($this->translation instanceof \Closure) { $this->callable = $this->translation; } else { $path = $this->translation; if ($uri != '') { // strip the extension if needed and there is something to strip if ($this->strip_extension and strrchr($uri, '.') == ($ext = '.' . \Input::extension())) { $uri = substr($uri, 0, -strlen($ext)); } if ($this->case_sensitive) { $path = preg_replace('#^' . $this->search . '$#uD', $this->translation, $uri); } else { $path = preg_replace('#^' . $this->search . '$#uiD', $this->translation, $uri); } } $this->segments = explode('/', trim($path, '/')); } return $this; }
/** * Get the current base path, stopping at the given segment number */ protected function getImagePath($startSegment) { $segments = \Uri::segments(); $startSegment = min($startSegment, count($segments)); return implode('/', array_slice($segments, $startSegment)) . '.' . \Input::extension(); }