8000 Proofreading and tweaking the 2.1 session changes for the HttpFoundat… · symfony/symfony-docs@679374b · GitHub
[go: up one dir, main page]

Skip to content

Commit 679374b

Browse files
committed
Proofreading and tweaking the 2.1 session changes for the HttpFoundation component - see #1154
1 parent 92f0b58 commit 679374b

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

components/http_foundation.rst

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ The Symfony2 HttpFoundation Component has a very powerful and flexible session
382382
subsystem which is designed to provide session management through a simple
383383
object-oriented interface using a variety of session storage drivers.
384384

385+
.. versionadded:: 2.1
386+
The :class:`Symfony\\Component\\HttpFoundation\\Session\\SessionInterface` interface,
387+
as well as a number of other changes, are new as of Symfony 2.1.
388+
385389
Sessions are used via the simple :class:`Symfony\\Component\\HttpFoundation\\Session\\Session`
386390
implementation of :class:`Symfony\\Component\\HttpFoundation\\Session\\SessionInterface` interface.
387391

@@ -404,7 +408,7 @@ Quick example::
404408
Session API
405409
~~~~~~~~~~~
406410

407-
The :class:`Symfony\\Component\\HttpFoundation\\Session\\Session` implements
411+
The :class:`Symfony\\Component\\HttpFoundation\\Session\\Session` class implements
408412
:class:`Symfony\\Component\\HttpFoundation\\Session\\SessionInterface.
409413
410414
The :class:`Symfony\\Component\\HttpFoundation\\Session\\Session` has a simple API
@@ -413,18 +417,18 @@ as follows divided into a couple of groups.
413417
Session workflow
414418

415419
* :method:`Symfony\\Component\\HttpFoundation\\Session\\Session::start`:
416-
Starts the session - do not use `session_start()`.
420+
Starts the session - do not use ``session_start()``.
417421

418422
* :method:`Symfony\\Component\\HttpFoundation\\Session\\Session::migrate`:
419-
Starts the session - do not use `session_start()`.
423+
Regenerates the session id - do not use ``session_regenerate_id()``.
420424

421425
* :method:`Symfony\\Component\\HttpFoundation\\Session\\Session::invalidate`:
422-
Starts the session - do not use `session_start()`.
426+
Clears the session data and regenerates the session id do not use ``session_destroy()``.
423427

424428
* :method:`Symfony\\Component\\HttpFoundation\\Session\\Session::getId`: Gets the
425429
session ID.
426430

427-
* :method:`Symfony\\Component\\HttpFoundation\\Session\\Session::setId`: Gets the
431+
* :method:`Symfony\\Component\\HttpFoundation\\Session\\Session::setId`: Sets the
428432
session ID.
429433

430434
* :method:`Symfony\\Component\\HttpFoundation\\Session\\Session::getName`: Gets the
@@ -457,9 +461,10 @@ Session attributes
457461
Deletes an attribute by key;
458462

459463
* :method:`Symfony\\Component\\HttpFoundation\\Session\\Session::clear`:
460-
Clear the bag;
464+
Clear all attributes;
461465

462-
Bag management
466+
The attributes are stored internally in an "Bag", a PHP object that acts like
467+
an array. A few methods exist for "Bag" management:
463468

464469
* :method:`Symfony\\Component\\HttpFoundation\\Session\\Session::registerBag`:
465470
Registers a `Symfony\\Component\\HttpFoundation\\Session\\SessionBagInterface`
@@ -472,9 +477,6 @@ Bag management
472477
Gets the `Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface`.
473478
This is just a shortcut for convenience.
474479

475-
476-
477-
478480
Save Handlers
479481
~~~~~~~~~~~~~
480482

@@ -483,7 +485,7 @@ session follows `open`, `read`, `write` and `close`, with the possibility of
483485
`destroy` and `gc` (garbage collection which will expire any old sessions: `gc`
484486
is called randomly according to PHP's configuration and if called, it is invoked
485487
after the `open` operation). You can read more about this at
486-
http://php.net/session.customhandler
488+
`php.net/session.customhandle`_
487489

488490

489491
Native PHP Save Handlers
@@ -519,7 +521,7 @@ Custom handlers are those which completely replace PHP's built in session save
519521
handlers by providing six callback functions which PHP calls internally at
520522
various points in the session workflow.
521523

522-
Symfony2 HttpFoudation provides some by default and these can easily serve as
524+
Symfony2 HttpFoundation provides some by default and these can easily serve as
523525
examples if you wish to write your own.
524526

525527
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler`;
@@ -541,8 +543,8 @@ Session Bags
541543

542544
PHP's session management requires the use of the `$_SESSION` super-global,
543545
however, this interferes somewhat with code testability and encapsulation in a
544-
OOP paradigm. To help overcome this Symfony2 uses 'session bags' linked to the
545-
session to encapsulate a specific dataset like 'attributes' or 'flash messages'.
546+
OOP paradigm. To help overcome this, Symfony2 uses 'session bags' linked to the
547+
session to encapsulate a specific dataset of 'attributes' or 'flash messages'.
546548

547549
This approach also mitigates namespace pollution within the `$_SESSION`
548550
super-global because each bag stores all its data under a unique namespace.
@@ -577,15 +579,16 @@ and remember me login settings or other user based state information.
577579

