/** * Creates a new request with values from PHP's super globals. * * @return Request A new request * * @api */ public static function createFromGlobals() { $request = new static($_GET, $_POST, array(), $_COOKIE, $_FILES, $_SERVER); if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'DELETE', 'PATCH'))) { parse_str($request->getContent(), $data); $request->request = new ParameterBag($data); } else { if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/json') && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'POST'))) { $data = json_decode($request->getContent(), true); $request->request = new ParameterBag($data); } } return $request; }
/** @return bool|string */ public static function post($url, array $data) { $req = new static($url, 'POST', array('data' => $data)); if ($req->execute()) { return $req->getContent(); } return false; }
/** * Creates a new request with values from PHP's super globals. * * @return Request A new request * * @api */ public static function createFromGlobals() { $request = new static($_GET, $_POST, array(), $_COOKIE, $_FILES, $_SERVER); if (0 === strpos($request->server->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'DELETE', 'PATCH'))) { parse_str($request->getContent(), $data); if (magic_quotes()) { $data = array_strip_slashes($data); } $request->request = new ParameterBag($data); } return $request; }
/** * Creates a new request with values from PHP's super globals. * * @return Request A new request * * @api */ public static function createFromGlobals() { // With the php's bug #66606, the php's built-in web server // stores the Content-Type and Content-Length header values in // HTTP_CONTENT_TYPE and HTTP_CONTENT_LENGTH fields. $server = $_SERVER; if ('cli-server' === php_sapi_name()) { if (array_key_exists('HTTP_CONTENT_LENGTH', $_SERVER)) { $server['CONTENT_LENGTH'] = $_SERVER['HTTP_CONTENT_LENGTH']; } if (array_key_exists('HTTP_CONTENT_TYPE', $_SERVER)) { $server['CONTENT_TYPE'] = $_SERVER['HTTP_CONTENT_TYPE']; } } $request = new static($_GET, $_POST, array(), $_COOKIE, $_FILES, $server); if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'DELETE', 'PATCH'))) { parse_str($request->getContent(), $data); $request->request = new ParameterBag($data); } return $request; }