Skip to content

Commit 5aa3a19

Browse files
committed
Merge pull request #3021 from fabpot/request-factory
added documentation about Request::setFactory()
2 parents adcef55 + 0e9f02a commit 5aa3a19

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

components/http_foundation/introduction.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,26 @@ request information. Have a look at
275275
:class:`the Request API <Symfony\\Component\\HttpFoundation\\Request>`
276276
for more information about them.
277277

278+
Overriding the Request
279+
~~~~~~~~~~~~~~~~~~~~~~
280+
281+
.. versionadded:: 2.4
282+
The :method:`Symfony\\Component\\HttpFoundation\\Request::setFactory`
283+
class was added in Symfony 2.4.
284+
285+
The Request class should not be overridden as it is a data object that
286+
represents an HTTP message. But when moving from a legacy system, adding
287+
methods or changing some default behavior might help. In that case, register a
288+
PHP callable that is able to create an instance of your Request class::
289+
290+
use Symfony\Component\HttpFoundation\Request;
291+
292+
Request::setFactory(function (array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null) {
293+
return SpecialRequest::create($query, $request, $attributes, $cookies, $files, $server, $content);
294+
});
295+
296+
$request = Request::createFromGlobals();
297+
278298
.. _component-http-foundation-response:
279299

280300
Response

0 commit comments

Comments
 (0)