/** * Initialize the Response * * @return void */ protected function _init() { parent::_init(); if ($this->_config['message']) { $this->body = $this->_parseMessage($this->_config['message']); } if (isset($this->headers['Transfer-Encoding'])) { $this->body = $this->_httpChunkedDecode($this->body); } if (isset($this->headers['Content-Type'])) { $pattern = '/([-\\w\\/\\.+]+)(;\\s*?charset=(.+))?/i'; preg_match($pattern, $this->headers['Content-Type'], $match); if (isset($match[1])) { $this->type = trim($match[1]); $this->body = $this->_decode($this->body); } if (isset($match[3])) { $this->encoding = strtoupper(trim($match[3])); } } }
protected function _init() { parent::_init(); $body = $this->_config['body']; if ($this->_config['body'] && !$this->_config['message']) { $this->body = $this->_config['body']; } elseif (($body = $this->_config['message']) && !$this->_config['body']) { $body = $this->_parseMessage($body); } if (isset($this->headers['Content-Type'])) { preg_match('/^(.*?);\\s*?charset=(.+)/i', $this->headers['Content-Type'], $match); if ($match) { $this->type = trim($match[1]); $this->encoding = strtoupper(trim($match[2])); } } if (isset($this->headers['Transfer-Encoding'])) { $body = $this->_decode($body); } $this->body = $this->body ?: $body; }
/** * 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); } }