Beispiel #1
0
 private function _authorize(array $constraints)
 {
     if (count($constraints) === 0) {
         // for those action which do not need a user logged in
         return true;
     }
     if ($this->_user instanceof User === false) {
         $this->_session->set('referer', $this->_request->url());
         $this->redirect('/login');
     }
     $authorized = true;
     foreach ($constraints as $constraint) {
         $authorized = $authorized && $constraint->authorize($this);
     }
     return $authorized;
 }
Beispiel #2
0
 /**
  * Selects the proper route according to this response routes
  * @return void
  */
 private function _selectRoute()
 {
     $path = explode('/', trim($this->_request->path(), '/ '));
     $routes = isset($this->_routes['match']) ? $this->_routes['match'] : array();
     foreach ($routes as $pattern => $route) {
         $pattern_tokens = explode('/', trim($pattern, '/ '));
         if ($this->_matchCustomPattern($path, $pattern_tokens)) {
             $this->_parseCustomRoute($path, $route);
             return;
         }
     }
     if (!isset($this->_routes['default'])) {
         return;
     }
     $default = explode('/', trim($this->_routes['default'], '/ '));
     $controller_index = array_search(':controller', $default);
     $action_index = array_search(':action', $default);
     $params_index = array_search(':params', $default);
     $this->_controller = isset($path[$controller_index]) ? $path[$controller_index] : null;
     $this->_action = isset($path[$action_index]) ? $path[$action_index] : null;
     $this->_params = array_slice($path, $params_index);
 }