/** * 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(); }
public function testSetBody() { $this->response->setBody('abc'); $this->assertEquals('abc', $this->response->getBody()); }
/** * 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; } }