-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] fixed Request::create() method #6995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,6 +253,9 @@ public static function createFromGlobals() | |
/** | ||
* Creates a Request based on a given URI and configuration. | ||
* | ||
* The information contained in the URI always take precedence | ||
* over the other information (server and parameters). | ||
* | ||
* @param string $uri The URI | ||
* @param string $method The HTTP method | ||
* @param array $parameters The query (GET) or request (POST) parameters | ||
|
@@ -267,7 +270,7 @@ public static function createFromGlobals() | |
*/ | ||
public static function create($uri, $method = 'GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason not to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be BC break, and it's to late to have such in 2.2. |
||
{ | ||
$defaults = array( | ||
$server = array_replace(array( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rybakit do you have any idea on the perf impact ? (out of my own curiosity) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vicb, a simple benchmark - https://gist.github.com/rybakit/4737807 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quite micro difference anyway (notice it's visible when looping more than 10000 times)... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rybakit, do you have XDebug enabled ? (If yes could you please re-test by disabling it). Twice as fast is a notable difference IMO in favor of union. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rybakit could you please create a new issue to discuss this as the PR has been closed - you suggestion is applicable at several places in the code. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
'SERVER_NAME' => 'localhost', | ||
'SERVER_PORT' => 80, | ||
'HTTP_HOST' => 'localhost', | ||
|
@@ -280,32 +283,38 @@ public static function create($uri, $method = 'GET', $parameters = array(), $coo | |
'SCRIPT_FILENAME' => '', | ||
'SERVER_PROTOCOL' => 'HTTP/1.1', | ||
'REQUEST_TIME' => time(), | ||
); | ||
), $server); | ||
|
||
$server['PATH_INFO'] = ''; | ||
$server['REQUEST_METHOD'] = strtoupper($method); | ||
|
||
$components = parse_url($uri); | ||
if (isset($components['host'])) { | ||
$defaults['SERVER_NAME'] = $components['host']; | ||
$defaults['HTTP_HOST'] = $components['host']; | ||
$server['SERVER_NAME'] = $components['host']; | ||
$server['HTTP_HOST'] = $components['host']; | ||
} | ||
|
||
if (isset($components['scheme'])) { | ||
if ('https' === $components['scheme']) { | ||
$defaults['HTTPS'] = 'on'; | ||
$defaults['SERVER_PORT'] = 443; | ||
$server['HTTPS'] = 'on'; | ||
$server['SERVER_PORT'] = 443; | ||
} else { | ||
unset($server['HTTPS']); | ||
$server['SERVER_PORT'] = 80; | ||
} | ||
} | ||
|
||
if (isset($components['port'])) { | ||
$defaults['SERVER_PORT'] = $components['port']; | ||
$defaults['HTTP_HOST'] = $defaults['HTTP_HOST'].':'.$components['port']; | ||
$server['SERVER_PORT'] = $components['port']; | ||
$server['HTTP_HOST'] = $server['HTTP_HOST'].':'.$components['port']; | ||
} | ||
|
||
if (isset($components['user'])) { | ||
$defaults['PHP_AUTH_USER'] = $components['user']; | ||
$server['PHP_AUTH_USER'] = $components['user']; | ||
} | ||
|
||
if (isset($components['pass'])) { | ||
$defaults['PHP_AUTH_PW'] = $components['pass']; | ||
$server['PHP_AUTH_PW'] = $components['pass']; | ||
} | ||
|
||
if (!isset($components['path'])) { | ||
|
@@ -316,7 +325,7 @@ public static function create($uri, $method = 'GET', $parameters = array(), $coo | |
case 'POST': | ||
case 'PUT': | ||
case 'DELETE': | ||
$defaults['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; | ||
$server['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; | ||
case 'PATCH': | ||
$request = $parameters; | ||
$query = array(); | ||
|
@@ -333,14 +342,8 @@ public static function create($uri, $method = 'GET', $parameters = array(), $coo | |
} | ||
$queryString = http_build_query($query, '', '&'); | ||
|
||
$uri = $components['path'].('' !== $queryString ? '?'.$queryString : ''); | ||
|
||
$server = array_replace($defaults, $server, array( | ||
'REQUEST_METHOD' => strtoupper($method), | ||
'PATH_INFO' => '', | ||
'REQUEST_URI' => $uri, | ||
'QUERY_STRING' => $queryString, | ||
)); | ||
$server['REQUEST_URI'] = $components['path'].('' !== $queryString ? '?'.$queryString : ''); | ||
$server['QUERY_STRING'] = $queryString; | ||
|
||
return new static($query, $request, array(), $cookies, $files, $server, $content); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a widely used and
@api
tagged class, this probably deserves a "[BC BREAK]"