/** * Builds a response for an exception * @param \Exception $exception * @return \PHPixie\HTTP\Responses\Response */ public function process($exception) { $templateName = $this->configData->getRequired('template'); $trace = $this->debug->exceptionTrace($exception); $body = $this->template->render($templateName, array('exception' => $exception, 'trace' => $trace, 'logger' => $this->debug->logger())); return $this->http->responses()->response($body, array(), 500); }
/** * Convert data to a HTTP response * @param mixed $value * @return \PHPixie\HTTP\Responses\Response * @throws \PHPixie\HTTPProcessors\Exception If data type is not supported */ public function process($value) { if ($value instanceof \PHPixie\HTTP\Responses\Response) { return $value; } if ($value instanceof \Psr\Http\Message\ResponseInterface) { return $value; } if ($value instanceof \PHPixie\Template\Container) { $value = $value->render(); } if (is_string($value)) { return $this->http->responses()->string($value); } if (is_object($value) || is_array($value)) { return $this->http->responses()->json($value); } $type = gettype($value); throw new \PHPixie\HTTPProcessors\Exception("Cannot convert type '{$type}' into a response"); }
/** * Build a response for when a uri does not exist * @param \PHPixie\HTTP\Request $request * @return \PHPixie\HTTP\Responses\Response */ public function process($request) { $templateName = $this->configData->getRequired('template'); $body = $this->template->render($templateName, array('request' => $request)); return $this->http->responses()->response($body, array(), 404); }
private function request() { return $this->http->request(); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; use PHPixie\Slice; use PHPixie\HTTP; use Koka\Flash\Flash; $slice = new \PHPixie\Slice(); $http = new \PHPixie\HTTP($slice); $container = $http->contextContainer($http->context($http->request())); $flash = new Flash($container); var_dump($flash->has()); $flash->info('Test info message'); var_dump($flash->has()); foreach ($flash as $msg) { echo "Type: {$msg->getType()} message: {$msg->getMessage()}"; } var_dump($flash->has());