578580
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBag`
579581
This is the standard default implementation.
582+
580583
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\NamespacedAttributeBag`
581584
This implementation allows for attributes to be stored in a structured namespace.
582585

583586
Any plain `key => value` storage system is limited in the extent to which
584-
complex data can be stored since each key must be unique. You can achieve
587+
complex data can be stored since each key must be unique. You can achieve
585588
namespacing by introducing a naming convention to the keys so different parts of
586-
your application could operate without clashing. For example, `module1.foo` and
589+
your application could operate without clashing. For example, `module1.foo` and
587590
`module2.foo`. However, sometimes this is not very practical when the attributes
588-
data is an array, for example a set of tokens. In this case, managing the array
591+
data is an array, for example a set of tokens. In this case, managing the array
589592
becomes a burden because you have to retrieve the array then process it and
590593
store it again.
591594

@@ -639,19 +642,20 @@ Flash messages
639642
The purpose of the :class:`Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface`
640643
is to provide a way of settings and retrieving messages on a per session basis.
641644
The usual workflow for flash messages would be set in an request, and displayed
642-
on page redirect. For example, a user submits a form which hits an update
645+
after a page redirect. For example, a user submits a form which hits an update
643646
controller, and after processing the controller redirects the page to either the
644-
updated page or a error page. Flash messages set in the previous page request
647+
updated page or an error page. Flash messages set in the previous page request
645648
would be displayed immediately on the subsequent page load for that session.
646649
This is however just one application for flash messages.
647650

648651
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Flash\\AutoExpireFlashBag`
649652
This implementation messages set in one page-load will
650653
be available for display only on the next page load. These messages will auto
651654
expire regardless of if they are retrieved or not.
655+
652656
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBag`
653657
In this implementation, messages will remain in the session until
654-
they are explicitly retrieved or cleared. This makes it possible to use ESI
658+
they are explicitly retrieved or cleared. This makes it possible to use ESI
655659
caching.
656660

657661
:class:`Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface`
@@ -673,7 +677,7 @@ has a simple API
673677
Gets a flash by type (read only);
674678

675679
* :method:`Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface::peekAll`:
676-
Gets all flashes (readoly);
680+
Gets all flashes (read only);
677681

678682
* :method:`Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface::has`:
679683
Returns true if the type exists;
@@ -687,26 +691,26 @@ has a simple API
687691
Testability
688692
-----------
689693

690-
Symfony2 is designed from the ground up with code-testability in mind. In order
691-
to make your code which utilises session easily testable we provide two separate
694+
Symfony2 is designed from the ground up with code-testability in mind. In order
695+
to make your code which utilizes session easily testable we provide two separate
692696
mock storage mechanisms for both unit testing and functional testing.
693697

694698
Testing code using real sessions is tricky because PHP's workflow state is global
695699
and it is not possible to have multiple concurrent sessions in the same PHP
696700
process.
697701

698702
The mock storage engines simulate the PHP session workflow without actually
699-
starting one allowing you to test your code without complications. You may also
703+
starting one allowing you to test your code without complications. You may also
700704
run multiple instances in the same PHP process.
701705

702706
The mock storage drivers do not read or write the system globals
703-
`session_id()` or `session_name()`. Methods are provided to simulate this if
707+
`session_id()` or `session_name()`. Methods are provided to simulate this if
704708
required:
705709

706710
* :method:`Symfony\\Component\\HttpFoundation\\Session\\SessionStorageInterface::getId`: Gets the
707711
session ID.
708712

709-
* :method:`Symfony\\Component\\HttpFoundation\\Session\\SessionStorageInterface::setId`: Gets the
713+
* :method:`Symfony\\Component\\HttpFoundation\\Session\\SessionStorageInterface::setId`: Sets the
710714
session ID.
711715

712716
* :method:`Symfony\\Component\\HttpFoundation\\Session\\SessionStorageInterface::getName`: Gets the
@@ -753,14 +757,14 @@ handlers to PHP user-space.
753757
In order to provide a solution for those using PHP 5.4, Symfony2 has a special
754758
class called :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeSessionHandler`
755759
which under PHP 5.4, extends from `\SessionHandler` and under PHP 5.3 is just a
756-
empty base class. This provides some interesting opportunities to leverage
760+
empty base class. This provides some interesting opportunities to leverage
757761
PHP 5.4 functionality if it is available.
758762

759763
Save Handler Proxy
760764
~~~~~~~~~~~~~~~~~~
761765

762-
There are two kinds of save handler classes proxy which inherit from
763-
:class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\AbstractProxy`,
766+
There are two kinds of save handler class proxies which inherit from
767+
:class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\AbstractProxy`:
764768
they are :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeProxy`
765769
and :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\SessionHandlerProxy`.
766770

@@ -778,5 +782,8 @@ Under PHP 5.4 and above, all session handlers implement :phpclass:`SessionHandle
778782
including `Native*SessionHandler` classes which inherit from :phpclass:`SessionHandler`.
779783

780784
The proxy mechanism allow you to get more deeply involved in session save handler
781-
classes. A proxy for example could be used to encrypt any session transaction
785+
classes. A proxy for example could be used to encrypt any session transaction
782786
without knowledge of the specific save handler.
787+
788+
789+
.. _`php.net/session.customhandle`: http://php.net/session.customhandler

0 commit comments

Comments
 (0)
0