@@ -382,7 +382,10 @@ The Symfony2 HttpFoundation Component has a very powerful and flexible session
382
382
subsystem which is designed to provide session management through a simple
383
383
object-oriented interface using a variety of session storage drivers.
384
384
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::
386
389
387
390
use Symfony\\Component\\HttpFoundation\\Session\\Session;
388
391
@@ -408,24 +411,25 @@ is called randomly according to PHP's configuration and if called, it is invoked
408
411
after the `open ` operation). You can read more about this at
409
412
http://php.net/session.customhandler
410
413
414
+
411
415
Native PHP Save Handlers
412
416
~~~~~~~~~~~~~~~~~~~~~~~~
413
417
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
417
421
`ini_set('session.save_handler', $name); ` and are usually configured with
418
422
`ini_set('session.save_path', $path); ` and sometimes, a variety of other PHP
419
423
`ini ` directives.
420
424
421
425
Symfony2 provides drivers for native handlers which are easy to configure, these are:
422
426
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 `;
427
431
428
- Example of use:
432
+ Example of use::
429
433
430
434
use Symfony\\Component\\HttpFoundation\\Session\\Session;
431
435
use Symfony\\Component\\HttpFoundation\\Session\\Storage\\NativeSessionStorage;
@@ -444,12 +448,12 @@ various points in the session workflow.
444
448
Symfony2 HttpFoudation provides some by default and these can easily serve as
445
449
examples if you wish to write your own.
446
450
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 `;
451
455
452
- Example:
456
+ Example::
453
457
454
458
use Symfony\\Component\\HttpFoundation\\Session\\Session;
455
459
use Symfony\\Component\\HttpFoundation\\Session\\Storage\\SessionStorage;
@@ -467,7 +471,7 @@ OOP paradigm. To help overcome this Symfony2 uses 'session bags' linked to the
467
471
session to encapsulate a specific dataset like 'attributes' or 'flash messages'.
468
472
469
473
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.
471
475
This allows Symfony2 to peacefully co-exist with other applications or libraries
472
476
that might use the `$_SESSION ` super-global and all data remains completely
473
477
compatible with Symfony2's session management.
@@ -479,13 +483,14 @@ bag types if necessary.
479
483
Attributes
480
484
~~~~~~~~~~
481
485
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.
485
489
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.
489
494
490
495
Any plain `key => value ` storage system is limited in the extent to which
491
496
complex data can be stored since each key must be unique. You can achieve
@@ -500,14 +505,14 @@ store it again.
500
505
'b' => 'f4a7b1f3')
501
506
502
507
So any processing of this might quickly get ugly, even simply adding a token to
503
- the array:
508
+ the array::
504
509
505
510
$tokens = $session->get('tokens');
506
511
$tokens['c'] = $value;
507
512
$session->set('tokens', $tokens);
508
513
509
514
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 `/ `)::
511
516
512
517
$session->set('tokens/c', $value);
513
518
@@ -516,19 +521,21 @@ This way you can easily access a key within the stored array directly and easily
516
521
Flash messages
517
522
~~~~~~~~~~~~~~
518
523
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
529
535
be available for display only on the next page load. These messages will auto
530
536
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
532
539
they are explicitly retrieved or cleared. This makes it possible to use ESI
533
540
caching.
534
541
@@ -539,7 +546,7 @@ Symfony2 is designed from the ground up with code-testability in mind. In order
539
546
to make your code which utilises session easily testable we provide two separate
540
547
mock storage mechanisms for both unit testing and functional testing.
541
548
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
543
550
and it is not possible to have multiple concurrent sessions in the same PHP
544
551
process.
545
552
@@ -555,7 +562,7 @@ Unit Testing
555
562
556
563
For unit testing where it is not necessary to persist the session, you should
557
564
simply swap out the default storage engine with
558
- `Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockArraySessionStorage `.
565
+ :class: `Symfony\\ Component\\ HttpFoundation\\ Session\\ Storage\\ MockArraySessionStorage `::
559
566
560
567
use Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockArraySessionStorage;
561
568
use Symfony\\Component\\HttpFoundation\\Session\\Session;
@@ -567,39 +574,39 @@ Functional Testing
567
574
568
575
For functional testing where you may need to persist session data across
569
576
separate PHP processes, simply change the storage engine to
570
- `Symfony\\Component\\HttpFoundation\\SessionMockFileSessionStorage `.
577
+ :class: `Symfony\\ Component\\ HttpFoundation\\ Session \\ Storage \\ MockFileSessionStorage `::
571
578
572
579
use Symfony\\Component\\HttpFoundation\\Session\\Session;
573
- use Symfony\\ Component\\ HttpFoundation\\ Session\\ Storage\\ MockFileessionStorage ;
580
+ use Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockFileSessionStorage ;
574
581
575
582
$session = new Session(new MockFileSessionStorage());
576
583
577
584
PHP 5.4 compatibility
578
585
~~~~~~~~~~~~~~~~~~~~~
579
586
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
582
589
it can be used under PHP 5.3. This greatly improves inter-operability with other
583
590
libraries.
584
591
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.
588
594
589
595
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 `
591
597
which under PHP 5.4, extends from `\SessionHandler ` and under PHP 5.3 is just a
592
598
empty base class. This provides some interesting opportunities to leverage
593
599
PHP 5.4 functionality if it is available.
594
600
595
601
Handler Proxy
596
602
~~~~~~~~~~~~~
597
603
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 `
600
607
including native handlers (those which activate internal PHP/PHP-extension
601
608
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
603
610
handlers.
604
611
605
612
In order to manage all of this, Symfony2 uses a proxy handler object. It means
0 commit comments