Example #1
0
 /**
  * Runs this controller action, printing its view
  * @final
  * @return void
  */
 public final function run()
 {
     $action = $this->_response->action() . 'Action';
     $params = $this->_response->params();
     // get variables of the abstract controller
     $vars = get_object_vars($this);
     if (is_callable(array($this, $action))) {
         //TODO: put these assertions in a private method
         $refl = new ReflectionAnnotatedMethod($this, $action);
         if (!$this->_authorize($refl->getAllAnnotations())) {
             throw new UserError('You do not have permission to access this action');
         }
         if (count($params) < $refl->getNumberOfRequiredParameters()) {
             throw new UserError('The URL misses some parameters');
         }
         call_user_func_array(array($this, $action), $params);
         $this->flush();
         // closes the database connection because only a controller can access it
         $this->close();
     }
     // get only variables set in the controller instance
     $vars = array_diff_key(get_object_vars($this), $vars);
     $this->_view->setVariables($vars);
     if ($this->_request->json() || $this->_request->ajax()) {
         $this->disableDecorator();
     }
     if (!is_null($this->_decorator)) {
         $this->_view->setDecorator($this->_decorator);
     }
     $this->_view->render();
     $this->_view->show();
     //FIXME: in the view, we need to know which constraints are in use, in order to hide some information like links to add an item
 }
    public function handle($request, $response, $template)
    {
        $now = new DateTime();
        $time = $now->format(DateTime::RFC850);
        $trace = TextUtil::tabify($this->getTraceAsString(), 1);
        $request = $request ? TextUtil::tabify($request, 1) : '(No request information)';
        $response = $response ? TextUtil::tabify($response, 1) : '(No response information)';
        $view = new View($request, $response);
        $view->setDecorator($template);
        $this->message = <<<EOT
{$this->message}

* Time: {$time}
* File: {$this->file}
* Line: {$this->line}
* Trace:
\t{$trace}

* Request:
\t{$request}

* Response:
\t{$response}
EOT;
        if (Config::get('development')) {
            $this->message = "<pre>{$this->message}</pre>";
            $view->setText($this->message);
        } else {
            Mail::send(Config::get('developers'), 'Application error', $this->message, Mail::PRIORITY_HIGH);
            $view->setText('An email has been sent to the developers to resolve the issue.' . ' Thank you.');
        }
        $view->render();
        $view->show();
    }
Example #3
0
 public function handle($request, $response, $template)
 {
     $view = new View($request, $response);
     $view->setDecorator($template);
     $view->setText($this->message);
     $view->render();
     $view->show();
 }