コード例 #1
0
ファイル: Runnable.php プロジェクト: phavour/phavour
 /**
  * When you need to send a not found in your runnable, you
  * can call this directly.
  * Optionally, you can specify the package name, class name,
  * and method name to render accordingly.
  * @param sring $package (optional) default 'DefaultPackage'
  * @param sring $class (optional) default 'Error'
  * @param sring $method (optional) default 'notFound'
  * @return void
  */
 public function notFound($package = 'DefaultPackage', $class = 'Error', $method = 'notFound')
 {
     $this->response->setStatus(404);
     $this->view->setPackage($package);
     $this->view->setClass($class);
     $this->view->setScriptName($method);
     return;
 }
コード例 #2
0
ファイル: View.php プロジェクト: phavour/phavour
 /**
  * Render the view
  * @param string $methodName
  * @param string $class
  * @param string $package
  * @return boolean if no view, otherwise sends the response
  */
 public function render($methodName = null, $class = null, $package = null)
 {
     if (!$this->isEnabled()) {
         return true;
     }
     if (null != $package) {
         $this->package = $this->treatPackageName($package);
     }
     if (null != $class) {
         $this->class = $class;
     }
     if (null != $methodName) {
         $this->method = $methodName;
     }
     $this->currentView = $this->getPathForView();
     @ob_start();
     @(include $this->currentView);
     $this->viewBody = @ob_get_clean();
     if (!empty($this->layoutLocation)) {
         @ob_start();
         @(include $this->layoutLocation);
         $this->viewBody = @ob_get_clean();
     }
     $this->response->setBody($this->viewBody);
     $this->response->sendResponse();
 }
コード例 #3
0
ファイル: ResponseTest.php プロジェクト: phavour/phavour
 public function testSetStatus()
 {
     $this->response->setStatus(404);
     $this->assertEquals(404, $this->response->getStatus());
 }
コード例 #4
0
ファイル: Application.php プロジェクト: phavour/phavour
 /**
  * In the event of an uncaught Exception at point of run, this method will be called
  * by default it'll look for 'DefaultPackage::Error::uncaughtError' before
  * manipulating the response directly and returning to the user.
  * It's environmental sensitive, so will format things accordingly.
  * @param \Exception $throwable
  * @codeCoverageIgnore
  */
 private function error(\Exception $throwable)
 {
     if ($this->env->isProduction()) {
         if (false != ($errorClass = $this->getErrorClass())) {
             try {
                 $this->response->setStatus(500);
                 $instance = $this->getRunnable('DefaultPackage', 'Error', 'uncaughtException', $errorClass);
                 if (is_callable(array($instance, 'uncaughtException'))) {
                     $instance->uncaughtException();
                 } else {
                     $e = new RunnableNotFoundException('Runnable not found');
                     $e->setAdditionalData('Expected: ', '\\DefaultPackage\\src\\Error::uncaughtException()');
                     throw $e;
                 }
                 $instance->finalise();
                 return;
             } catch (\Exception $e) {
                 // Ignore, we're already here.
             }
         }
         @ob_get_clean();
         $this->response->setStatus(500);
         $this->response->setBody('<h1 style="font:28px/1.5 Helvetica,Arial,Verdana,sans-serif;">Application Error</h1>');
         $this->response->sendResponse();
         return;
     } else {
         FormattedException::display($throwable);
         return;
     }
 }