Skip to content

Commit 0d0e81d

Browse files
committed
Simplified Requests and Responses in Symfony
1 parent 6de2cf6 commit 0d0e81d

File tree

2 files changed

+8
-41
lines changed

2 files changed

+8
-41
lines changed

components/http_foundation.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ Thanks to the public ``attributes`` property, you can store additional data
180180
in the request, which is also an instance of
181181
:class:`Symfony\\Component\\HttpFoundation\\ParameterBag`. This is mostly used
182182
to attach information that belongs to the Request and that needs to be
183-
accessed from many different points in your application. For information
184-
on how this is used in the Symfony Framework, see
185-
:ref:`the Symfony book <book-fundamentals-attributes>`.
183+
accessed from many different points in your application.
186184

187185
Finally, the raw data sent with the request body can be accessed using
188186
:method:`Symfony\\Component\\HttpFoundation\\Request::getContent`::

http_fundamentals.rst

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ allow you to interact with the HTTP request and response in an easier way.
206206
Symfony Request Object
207207
~~~~~~~~~~~~~~~~~~~~~~
208208

209-
The :class:`Symfony\\Component\\HttpFoundation\\Request` class is a simple
209+
The :class:`Symfony\\Component\\HttpFoundation\\Request` class is an
210210
object-oriented representation of the HTTP request message. With it, you
211211
have all the request information at your fingertips::
212212

@@ -218,14 +218,14 @@ have all the request information at your fingertips::
218218
$request->getPathInfo();
219219

220220
// retrieve $_GET and $_POST variables respectively
221-
$request->query->get('foo');
222-
$request->request->get('bar', 'default value if bar does not exist');
221+
$request->query->get('id');
222+
$request->request->get('category', 'default category');
223223

224224
// retrieve $_SERVER variables
225225
$request->server->get('HTTP_HOST');
226226

227-
// retrieves an instance of UploadedFile identified by foo
228-
$request->files->get('foo');
227+
// retrieves an instance of UploadedFile identified by "attachment"
228+
$request->files->get('attachment');
229229

230230
// retrieve a $_COOKIE value
231231
$request->cookies->get('PHPSESSID');
@@ -234,36 +234,14 @@ have all the request information at your fingertips::
234234
$request->headers->get('host');
235235
$request->headers->get('content_type');
236236

237-
$request->getMethod(); // GET, POST, PUT, DELETE, HEAD
237+
$request->getMethod(); // e.g. GET, POST, PUT, DELETE or HEAD
238238
$request->getLanguages(); // an array of languages the client accepts
239239

240240
As a bonus, the ``Request`` class does a lot of work in the background that
241241
you'll never need to worry about. For example, the ``isSecure()`` method
242242
checks the *three* different values in PHP that can indicate whether or not
243243
the user is connecting via a secured connection (i.e. HTTPS).
244244

245-
.. sidebar:: ParameterBags and Request Attributes
246-
247-
As seen above, the ``$_GET`` and ``$_POST`` variables are accessible via
248-
the public ``query`` and ``request`` properties respectively. Each of
249-
these objects is a :class:`Symfony\\Component\\HttpFoundation\\ParameterBag`
250-
object, which has methods like
251-
:method:`Symfony\\Component\\HttpFoundation\\ParameterBag::get`,
252-
:method:`Symfony\\Component\\HttpFoundation\\ParameterBag::has`,
253-
:method:`Symfony\\Component\\HttpFoundation\\ParameterBag::all` and more.
254-
In fact, every public property used in the previous example is some instance
255-
of the ParameterBag.
256-
257-
.. _book-fundamentals-attributes:
258-
259-
The Request class also has a public ``attributes`` property, which holds
260-
special data related to how the application works internally. For the
261-
Symfony Framework, the ``attributes`` holds the values returned by the
262-
matched route, like ``_controller``, ``id`` (if you have an ``{id}``
263-
wildcard), and even the name of the matched route (``_route``). The
264-
``attributes`` property exists entirely to be a place where you can
265-
prepare and store context-specific information about the request.
266-
267245
Symfony Response Object
268246
~~~~~~~~~~~~~~~~~~~~~~~
269247

@@ -285,20 +263,11 @@ needs to be returned to the client::
285263
// print the HTTP headers followed by the content
286264
$response->send();
287265

288-
There are also special classes to make certain types of responses easier to create:
289-
290-
* :ref:`JsonResponse <component-http-foundation-json-response>`;
291-
292-
* :ref:`BinaryFileResponse <component-http-foundation-serving-files>` (for streaming
293-
files and sending file downloads);
294-
295-
* :ref:`StreamedResponse <streaming-response>` (for streaming any other large responses);
296-
297266
.. tip::
298267

299268
The ``Request`` and ``Response`` classes are part of a standalone component
300269
called :doc:`symfony/http-foundation </components/http_foundation/introduction>`
301-
that yo can use in *any* PHP project. This also contains classes for handling
270+
that you can use in *any* PHP project. This also contains classes for handling
302271
sessions, file uploads and more.
303272

304273
If Symfony offered nothing else, you would already have a toolkit for easily

0 commit comments

Comments
 (0)