SessionHandlerProxy.php
102 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | |
| 12 | namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy; |
| 13 | |
| 14 | /** |
| 15 | * @author Drak <drak@zikula.org> |
| 16 | */ |
| 17 | class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface |
| 18 | { |
| 19 | protected $handler; |
| 20 | |
| 21 | public function __construct(\SessionHandlerInterface $handler) |
| 22 | { |
| 23 | $this->handler = $handler; |
| 24 | $this->wrapper = ($handler instanceof \SessionHandler); |
| 25 | $this->saveHandlerName = $this->wrapper ? ini_get('session.save_handler') : 'user'; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @return \SessionHandlerInterface |
| 30 | */ |
| 31 | public function getHandler() |
| 32 | { |
| 33 | return $this->handler; |
| 34 | } |
| 35 | |
| 36 | // \SessionHandlerInterface |
| 37 | |
| 38 | /** |
| 39 | * {@inheritdoc} |
| 40 | */ |
| 41 | public function open($savePath, $sessionName) |
| 42 | { |
| 43 | return (bool) $this->handler->open($savePath, $sessionName); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * {@inheritdoc} |
| 48 | */ |
| 49 | public function close() |
| 50 | { |
| 51 | return (bool) $this->handler->close(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * {@inheritdoc} |
| 56 | */ |
| 57 | public function read($sessionId) |
| 58 | { |
| 59 | return (string) $this->handler->read($sessionId); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * {@inheritdoc} |
| 64 | */ |
| 65 | public function write($sessionId, $data) |
| 66 | { |
| 67 | return (bool) $this->handler->write($sessionId, $data); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * {@inheritdoc} |
| 72 | */ |
| 73 | public function destroy($sessionId) |
| 74 | { |
| 75 | return (bool) $this->handler->destroy($sessionId); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @return bool |
| 80 | */ |
| 81 | public function gc($maxlifetime) |
| 82 | { |
| 83 | return (bool) $this->handler->gc($maxlifetime); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * {@inheritdoc} |
| 88 | */ |
| 89 | public function validateId($sessionId) |
| 90 | { |
| 91 | return !$this->handler instanceof \SessionUpdateTimestampHandlerInterface || $this->handler->validateId($sessionId); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * {@inheritdoc} |
| 96 | */ |
| 97 | public function updateTimestamp($sessionId, $data) |
| 98 | { |
| 99 | return $this->handler instanceof \SessionUpdateTimestampHandlerInterface ? $this->handler->updateTimestamp($sessionId, $data) : $this->write($sessionId, $data); |
| 100 | } |
| 101 | } |
| 102 |