From 0e9f02a96b5955cc477a101aa595686390800290 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 30 Sep 2013 22:45:55 +0200 Subject: [PATCH] added documentation about Request::setFactory() --- components/http_foundation/introduction.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/components/http_foundation/introduction.rst b/components/http_foundation/introduction.rst index f15372da975..ba37c78aa25 100644 --- a/components/http_foundation/introduction.rst +++ b/components/http_foundation/introduction.rst @@ -269,6 +269,26 @@ request information. Have a look at :class:`the Request API` for more information about them. +Overriding the Request +~~~~~~~~~~~~~~~~~~~~~~ + +.. versionadded:: 2.4 + The :method:`Symfony\\Component\\HttpFoundation\\Request::setFactory` + class was added in Symfony 2.4. + +The Request class should not be overridden as it is a data object that +represents an HTTP message. But when moving from a legacy system, adding +methods or changing some default behavior might help. In that case, register a +PHP callable that is able to create an instance of your Request class:: + + use Symfony\Component\HttpFoundation\Request; + + Request::setFactory(function (array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null) { + return SpecialRequest::create($query, $request, $attributes, $cookies, $files, $server, $content); + }); + + $request = Request::createFromGlobals(); + .. _component-http-foundation-response: Response