public function __construct(\Request $request, \Response $response) { if ($this->force_this_main_template) { $this->main_template = $this->force_this_main_template; } else { if ($request->directory()) { $this->main_template = lcfirst($request->directory()); } } parent::__construct($request, $response); }
/** * @param int $total Total items * @param int $limit Items limit per page, if not set the config value will be used * @param int $current If not set, it will be auto detected * * @uses Request::current * @uses Kohana::$config */ public function __construct($total, $limit = null, $current = null) { $this->request(Request::current()); $this->route($this->_request->route()); $this->_route_params = array('directory' => $this->_request->directory(), 'controller' => $this->_request->controller(), 'action' => $this->_request->action()) + $this->_request->param(); $this->_config = Kohana::$config->load('pagination'); if ($current === null) { $this->_current = (int) $this->_detect_current_page(); } else { $this->_current = (int) $current; } $this->_total = (int) $total; $this->_limit = (int) $limit ? $limit : $this->_config->limit; }
public function execute_request(Request $request, Response $response) { $prefix = "Controller_"; $directory = $request->directory(); $controller = $request->controller(); if ($directory) { $prefix .= str_replace(array("\\", "/"), "_", trim($directory, "/")) . "_"; } if (JsonApiApplication::$profiling) { $benchmark = "'" . $request->uri() . "'"; if ($request !== Request::$initial and Request::$current) { $benchmark .= " « '" . Request::$current->uri() . "'"; } $benchmark = Profiler::start("Requests", $benchmark); } $previous = Request::$current; Request::$current = $request; $initial_request = $request === Request::$initial; try { if (!class_exists($prefix . $controller)) { throw HTTP_Exception::factory(404, "The requested URL :uri was not found on this server.", array(":uri" => $request->uri()))->request($request); } $class = new ReflectionClass($prefix . $controller); if ($class->isAbstract()) { throw new JsonApiApplication_Exception("Cannot create instances of abstract :controller", array(":controller" => $prefix . $controller)); } $controller = $class->newInstance($request, $response); $response = $class->getMethod("execute")->invoke($controller); if (!$response instanceof Response) { throw new JsonApiApplication_Exception("Controller failed to return a Response"); } } catch (HTTP_Exception $e) { if ($e->request() === NULL) { $e->request($request); } $response = $e->get_response(); } catch (Exception $e) { $response = JsonApiApplication_Exception::_handler($e); } Request::$current = $previous; if (isset($benchmark)) { Profiler::stop($benchmark); } return $response; }
/** * * Contruct that checks you are loged in before nothing else happens! */ function __construct(Request $request, Response $response) { // Assign the request to the controller $this->request = $request; // Assign a response to the controller $this->response = $response; //login control, don't do it for auth controller so we dont loop if ($this->request->controller() != 'auth') { $url_bread = Route::url('oc-panel', array('controller' => 'home')); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Panel'))->set_url($url_bread)); //check if user is login if (!Auth::instance()->logged_in($request->controller(), $request->action(), $request->directory())) { Alert::set(Alert::ERROR, sprintf(__('You do not have permissions to access %s'), $request->controller() . ' ' . $request->action())); $url = Route::get('oc-panel')->uri(array('controller' => 'auth', 'action' => 'login')); $this->redirect($url); } //in case we are loading another theme since we use the allow query we force the configs of the selected theme if (Theme::$theme != Core::config('appearance.theme') and Core::config('appearance.allow_query_theme') == '1') { Theme::initialize(Core::config('appearance.theme')); } } //the user was loged in and with the right permissions parent::__construct($request, $response); }
public function execute_request(Request $request, Response $response) { // Create the class prefix $prefix = 'Controller_'; // Directory $directory = $request->directory(); // Controller $controller = $request->controller(); if ($directory) { // Add the directory name to the class prefix $prefix .= str_replace(array('\\', '/'), '_', trim($directory, '/')) . '_'; } if (Kohana::$profiling) { // Set the benchmark name $benchmark = '"' . $request->uri() . '"'; if ($request !== Request::$initial and Request::$current) { // Add the parent request uri $benchmark .= ' « "' . Request::$current->uri() . '"'; } // Start benchmarking $benchmark = Profiler::start('Requests', $benchmark); } // Store the currently active request $previous = Request::$current; // Change the current request to this request Request::$current = $request; // Is this the initial request $initial_request = $request === Request::$initial; try { if (!class_exists($prefix . $controller)) { $prefix = str_replace('_', '\\', $prefix); $controller = str_replace('_', '\\', $controller); if (!class_exists($prefix . $controller)) { $z = new HTTP_Exception_404('The requested URL :uri was not found on this server.at :prefix :controller', array(':uri' => $request->uri(), ':prefix' => $prefix, ':controller' => $controller)); $z->request($request); throw $z; } } // Load the controller using reflection $class = new ReflectionClass($prefix . $controller); if ($class->isAbstract()) { throw new Kohana_Exception('Cannot create instances of abstract :controller', array(':controller' => $prefix . $controller)); } // Create a new instance of the controller $controller = $class->newInstance($request, $response); // Run the controller's execute() method $response = $class->getMethod('execute')->invoke($controller); if (!$response instanceof Response) { // Controller failed to return a Response. throw new Kohana_Exception('Controller failed to return a Response'); } } catch (HTTP_Exception $e) { // Store the request context in the Exception if ($e->request() === NULL) { $e->request($request); } // Get the response via the Exception $response = $e->get_response(); } catch (Exception $e) { // Generate an appropriate Response object $response = Kohana_Exception::_handler($e); } // Restore the previous request Request::$current = $previous; if (isset($benchmark)) { // Stop the benchmark Profiler::stop($benchmark); } // Return the response return $response; }
/** * Processes the request, executing the controller action that handles this * request, determined by the [Route]. * * 1. Before the controller action is called, the [Controller::before] method * will be called. * 2. Next the controller action will be called. * 3. After the controller action is called, the [Controller::after] method * will be called. * * By default, the output from the controller is captured and returned, and * no headers are sent. * * $request->execute(); * * @param Request $request * @return Response * @throws Kohana_Exception * @uses [Kohana::$profiling] * @uses [Profiler] * @deprecated passing $params to controller methods deprecated since version 3.1 * will be removed in 3.2 */ public function execute_request(Request $request) { // Create the class prefix $prefix = 'controller_'; // Directory $directory = $request->directory(); // Controller $controller = $request->controller(); if ($directory) { // Add the directory name to the class prefix $prefix .= str_replace(array('\\', '/'), '_', trim($directory, '/')) . '_'; } if (Kohana::$profiling) { // Set the benchmark name $benchmark = '"' . $request->uri() . '"'; if ($request !== Request::$initial and Request::$current) { // Add the parent request uri $benchmark .= ' « "' . Request::$current->uri() . '"'; } // Start benchmarking $benchmark = Profiler::start('Requests', $benchmark); } // Store the currently active request $previous = Request::$current; // Change the current request to this request Request::$current = $request; // Is this the initial request $initial_request = $request === Request::$initial; try { if (!class_exists($prefix . $controller)) { throw new HTTP_Exception_404('The requested URL :uri was not found on this server.', array(':uri' => $request->uri())); } // Load the controller using reflection $class = new ReflectionClass($prefix . $controller); if ($class->isAbstract()) { throw new Kohana_Exception('Cannot create instances of abstract :controller', array(':controller' => $prefix . $controller)); } // Create a new instance of the controller $controller = $class->newInstance($request, $request->response() ? $request->response() : $request->create_response()); $class->getMethod('before')->invoke($controller); // Determine the action to use $action = $request->action(); $params = $request->param(); // If the action doesn't exist, it's a 404 if (!$class->hasMethod('action_' . $action)) { throw new HTTP_Exception_404('The requested URL :uri was not found on this server.', array(':uri' => $request->uri())); } $method = $class->getMethod('action_' . $action); $method->invoke($controller); // Execute the "after action" method $class->getMethod('after')->invoke($controller); } catch (Exception $e) { // Restore the previous request if ($previous instanceof Request) { Request::$current = $previous; } if (isset($benchmark)) { // Delete the benchmark, it is invalid Profiler::delete($benchmark); } // Re-throw the exception throw $e; } // Restore the previous request Request::$current = $previous; if (isset($benchmark)) { // Stop the benchmark Profiler::stop($benchmark); } // Return the response return $request->response(); }
/** * Проверка прав на доступ * * @param string|Request $action * @param Model_User $user * @return boolean */ public static function check($action, Model_User $user = NULL) { if ($user === NULL) { $user = Auth::get_record(); } if (!$user instanceof Model_User) { return self::DENY; } if (empty($action)) { return self::ALLOW; } if (self::is_admin($user)) { return self::ALLOW; } if ($action instanceof Request) { $params = array(); $directory = $action->directory(); if (!empty($directory) and $directory != ADMIN_DIR_NAME) { $params[] = $action->directory(); } $params[] = $action->controller(); $params[] = $action->action(); $action = $params; } if (is_array($action)) { $action = strtolower(implode('.', $action)); } if (!isset(self::$_permissions[$user->id])) { self::_set_permissions($user); } return isset(self::$_permissions[$user->id][$action]); }