Skip to content

Commit 27dff26

Browse files
committed
Documented the arguments of the Cookie class
1 parent 10ea5e9 commit 27dff26

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

components/http_foundation/introduction.rst

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ When PHP imports the request query, it handles request parameters like
165165
// returns array('bar' => 'bar')
166166

167167
$request->query->get('foo[bar]');
168-
// returns null
168+
// returns null
169169

170170
.. _component-foundation-attributes:
171171

@@ -374,7 +374,45 @@ attribute::
374374
The
375375
:method:`Symfony\\Component\\HttpFoundation\\ResponseHeaderBag::setCookie`
376376
method takes an instance of
377-
:class:`Symfony\\Component\\HttpFoundation\\Cookie` as an argument.
377+
:class:`Symfony\\Component\\HttpFoundation\\Cookie` as an argument. This class
378+
takes eight arguments in its constructor:
379+
380+
``$name``
381+
**type**: ``string`` **default**: none (this argument is mandatory)
382+
The name of the cookie.
383+
``$value``
384+
**type**: ``string`` **default**: ``null``
385+
The value stored in the cookie.
386+
``$expire``
387+
**type**: ``int``|``string``|``DateTime``|``DateTimeInterface`` **default**: 0
388+
The time the cookie expires. This value can be set as a timestamp integer,
389+
as a ``strtotime()`` valid date string (e.g. ``+1 week``), as a ``DateTime``
390+
object or as an object which implements ``DateTimeInterface``.
391+
The default value is ``0``, which deletes the cookie as soon as the browser
392+
is closed.
393+
``$path``
394+
**type**: ``string`` **default**: ``/``
395+
The path on the server in which the cookie will be available on. The default
396+
values makes the cookie available on any URL of the server.
397+
``$domain``
398+
**type**: ``string`` **default**: ``null``
399+
The domain that the cookie is available to. The default value makes the cookie
400+
available just for the current domain (and any of its subdomains).
401+
``$secure``
402+
**type**: ``bool`` **default**: ``false``
403+
Whether the cookie should only be transmitted over a secure HTTPS connection
404+
from the client.
405+
``$httpOnly``
406+
**type**: ``bool`` **default**: ``true``
407+
Whether the cookie will be made accessible only through the HTTP protocol.
408+
``$raw``
409+
.. versionadded:: 3.1
410+
The ``$raw`` argument was introduced in Symfony 3.1.
411+
412+
**type**: ``bool`` **default**: ``false``
413+
Whether the cookie value should be sent with no URL encoding. If set to
414+
``true`` the cookie is created with the ``setrawcookie()`` PHP function
415+
instead of ``setcookie()``.
378416

379417
You can clear a cookie via the
380418
:method:`Symfony\\Component\\HttpFoundation\\ResponseHeaderBag::clearCookie` method.

0 commit comments

Comments
 (0)