コード例 #1
0
ファイル: Request.php プロジェクト: rmarscher/lithium
 /**
  * Initialize request object, pulling request data from superglobals.
  *
  * Defines an artificial `'PLATFORM'` environment variable as either
  * `'IIS'`, `'CGI'` or `null` to allow checking for the SAPI in a
  * normalized way.
  *
  * @return void
  */
 protected function _init()
 {
     parent::_init();
     $mobile = array('iPhone', 'MIDP', 'AvantGo', 'BlackBerry', 'J2ME', 'Opera Mini', 'DoCoMo', 'NetFront', 'Nokia', 'PalmOS', 'PalmSource', 'portalmmm', 'Plucker', 'ReqwirelessWeb', 'iPod', 'SonyEricsson', 'Symbian', 'UP\\.Browser', 'Windows CE', 'Xiino', 'Android');
     if (!empty($this->_config['detectors']['mobile'][1])) {
         $mobile = array_merge($mobile, (array) $this->_config['detectors']['mobile'][1]);
     }
     $this->_detectors['mobile'][1] = $mobile;
     $defaults = array('REQUEST_METHOD' => 'GET', 'CONTENT_TYPE' => 'text/html');
     $this->_env += (array) $_SERVER + (array) $_ENV + $defaults;
     $envs = array('isapi' => 'IIS', 'cgi' => 'CGI', 'cgi-fcgi' => 'CGI');
     $this->_env['PLATFORM'] = isset($envs[PHP_SAPI]) ? $envs[PHP_SAPI] : null;
     $this->_base = $this->_base();
     $this->url = $this->_url();
     if (!empty($this->_config['query'])) {
         $this->query = $this->_config['query'];
     }
     if (isset($_GET)) {
         $this->query += $_GET;
     }
     if (!empty($this->_config['data'])) {
         $this->data = $this->_config['data'];
     }
     if (isset($_POST)) {
         $this->data += $_POST;
     }
     if (isset($this->data['_method'])) {
         $this->_env['HTTP_X_HTTP_METHOD_OVERRIDE'] = strtoupper($this->data['_method']);
         unset($this->data['_method']);
     }
     if (!empty($this->_env['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
         $this->_env['REQUEST_METHOD'] = $this->_env['HTTP_X_HTTP_METHOD_OVERRIDE'];
     }
     $type = $this->type($this->_env['CONTENT_TYPE']);
     $this->method = $method = strtoupper($this->_env['REQUEST_METHOD']);
     if (!$this->data && ($method == 'POST' || $method == 'PUT')) {
         if ($type !== 'html') {
             $this->_stream = $this->_stream ?: fopen('php://input', 'r');
             $media = $this->_classes['media'];
             $this->data = (array) $media::decode($type, stream_get_contents($this->_stream));
             fclose($this->_stream);
         }
     }
     $this->data = Set::merge((array) $this->data, $this->_parseFiles());
 }
コード例 #2
0
ファイル: Request.php プロジェクト: Nys/lithium
 /**
  * Pulls request data from superglobals.
  *
  * @return void
  */
 protected function _init()
 {
     parent::_init();
     $mobile = array('iPhone', 'MIDP', 'AvantGo', 'BlackBerry', 'J2ME', 'Opera Mini', 'DoCoMo', 'NetFront', 'Nokia', 'PalmOS', 'PalmSource', 'portalmmm', 'Plucker', 'ReqwirelessWeb', 'iPod', 'SonyEricsson', 'Symbian', 'UP\\.Browser', 'Windows CE', 'Xiino', 'Android');
     if (!empty($this->_config['detectors']['mobile'][1])) {
         $mobile = array_merge($mobile, (array) $this->_config['detectors']['mobile'][1]);
     }
     $this->_detectors['mobile'][1] = $mobile;
     $this->_env += (array) $_SERVER + (array) $_ENV + array('REQUEST_METHOD' => 'GET');
     $envs = array('isapi' => 'IIS', 'cgi' => 'CGI', 'cgi-fcgi' => 'CGI');
     $this->_env['PLATFORM'] = isset($envs[PHP_SAPI]) ? $envs[PHP_SAPI] : null;
     $this->_base = isset($this->_base) ? $this->_base : $this->_base();
     $this->url = '/';
     if (isset($this->_config['url'])) {
         $this->url = rtrim($this->_config['url'], '/');
     } elseif (!empty($_GET['url'])) {
         $this->url = rtrim($_GET['url'], '/');
         unset($_GET['url']);
     }
     if (!empty($this->_config['query'])) {
         $this->query = $this->_config['query'];
     }
     if (isset($_GET)) {
         $this->query += $_GET;
     }
     if (!empty($this->_config['data'])) {
         $this->data = $this->_config['data'];
     } elseif (isset($_POST)) {
         $this->data += $_POST;
     }
     if (isset($this->data['_method'])) {
         $this->_env['HTTP_X_HTTP_METHOD_OVERRIDE'] = strtoupper($this->data['_method']);
         unset($this->data['_method']);
     }
     if (!empty($this->_env['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
         $this->_env['REQUEST_METHOD'] = $this->_env['HTTP_X_HTTP_METHOD_OVERRIDE'];
     }
     $method = strtoupper($this->_env['REQUEST_METHOD']);
     if (($method == 'POST' || $method == 'PUT') && !$this->data) {
         if (($type = $this->type()) && $type !== 'html') {
             $this->_stream = $this->_stream ?: fopen('php://input', 'r');
             $media = $this->_classes['media'];
             $this->data = (array) $media::decode($type, stream_get_contents($this->_stream));
             fclose($this->_stream);
         }
     }
     if (isset($_FILES) && $_FILES) {
         $result = array();
         $normalize = function ($key, $value) use($result, &$normalize) {
             foreach ($value as $param => $content) {
                 foreach ($content as $num => $val) {
                     if (is_numeric($num)) {
                         $result[$key][$num][$param] = $val;
                         continue;
                     }
                     if (is_array($val)) {
                         foreach ($val as $next => $one) {
                             $result[$key][$num][$next][$param] = $one;
                         }
                         continue;
                     }
                     $result[$key][$num][$param] = $val;
                 }
             }
             return $result;
         };
         foreach ($_FILES as $key => $value) {
             if (isset($value['name'])) {
                 if (is_string($value['name'])) {
                     $result[$key] = $value;
                     continue;
                 }
                 if (is_array($value['name'])) {
                     $result += $normalize($key, $value);
                 }
             }
         }
         $this->data = Set::merge((array) $this->data, $result);
     }
 }
コード例 #3
0
ファイル: Request.php プロジェクト: rapzo/lithium
 /**
  * Initialize request object
  *
  * Defines an artificial `'PLATFORM'` environment variable as either `'IIS'`, `'CGI'` or `null`
  * to allow checking for the SAPI in a normalized way.
  */
 protected function _init()
 {
     parent::_init();
     $mobile = array('iPhone', 'MIDP', 'AvantGo', 'BlackBerry', 'J2ME', 'Opera Mini', 'DoCoMo', 'NetFront', 'Nokia', 'PalmOS', 'PalmSource', 'portalmmm', 'Plucker', 'ReqwirelessWeb', 'iPod', 'SonyEricsson', 'Symbian', 'UP\\.Browser', 'Windows CE', 'Xiino', 'Android');
     if (!empty($this->_config['detectors']['mobile'][1])) {
         $mobile = array_merge($mobile, (array) $this->_config['detectors']['mobile'][1]);
     }
     $this->_detectors['mobile'][1] = $mobile;
     $this->data = $this->_config['data'];
     if (isset($this->data['_method'])) {
         $this->_computed['HTTP_X_HTTP_METHOD_OVERRIDE'] = strtoupper($this->data['_method']);
         unset($this->data['_method']);
     }
     $type = $this->type($this->_config['type'] ?: $this->env('CONTENT_TYPE'));
     $this->method = $method = strtoupper($this->env('REQUEST_METHOD'));
     $hasBody = in_array($method, array('POST', 'PUT', 'PATCH'));
     if (!$this->body && $hasBody && $type !== 'html') {
         $this->_stream = $this->_stream ?: fopen('php://input', 'r');
         $this->body = stream_get_contents($this->_stream);
         fclose($this->_stream);
     }
     if (!$this->data && $this->body) {
         $this->data = $this->body(null, array('decode' => true, 'encode' => false));
     }
     $this->body = $this->data;
     $this->data = Set::merge((array) $this->data, $this->_parseFiles());
 }