Skip to content

Commit 0e9f02a

Browse files
committed
added documentation about Request::setFactory()
1 parent 574d7a8 commit 0e9f02a

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
@@ -269,6 +269,26 @@ request information. Have a look at
269269
:class:`the Request API<Symfony\\Component\\HttpFoundation\\Request>`
270270
for more information about them.
271271

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

274294
Response

0 commit comments

Comments
 (0)