Example #1
0
 /**
  * Handle an incoming web request.
  */
 public function handleRequest()
 {
     try {
         $this->response = parent::handleRequest();
     } catch (HttpException $ex) {
         $this->config->set('page_title', 'Error');
         $view = new View('exception');
         $view->exception = $ex;
         $this->response->setResponseCode($ex->getErrorCode());
         $this->response->setContent($view->render());
     } catch (\Exception $ex) {
         $this->config->set('page_title', 'Error');
         $view = new View('exception');
         $view->exception = $ex;
         $this->response->setResponseCode(500);
         $this->response->setContent($view->render());
     }
     if (View::exists('layout') && $this->response->hasLayout()) {
         $view = new View('layout');
         $pageTitle = $this->config->get('page_title', null);
         if (!is_null($pageTitle)) {
             $view->title = $pageTitle;
         }
         $view->content = $this->response->getContent();
         $this->response->setContent($view->render());
     }
     return $this->response;
 }
Example #2
0
 public function tryRoute($route)
 {
     $pathParts = $this->request->getPathParts();
     //-------
     // Set up default values for everything:
     //-------
     list($thisNamespace, $thisController, $thisAction) = $this->getDefaults($route);
     $routeParts = array_filter(explode('/', $route['route']));
     $routeMatches = true;
     while (count($routeParts)) {
         $routePart = array_shift($routeParts);
         $pathPart = array_shift($pathParts);
         switch ($routePart) {
             case ':namespace':
                 if (!is_null($pathPart)) {
                     $thisNamespace = $pathPart;
                 }
                 break;
             case ':controller':
                 if (!is_null($pathPart)) {
                     $thisController = $pathPart;
                 }
                 break;
             case ':action':
                 if (!is_null($pathPart)) {
                     $thisAction = $pathPart;
                 }
                 break;
             default:
                 if (substr($routePart, 0, 1) == '(' && substr($routePart, -1) == ')') {
                     if (preg_match('/^' . $routePart . '$/', $pathPart)) {
                         break;
                     }
                 }
                 if ($routePart != $pathPart) {
                     $routeMatches = false;
                 }
         }
         if (!$routeMatches || !count($pathParts)) {
             break;
         }
     }
     $thisArgs = $pathParts;
     if ($routeMatches) {
         $route = array('namespace' => $thisNamespace, 'controller' => $thisController, 'action' => $thisAction, 'args' => $thisArgs, 'callback' => $route['callback']);
         if ($this->application->isValidRoute($route)) {
             return $route;
         }
     }
     return null;
 }
Example #3
0
 /**
  * Loads a particular controller, and injects our layout view into it.
  * @param $class
  * @return mixed
  */
 protected function loadController($class)
 {
     $controller = parent::loadController($class);
     $controller->layout = new View('layout');
     $controller->layout->title = 'PHPCI';
     $controller->layout->breadcrumb = array();
     return $controller;
 }
Example #4
0
 /**
  * Handle the request
  *
  * @return mixed
  * @throws \b8\Exception\HttpException
  * @throws \Exception
  * @throws \Exception
  */
 public function handleRequest()
 {
     try {
         $rtn = parent::handleRequest();
         if (extension_loaded('newrelic')) {
             $site = $this->toPhpName($this->config->get('site.name'));
             $controller = $this->toPhpName($this->route['controller']);
             $action = $this->toPhpName($this->route['action']);
             newrelic_name_transaction($site . '.' . $controller . '.' . $action);
         }
     } catch (HttpException $ex) {
         if (defined('CMS_ENV') && CMS_ENV == 'development' || array_key_exists('ex', $_GET)) {
             throw $ex;
         }
         $rtn = $this->handleHttpError($ex->getErrorCode());
     } catch (Exception $ex) {
         if (defined('CMS_ENV') && CMS_ENV == 'development' || array_key_exists('ex', $_GET)) {
             throw $ex;
         }
         $rtn = $this->handleHttpError(500);
     }
     return $rtn;
 }