Exemple #1
0
 public function redirect($controller = NULL, $action = NULL, $item = NULL, $module = NULL)
 {
     if ($controller === NULL) {
         $url = \Biome\Biome::getService('request')->headers->get('referer');
     } else {
         $url = \URL::fromRoute($controller, $action, $item, $module);
     }
     Logger::info('Redirect to ' . $url);
     $this->headers->set('Location', $url);
     $this->setStatusCode(302);
     return $this;
 }
Exemple #2
0
 public function process($type, $controller_name, $action_name, $method_name, $method_params)
 {
     Logger::info('Processing method ' . $method_name);
     $this->_call_params['http_method_type'] = $type;
     $this->_call_params['controller_name'] = $controller_name;
     $this->_call_params['action_name'] = $action_name;
     $this->_call_params['method_name'] = $method_name;
     $this->_call_params['method_params'] = $method_params;
     /**
      * preRoute
      */
     if (!$this->beforeRoute()) {
         return $this->response();
     }
     $rendering = $type == 'GET' ? TRUE : FALSE;
     $this->view = \Biome\Biome::getService('view');
     try {
         $this->view->load($controller_name, $action_name);
     } catch (\Biome\Core\View\Exception\TemplateNotFoundException $e) {
         $rendering = FALSE;
     }
     $result = call_user_func_array(array($this, $method_name), $method_params);
     if ($result instanceof Response) {
         $this->response = $result;
     }
     // Ajax Request
     if ($this->request->isXmlHttpRequest()) {
         $rendering = FALSE;
         $partial_rendering = $this->request->get('partial');
         if ($partial_rendering) {
             $this->response->setContentType('application/json');
             $this->view->ajaxHandle($partial_rendering);
         }
     }
     if ($rendering && !$this->response->isRedirection()) {
         // Render view
         $content = $this->view->render();
         if (!empty($content)) {
             $this->response->setContent($content);
         }
     }
     $this->response = $this->afterRoute($this->response);
     return $this->response;
 }
Exemple #3
0
 protected static function declareServices()
 {
     /* Registering default services. */
     /**
      * Autoload
      */
     Autoload::register();
     /**
      * Biome default logger service.
      */
     if (!Biome::hasService('logger')) {
         Biome::registerService('logger', function () {
             return new \Psr\Log\NullLogger();
         });
     }
     /**
      * Biome default request.
      */
     if (!Biome::hasService('request')) {
         Biome::registerService('request', function () {
             return Request::createFromGlobals();
         });
     }
     /**
      * Biome default lang service.
      */
     if (!Biome::hasService('lang')) {
         Biome::registerService('lang', function () {
             $languages = Biome::getService('request')->getLanguages();
             $lang = new \Biome\Core\Lang\XMLLang($languages);
             return $lang;
         });
     }
     /**
      * Biome default view service.
      */
     if (!Biome::hasService('view')) {
         Biome::registerService('view', function () {
             $view = new \Biome\Core\View();
             $app_name = Biome::getService('lang')->get('app_name');
             $view->setTitle($app_name);
             return $view;
         });
     }
     /**
      * Biome default rights service.
      */
     if (!Biome::hasService('rights')) {
         Biome::registerService('rights', function () {
             $auth = \Biome\Core\Collection::get('auth');
             if ($auth->isAuthenticated()) {
                 $admin_id = 1;
                 // Default value of the Admin role id.
                 if (Biome::hasService('config')) {
                     $admin_id = Biome::getService('config')->get('ADMIN_ROLE_ID', 1);
                 }
                 $roles = $auth->user->roles;
                 foreach ($roles as $role) {
                     /* If Admin. */
                     if ($role->role_id == $admin_id) {
                         return new \Biome\Core\Rights\FreeRights();
                     }
                     $rights = AccessRights::loadFromJSON($role->role_rights);
                 }
                 return $rights;
             }
             $rights = AccessRights::loadFromArray(array());
             $rights->setAttribute('User', 'firstname', TRUE, TRUE)->setAttribute('User', 'lastname', TRUE, TRUE)->setAttribute('User', 'mail', TRUE, TRUE)->setAttribute('User', 'password', TRUE, TRUE)->setRoute('GET', 'index', 'index')->setRoute('GET', 'auth', 'login')->setRoute('POST', 'auth', 'signin')->setRoute('POST', 'auth', 'signup');
             return $rights;
         });
     }
     /**
      * Biome default route service.
      */
     if (!Biome::hasService('router')) {
         Biome::registerService('router', function () {
             $router = new Route();
             $router->autoroute();
             return $router;
         });
     }
     /**
      * Biome default dispatch service.
      */
     if (!Biome::hasService('dispatcher')) {
         Biome::registerService('dispatcher', function () {
             return Biome::getService('router')->getDispatcher();
         });
     }
     Logger::info('Services registered!');
 }