@@ -9,8 +9,8 @@ The HttpFoundation Component
9
9
specification.
10
10
11
11
In PHP, the request is represented by some global variables (``$_GET ``,
12
- ``$_POST ``, , ``$_FILE ``, , ``$_COOKIE ``, ``$_SESSION ``...) and the response
13
- is generated by some functions (``echo ``, ``header ``, ``setcookie ``, ...).
12
+ ``$_POST ``, ``$_FILE ``, ``$_COOKIE ``, ``$_SESSION ``...) and the response is
13
+ generated by some functions (``echo ``, ``header ``, ``setcookie ``, ...).
14
14
15
15
The Symfony2 HttpFoundation component replaces these default PHP global
16
16
variables and functions by an Object-Oriented layer.
@@ -20,14 +20,14 @@ Request
20
20
21
21
The most common way to create request is to base it on the current PHP global
22
22
variables with
23
- ` :method:Symfony\\Component\\HttpFoundation\\Request::createFromGlobals() `::
23
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::createFromGlobals() `::
24
24
25
25
use Symfony\Component\HttpFoundation\Request;
26
26
27
27
$request = Request::createFromGlobals();
28
28
29
29
which is almost equivalent to the more verbose, but also more flexible,
30
- ` :method:Symfony\\Component\\HttpFoundation\\Request::__construct() ` call::
30
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::__construct() ` call::
31
31
32
32
$request = new Request($_GET, $_POST, array(), $_COOKIE, $_FILES, $_SERVER);
33
33
@@ -50,64 +50,64 @@ can be accessed via several public properties:
50
50
* ``headers ``: mostly equivalent to a sub-set of ``$_SERVER ``
51
51
(``$request->headers->get('Content-Type') ``).
52
52
53
- Each property is a ` :class:Symfony\\Component\\HttpFoundation\\ParameterBag `
53
+ Each property is a :class: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBag `
54
54
instance (or a sub-class of), which is a data holder class:
55
55
56
- * ``request ``: ` :class:Symfony\\Component\\HttpFoundation\\ParameterBag `;
56
+ * ``request ``: :class: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBag `;
57
57
58
- * ``query ``: ` :class:Symfony\\Component\\HttpFoundation\\ParameterBag `;
58
+ * ``query ``: :class: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBag `;
59
59
60
- * ``cookies ``: ` :class:Symfony\\Component\\HttpFoundation\\ParameterBag `;
60
+ * ``cookies ``: :class: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBag `;
61
61
62
- * ``files ``: ` :class:Symfony\\Component\\HttpFoundation\\FileBag `;
62
+ * ``files ``: :class: ` Symfony\\ Component\\ HttpFoundation\\ FileBag `;
63
63
64
- * ``server ``: ` :class:Symfony\\Component\\HttpFoundation\\ServerBag `;
64
+ * ``server ``: :class: ` Symfony\\ Component\\ HttpFoundation\\ ServerBag `;
65
65
66
- * ``headers ``: ` :class:Symfony\\Component\\HttpFoundation\\HeaderBag `.
66
+ * ``headers ``: :class: ` Symfony\\ Component\\ HttpFoundation\\ HeaderBag `.
67
67
68
- All ` :class:Symfony\\Component\\HttpFoundation\\ParameterBag ` instances have
68
+ All :class: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBag ` instances have
69
69
methods to retrieve and update its data:
70
70
71
- * ` :method:Symfony\\Component\\HttpFoundation\\ParameterBag::all() `: Returns
71
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBag::all() `: Returns
72
72
the parameters;
73
73
74
- * ` :method:Symfony\\Component\\HttpFoundation\\ParameterBagkeys() `: Returns
74
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBagkeys() `: Returns
75
75
the parameter keys;
76
76
77
- * ` :method:Symfony\\Component\\HttpFoundation\\ParameterBagreplace() `:
77
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBagreplace() `:
78
78
Replaces the current parameters by a new set;
79
79
80
- * ` :method:Symfony\\Component\\HttpFoundation\\ParameterBagadd() `: Adds
80
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBagadd() `: Adds
81
81
parameters;
82
82
83
- * ` :method:Symfony\\Component\\HttpFoundation\\ParameterBagget() `: Returns a
83
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBagget() `: Returns a
84
84
parameter by name;
85
85
86
- * ` :method:Symfony\\Component\\HttpFoundation\\ParameterBagset() `: Sets a
86
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBagset() `: Sets a
87
87
parameter by name;
88
88
89
- * ` :method:Symfony\\Component\\HttpFoundation\\ParameterBaghas() `: Returns
89
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBaghas() `: Returns
90
90
true if the parameter is defined;
91
91
92
- * ` :method:Symfony\\Component\\HttpFoundation\\ParameterBagremove() `: Removes
92
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBagremove() `: Removes
93
93
a parameter.
94
94
95
- The ` :class:Symfony\\Component\\HttpFoundation\\ParameterBag ` instance also
95
+ The :class: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBag ` instance also
96
96
has some methods to filter the input values:
97
97
98
- * ` :method:Symfony\\Component\\HttpFoundation\\Request::getAlpha() `: Returns
98
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::getAlpha() `: Returns
99
99
the alphabetic characters of the parameter value;
100
100
101
- * ` :method:Symfony\\Component\\HttpFoundation\\Request::getAlnum() `: Returns
101
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::getAlnum() `: Returns
102
102
the alphabetic characters and digits of the parameter value;
103
103
104
- * ` :method:Symfony\\Component\\HttpFoundation\\Request::getDigits() `: Returns
104
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::getDigits() `: Returns
105
105
the digits of the parameter value;
106
106
107
- * ` :method:Symfony\\Component\\HttpFoundation\\Request::getInt() `: Returns the
107
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::getInt() `: Returns the
108
108
parameter value converted to integer;
109
109
110
- * ` :method:Symfony\\Component\\HttpFoundation\\Request::filter() `: Filters the
110
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::filter() `: Filters the
111
111
parameter by using the PHP ``filter_var() `` function.
112
112
113
113
All getters takes up to three arguments: the first one is the parameter name
@@ -131,7 +131,7 @@ When PHP imports the request query, it handles request parameters like
131
131
``foo `` parameter and you will get back an array with a ``bar `` element. But
132
132
sometimes, you might want to get the value for the "original" parameter name:
133
133
``foo[bar] ``. This is possible with all the `ParameterBag ` getters like
134
- ` :method:Symfony\\Component\\HttpFoundation\\Request::get() ` via the third
134
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::get() ` via the third
135
135
argument::
136
136
137
137
// the query string is '?foo[bar]=bar'
@@ -147,7 +147,7 @@ argument::
147
147
148
148
Last, but not the least, you can also store additional data in the request,
149
149
thanks to the ``attributes `` public property, which is also an instance of
150
- ` :class:Symfony\\Component\\HttpFoundation\\ParameterBag `. This is mostly used
150
+ :class: ` Symfony\\ Component\\ HttpFoundation\\ ParameterBag `. This is mostly used
151
151
to attach information that belongs to the Request and that needs to be
152
152
accessed from many different points in your application.
153
153
@@ -156,7 +156,7 @@ Identifying a Request
156
156
157
157
In your application, you need a way to identify a request; most of the time,
158
158
this is done via the "path info" of the request, which can be accessed via the
159
- ` :method:Symfony\\Component\\HttpFoundation\\Request::getPathInfo() ` method:
159
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::getPathInfo() ` method:
160
160
161
161
// for a request to http://example.com/blog/index.php/post/hello-world
162
162
// the path info is "/post/hello-world"
@@ -170,31 +170,31 @@ a Request::
170
170
171
171
$request = Request::create('/hello-world', 'GET', array('name' => 'Fabien'));
172
172
173
- The ` :method:Symfony\\Component\\HttpFoundation\\Request::create() ` method
173
+ The :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::create() ` method
174
174
creates a request based on a path info, a method and some parameters (the
175
175
query parameters or the request ones depending on the HTTP method); and of
176
176
course, you an also override all other variables as well (by default, Symfony
177
177
creates sensible defaults for all the PHP global variables).
178
178
179
179
Based on such a request, you can override the PHP global variables via
180
- ` :method:Symfony\\Component\\HttpFoundation\\Request::overrideGlobals() `::
180
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::overrideGlobals() `::
181
181
182
182
$request->overrideGlobals();
183
183
184
184
.. tip ::
185
185
186
186
You can also duplicate an existing query via
187
- ` :method:Symfony\\Component\\HttpFoundation\\Request::duplicate() ` or
187
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::duplicate() ` or
188
188
change a bunch of parameters with a single call to
189
- ` :method:Symfony\\Component\\HttpFoundation\\Request::initialize() `.
189
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::initialize() `.
190
190
191
191
Accessing the Session
192
192
~~~~~~~~~~~~~~~~~~~~~
193
193
194
194
If you have a session attached to the Request, you can access it via the
195
- ` :method:Symfony\\Component\\HttpFoundation\\Request::getSession() ` method;
195
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::getSession() ` method;
196
196
the
197
- ` :method:Symfony\\Component\\HttpFoundation\\Request::hasPreviousSession() `
197
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Request::hasPreviousSession() `
198
198
method tells you if the request contains a Session which was started in one of
199
199
the previous requests.
200
200
@@ -207,7 +207,7 @@ request information. Have a look at the API for more information about them.
207
207
Response
208
208
--------
209
209
210
- A ` :class:Symfony\\Component\\HttpFoundation\\Response ` object holds all the
210
+ A :class: ` Symfony\\ Component\\ HttpFoundation\\ Response ` object holds all the
211
211
information that needs to be sent back to the client from a given request. The
212
212
constructor takes up to three arguments: the response content, the status
213
213
code, and an array of HTTP headers::
@@ -227,7 +227,7 @@ These information can also be manipulated after the Response object creation::
227
227
228
228
When setting the ``Content-Type `` of the Response, you can set the charset,
229
229
but it is better to set it via the
230
- ` :method:Symfony\\Component\\HttpFoundation\\Response::setCharset() ` method::
230
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::setCharset() ` method::
231
231
232
232
$response->setCharset('ISO-8859-1');
233
233
@@ -239,12 +239,12 @@ Sending the Response
239
239
240
240
Before sending the Response, you can ensure that it is compliant with the HTTP
241
241
specification by calling the
242
- ` :method:Symfony\\Component\\HttpFoundation\\Response::prepare() ` method::
242
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::prepare() ` method::
243
243
244
244
$response->prepare($request);
245
245
246
246
Sending the response to the client is then as simple as calling
247
- ` :method:Symfony\\Component\\HttpFoundation\\Response::send() `:
247
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::send() `:
248
248
249
249
$response->send();
250
250
@@ -259,32 +259,32 @@ attribute::
259
259
$response->headers->setCookie(new Cookie('foo', 'bar'));
260
260
261
261
The
262
- ` :method:Symfony\\Component\\HttpFoundation\\ResponseHeaderBag::setCookie() `
262
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ ResponseHeaderBag::setCookie() `
263
263
method takes an instance of
264
- ` :class:Symfony\\Component\\HttpFoundation\\Cookie ` as an argument.
264
+ :class: ` Symfony\\ Component\\ HttpFoundation\\ Cookie ` as an argument.
265
265
266
266
You can clear a cookie via the
267
- ` :method:Symfony\\Component\\HttpFoundation\\Response::clearCookie() ` method.
267
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::clearCookie() ` method.
268
268
269
269
Managing the HTTP Cache
270
270
~~~~~~~~~~~~~~~~~~~~~~~
271
271
272
- The ` :class:Symfony\\Component\\HttpFoundation\\Response ` class has a rich set
272
+ The :class: ` Symfony\\ Component\\ HttpFoundation\\ Response ` class has a rich set
273
273
of methods to manipulate the HTTP headers related to the cache:
274
274
275
- * ` :method:Symfony\\Component\\HttpFoundation\\Response::setPublic() `;
276
- * ` :method:Symfony\\Component\\HttpFoundation\\Response::setPrivate() `;
277
- * ` :method:Symfony\\Component\\HttpFoundation\\Response::expire() `;
278
- * ` :method:Symfony\\Component\\HttpFoundation\\Response::setExpires() `;
279
- * ` :method:Symfony\\Component\\HttpFoundation\\Response::setMaxAge() `;
280
- * ` :method:Symfony\\Component\\HttpFoundation\\Response::setSharedMaxAge() `;
281
- * ` :method:Symfony\\Component\\HttpFoundation\\Response::setTtl() `;
282
- * ` :method:Symfony\\Component\\HttpFoundation\\Response::setClientTtl() `;
283
- * ` :method:Symfony\\Component\\HttpFoundation\\Response::setLastModified() `;
284
- * ` :method:Symfony\\Component\\HttpFoundation\\Response::setEtag() `;
285
- * ` :method:Symfony\\Component\\HttpFoundation\\Response::setVary() `;
286
-
287
- The ` :method:Symfony\\Component\\HttpFoundation\\Response::setCache() ` method
275
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::setPublic() `;
276
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::setPrivate() `;
277
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::expire() `;
278
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::setExpires() `;
279
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::setMaxAge() `;
280
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::setSharedMaxAge() `;
281
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::setTtl() `;
282
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::setClientTtl() `;
283
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::setLastModified() `;
284
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::setEtag() `;
285
+ * :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::setVary() `;
286
+
287
+ The :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::setCache() ` method
288
288
can be used to set the most commonly used cache information in one method
289
289
call::
290
290
@@ -299,7 +299,7 @@ call::
299
299
300
300
To check if the Response validators (``ETag ``, ``Last-Modified ``) match a
301
301
conditional value specified in the client Request, use the
302
- ` :method:Symfony\\Component\\HttpFoundation\\Response::isNotModified() `
302
+ :method: ` Symfony\\ Component\\ HttpFoundation\\ Response::isNotModified() `
303
303
method::
304
304
305
305
if ($response->isNotModified($request)) {
@@ -313,7 +313,7 @@ Redirecting the User
313
313
~~~~~~~~~~~~~~~~~~~~
314
314
315
315
To redirect the client to another URL, you can use the
316
- ` :class:Symfony\\Component\\HttpFoundation\\RedirectResponse ` class::
316
+ :class: ` Symfony\\ Component\\ HttpFoundation\\ RedirectResponse ` class::
317
317
318
318
use Symfony\Component\HttpFoundation\RedirectResponse;
319
319
@@ -325,7 +325,7 @@ Streaming a Response
325
325
.. versionadded :: 2.1
326
326
Support for streamed responses was added in Symfony 2.1.
327
327
328
- The ` :class:Symfony\\Component\\HttpFoundation\\StreamedResponse ` class allows
328
+ The :class: ` Symfony\\ Component\\ HttpFoundation\\ StreamedResponse ` class allows
329
329
you to stream the Response back to the client. The response content is
330
330
represented by a PHP callable instead of a string::
331
331
@@ -350,7 +350,7 @@ Downloading Files
350
350
When uploading a file, you must add a ``Content-Disposition `` header to your
351
351
response. While creating this header for basic file downloads is easy, using
352
352
non-ASCII filenames is more involving. The
353
- ` :method::Symfony\\Component\\HttpFoundation\\Response:makeDisposition() `
353
+ :method: ` :Symfony\\ Component\\ HttpFoundation\\ Response:makeDisposition() `
354
354
abstracts the hard work behind a simple API::
355
355
356
356
use Symfony\\Component\\HttpFoundation\\ResponseHeaderBag;
0 commit comments