8000 Corrections · symfony/symfony-docs@66ce132 · GitHub
[go: up one dir, main page]

Skip to content

Commit 66ce132

Browse files
author
Drak
committed
Corrections
1 parent f8e9fc3 commit 66ce132

File tree

1 file changed

+54
-47
lines changed

1 file changed

+54
-47
lines changed

components/http_foundation.rst

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +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-
Quick example:
385+
Sessions are used via the simple :class:`Symfony\\Component\\HttpFoundation\\Session\\Session`
386+
implementation of :class:`Symfony\\Component\\HttpFoundation\\Session\\SessionInterface` interface.
387+
388+
Quick example::
386389

387390
use Symfony\\Component\\HttpFoundation\\Session\\Session;
388391

@@ -408,24 +411,25 @@ is called randomly according to PHP's configuration and if called, it is invoked
408411
after the `open` operation). You can read more about this at
409412
http://php.net/session.customhandler
410413

414+
411415
Native PHP Save Handlers
412416
~~~~~~~~~~~~~~~~~~~~~~~~
413417

414-
So-called 'native' handlers are session handlers are either compiled into PHP or
415-
provided by PHP extensions, such as PHP-Sqlite, PHP-Memcached and so on. The
416-
handlers are compiled and can be activated directly in PHP using
418+
So-called 'native' handlers, are session handlers which are either compiled into
419+
PHP or provided by PHP extensions, such as PHP-Sqlite, PHP-Memcached and so on.
420+
The handlers are compiled and can be activated directly in PHP using
417421
`ini_set('session.save_handler', $name);` and are usually configured with
418422
`ini_set('session.save_path', $path);` and sometimes, a variety of other PHP
419423
`ini` directives.
420424

421425
Symfony2 provides drivers for native handlers which are easy to configure, these are:
422426

423-
* `Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeFileSessionHandler`
424-
* `Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeSqliteSessionHandler`
425-
* `Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeMemcacheSessionHandler`
426-
* `Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeMemcachedSessionHandler`
427+
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeFileSessionHandler`;
428+
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeSqliteSessionHandler`;
429+
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeMemcacheSessionHandler`;
430+
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeMemcachedSessionHandler`;
427431

428-
Example of use:
432+
Example of use::
429433

430434
use Symfony\\Component\\HttpFoundation\\Session\\Session;
431435
use Symfony\\Component\\HttpFoundation\\Session\\Storage\\NativeSessionStorage;
@@ -444,12 +448,12 @@ various points in the session workflow.
444448
Symfony2 HttpFoudation provides some by default and these can easily serve as
445449
examples if you wish to write your own.
446450

447-
* `Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler`
448-
* `Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MemcacheSessionHandler`
449-
* `Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MemcachedSessionHandler`
450-
* `Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NullSessionHandler`
451+
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler`;
452+
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MemcacheSessionHandler`;
453+
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MemcachedSessionHandler`;
454+
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NullSessionHandler`;
451455

452-
Example:
456+
Example::
453457

454458
use Symfony\\Component\\HttpFoundation\\Session\\Session;
455459
use Symfony\\Component\\HttpFoundation\\Session\\Storage\\SessionStorage;
@@ -467,7 +471,7 @@ OOP paradigm. To help overcome this Symfony2 uses 'session bags' linked to the
467471
session to encapsulate a specific dataset like 'attributes' or 'flash messages'.
468472

469473
This approach also mitigates namespace pollution within the `$_SESSION`
470-
super-global because each bag stores all it's data under a unique namespace.
474+
super-global because each bag stores all its data under a unique namespace.
471475
This allows Symfony2 to peacefully co-exist with other applications or libraries
472476
that might use the `$_SESSION` super-global and all data remains completely
473477
compatible with Symfony2's session management.
@@ -479,13 +483,14 @@ bag types if necessary.
479483
Attributes
480484
~~~~~~~~~~
481485

