diff --git a/cookbook/session/index.rst b/cookbook/session/index.rst new file mode 100644 index 00000000000..687148dcd10 --- /dev/null +++ b/cookbook/session/index.rst @@ -0,0 +1,7 @@ +Sessions +======== + +.. toctree:: + :maxdepth: 2 + + proxy_examples diff --git a/cookbook/session/proxy_examples.rst b/cookbook/session/proxy_examples.rst new file mode 100644 index 00000000000..16ff6e0f1d9 --- /dev/null +++ b/cookbook/session/proxy_examples.rst @@ -0,0 +1,89 @@ +.. index:: + single: Sessions, session proxy, proxy + +Session Proxy Examples +---------------------- + +The session proxy mechanism has a variety of uses, this +example demonstrates two common uses. Rather than injecting +the session handler as normal, a handler is injected into the proxy +and registered with the session storage driver:: + + key = $key; + + parent::__construct($handler); + } + + public function read($id) + { + $data = parent::write($id, $data); + + return mcrypt_decrypt(\MCRYPT_3DES, $this->key, $data); + } + + public function write($id, $data) + { + $data = mcrypt_encrypt(\MCRYPT_3DES, $this->key, $data); + + return parent::write($id, $data); + } + } + + +Readonly Guest sessions +----------------------- + +There are some applications where a session is required for guest +users, but there is no particular need persist the session. In this +case you can intercept the session before it writes:: + + user = $user; + + parent::__construct($handler); + } + + public function write($id, $data) + { + if ($this->user->isGuest()) { + return; + } + + return parent::write($id, $data); + } + } +