/** * Run * * This method invokes the kernel stack, including the core Pulse application; * the result is an array of HTTP status, header, and body. These three items * are returned to the HTTP client. */ public function processor() { set_error_handler(array('\\Pulse\\Pulse', 'handleErrors')); //Apply final outer kernel layers if ($this->config('debug')) { //Apply pretty exceptions only in debug to avoid accidental information leakage in production $this->add(new \Pulse\Kernel\ErrorReporting()); } //Invoke kernel and application stack $this->kernel[0]->call(); //Fetch status, header, and body list($status, $headers, $body) = $this->response->finalize(); // Serialize cookies (with optional encryption) \Pulse\Http\Util::serializeCookies($headers, $this->response->cookies, $this->settings); //Send headers if (headers_sent() === false) { //Send status if (strpos(PHP_SAPI, 'cgi') === 0) { header(sprintf('Status: %s', \Pulse\Http\Response::getMessageForCode($status))); } else { header(sprintf('HTTP/%s %s', $this->config('http.version'), \Pulse\Http\Response::getMessageForCode($status))); } //Send headers foreach ($headers as $name => $value) { $hValues = explode("\n", $value); foreach ($hValues as $hVal) { header("{$name}: {$hVal}", false); } } } //Send body, but only if it isn't a HEAD request if (!$this->request->isHead()) { echo $body; } $this->applyHook('pulse.after'); restore_error_handler(); }
/** * Constructor * @param \Pulse\Environment $env */ public function __construct(\Pulse\Environment $env) { $this->env = $env; $this->headers = new \Pulse\Http\Headers(\Pulse\Http\Headers::extract($env)); $this->cookies = new \Pulse\Security\Set(\Pulse\Http\Util::parseCookieHeader($env['HTTP_COOKIE'])); }