482-
The purpose of the bags implementing the `AttributeBagInterface` is to handle
483-
session attribute storage. This might include things like user ID, and remember
484-
me login settings or other user based state information.
486+
The purpose of the bags implementing the :class:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBagInterface`
487+
is to handle session attribute storage. This might include things like user ID,
488+
and remember me login settings or other user based state information.
485489

486-
* `AttributeBag` - this is the standard default implementation.
487-
* `NamespacedAttributeBag` - this implementation allows for attributes to be
488-
stored in a structured namespace.
490+
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBag`
491+
This is the standard default implementation.
492+
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\NamespacedAttributeBag`
493+
This implementation allows for attributes to be stored in a structured namespace.
489494

490495
Any plain `key => value` storage system is limited in the extent to which
491496
complex data can be stored since each key must be unique. You can achieve
@@ -500,14 +505,14 @@ store it again.
500505
'b' => 'f4a7b1f3')
501506

502507
So any processing of this might quickly get ugly, even simply adding a token to
503-
the array:
508+
the array::
504509

505510
$tokens = $session->get('tokens');
506511
$tokens['c'] = $value;
507512
$session->set('tokens', $tokens);
508513

509514
With structured namespacing, the the key can be translated to the array
510-
structure like this using a namespace character (defaults to `/`).
515+
structure like this using a namespace character (defaults to `/`)::
511516

512517
$session->set('tokens/c', $value);
513518

@@ -516,19 +521,21 @@ This way you can easily access a key within the stored array directly and easily
516521
Flash messages
517522
~~~~~~~~~~~~~~
518523

519-
The purpose of the `FlashBagInterface` is to provide a way of settings and
520-
retrieving messages on a per session basis. The usual workflow for flash
521-
messages would be set in an request, and displayed on page redirect. For
522-
example, a user submits a form which hits an update controller, and after
523-
processing the controller redirects the page to either the updated page or a
524-
error page. Flash messages set in the previous page request would be displayed
525-
immediately on the subsequent page load for that session. This is however just
526-
one application for flash messages.
527-
528-
* `AutoExpireFlashBag` - This implementation messages set in one page-load will
524+
The purpose of the :class:`Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface`
525+
is to provide a way of settings and retrieving messages on a per session basis.
526+
The usual workflow for flash messages would be set in an request, and displayed
527+
on page redirect. For example, a user submits a form which hits an update
528+
controller, and after processing the controller redirects the page to either the
529+
updated page or a error page. Flash messages set in the previous page request
530+
would be displayed immediately on the subsequent page load for that session.
531+
This is however just one application for flash messages.
532+
533+
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Flash\\AutoExpireFlashBag`
534+
This implementation messages set in one page-load will
529535
be available for display only on the next page load. These messages will auto
530536
expire regardless of if they are retrieved or not.
531-
* `FlashBag` - In this implementation, messages will remain in the session until
537+
* :class:`Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBag`
538+
In this implementation, messages will remain in the session until
532539
they are explicitly retrieved or cleared. This makes it possible to use ESI
533540
caching.
534541

@@ -539,7 +546,7 @@ Symfony2 is designed from the ground up with code-testability in mind. In order
539546
to make your code which utilises session easily testable we provide two separate
540547
mock storage mechanisms for both unit testing and functional testing.
541548

542-
Testing code using real sessions is trick because PHP's workflow state is global
549+
Testing code using real sessions is tricky because PHP's workflow state is global
543550
and it is not possible to have multiple concurrent sessions in the same PHP
544551
process.
545552

@@ -555,7 +562,7 @@ Unit Testing
555562

556563
For unit testing where it is not necessary to persist the session, you should
557564
simply swap out the default storage engine with
558-
`Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockArraySessionStorage`.
565+
:class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockArraySessionStorage`::
559566

560567
use Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockArraySessionStorage;
561568
use Symfony\\Component\\HttpFoundation\\Session\\Session;
@@ -567,39 +574,39 @@ Functional Testing
567574

568575
For functional testing where you may need to persist session data across
569576
separate PHP processes, simply change the storage engine to
570-
`Symfony\\Component\\HttpFoundation\\SessionMockFileSessionStorage`.
577+
:class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockFileSessionStorage`::
571578

572579
use Symfony\\Component\\HttpFoundation\\Session\\Session;
573-
use Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockFileessionStorage;
580+
use Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockFileSessionStorage;
574581

575582
$session = new Session(new MockFileSessionStorage());
576583

577584
PHP 5.4 compatibility
578585
~~~~~~~~~~~~~~~~~~~~~
579586

580-
Since PHP 5.4.0, `\SessionHandler` and `\SessionHandlerInterface` are available.
581-
Symfony 2.1 provides forward compatibility for the `\SessionHandlerInterface` so
587+
Since PHP 5.4.0, :phpclass:`SessionHandler` and :phpclass:`SessionHandlerInterface` are available.
588+
Symfony 2.1 provides forward compatibility for the :phpclass:`SessionHandlerInterface` so
582589
it can be used under PHP 5.3. This greatly improves inter-operability with other
583590
libraries.
584591

585-
`\SessionHandler` is a special PHP internal class which exposes native save
586-
handlers to PHP user-space. You can read more about it at
587-
http://php.net/sessionhandler.
592+
:phpclass:`SessionHandler` is a special PHP internal class which exposes native save
593+
handlers to PHP user-space.
588594

589595
In order to provide a solution for those using PHP 5.4, Symfony2 has a special
590-
class called `Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeSessionHandler`
596+
class called :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeSessionHandler`
591597
which under PHP 5.4, extends from `\SessionHandler` and under PHP 5.3 is just a
592598
empty base class. This provides some interesting opportunities to leverage
593599
PHP 5.4 functionality if it is available.
594600

595601
Handler Proxy
596602
~~~~~~~~~~~~~
597603

598-
`SessionStorage` injects storage handlers into a handler proxy. The reason for
599-
this is that under PHP 5.4, all handlers implement `\SessionHandlerInterface`
604+
:class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\NativeSessionStorage`
605+
injects storage handlers into a handler proxy. The reason for this is that
606+
under PHP 5.4, all handlers implement :phpclass:`SessionHandlerInterface`
600607
including native handlers (those which activate internal PHP/PHP-extension
601608
handlers. Native handlers under PHP 5.4 will be children of
602-
`\SessionHandler` which allows one to intercept and modify even native session
609+
:phpclass:`SessionHandler` which allows one to intercept and modify even native session
603610
handlers.
604611

605612
In order to manage all of this, Symfony2 uses a proxy handler object. It means

0 commit comments

Comments
 (0)
0