コード例 #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
ファイル: Environment.php プロジェクト: yeephp/yeephp
 /**
  * Constructor (private access)
  *
  * @param  array|null $settings If present, these are used instead of global server variables
  */
 private function __construct($settings = null)
 {
     if ($settings) {
         $this->properties = $settings;
     } else {
         $env = array();
         //The HTTP request method
         $env['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD'];
         //The IP
         $env['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
         // Server params
         $scriptName = $_SERVER['SCRIPT_NAME'];
         // <-- "/foo/index.php"
         $requestUri = $_SERVER['REQUEST_URI'];
         // <-- "/foo/bar?test=abc" or "/foo/index.php/bar?test=abc"
         $queryString = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
         // <-- "test=abc" or ""
         // Physical path
         if (strpos($requestUri, $scriptName) !== false) {
             $physicalPath = $scriptName;
             // <-- Without rewriting
         } else {
             $physicalPath = str_replace('\\', '', dirname($scriptName));
             // <-- With rewriting
         }
         $env['SCRIPT_NAME'] = rtrim($physicalPath, '/');
         // <-- Remove trailing slashes
         // Virtual path
         $env['PATH_INFO'] = substr_replace($requestUri, '', 0, strlen($physicalPath));
         // <-- Remove physical path
         $env['PATH_INFO'] = str_replace('?' . $queryString, '', $env['PATH_INFO']);
         // <-- Remove query string
         $env['PATH_INFO'] = '/' . ltrim($env['PATH_INFO'], '/');
         // <-- Ensure leading slash
         // Query string (without leading "?")
         $env['QUERY_STRING'] = $queryString;
         //Name of server host that is running the script
         $env['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
         //Number of server port that is running the script
         $env['SERVER_PORT'] = $_SERVER['SERVER_PORT'];
         //HTTP request headers (retains HTTP_ prefix to match $_SERVER)
         $headers = \Yee\Http\Headers::extract($_SERVER);
         foreach ($headers as $key => $value) {
             $env[$key] = $value;
         }
         //Is the application running under HTTPS or HTTP protocol?
         $env['yee.url_scheme'] = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off' ? 'http' : 'https';
         //Input stream (readable one time only; not available for multipart/form-data requests)
         $rawInput = @file_get_contents('php://input');
         if (!$rawInput) {
             $rawInput = '';
         }
         $env['yee.input'] = $rawInput;
         //Error stream
         $env['yee.errors'] = @fopen('php://stderr', 'w');
         $this->properties = $env;
     }
 }