コード例 #1
0
ファイル: Request.php プロジェクト: yeephp/yeephp
 /**
  * Constructor
  * @param \Yee\Environment $env
  */
 public function __construct(\Yee\Environment $env)
 {
     $this->env = $env;
     $this->headers = new \Yee\Http\Headers(\Yee\Http\Headers::extract($env));
     $this->cookies = new \Yee\Helper\Set(\Yee\Http\Util::parseCookieHeader($env['HTTP_COOKIE']));
 }
コード例 #2
0
ファイル: Yee.php プロジェクト: yeephp/yeephp
 /**
  * Execute
  *
  * This method invokes the middleware stack, including the core Yee application;
  * the result is an array of HTTP status, header, and body. These three items
  * are returned to the HTTP client.
  */
 public function execute()
 {
     set_error_handler(array('\\Yee\\Yee', 'handleErrors'));
     //Apply final outer middleware layers
     if ($this->config('debug')) {
         //Apply pretty exceptions only in debug to avoid accidental information leakage in production
         $this->add(new \Yee\Middleware\PrettyExceptions());
     }
     //Invoke middleware and application stack
     $this->middleware[0]->call();
     //Fetch status, header, and body
     list($status, $headers, $body) = $this->response->finalize();
     // Serialize cookies (with optional encryption)
     \Yee\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', \Yee\Http\Response::getMessageForCode($status)));
         } else {
             header(sprintf('HTTP/%s %s', $this->config('http.version'), \Yee\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('yee.after');
     restore_error_handler();
 }