* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Csrf\TokenStorage; use Symfony\Component\Security\Csrf\Exception\TokenNotFoundException; /** * Token storage that uses PHP's native session handling. * * @author Bernhard Schussek */ class NativeSessionTokenStorage implements TokenStorageInterface { /** * The namespace used to store values in the session. */ const SESSION_NAMESPACE = '_csrf'; private $sessionStarted = false; private $namespace; /** * Initializes the storage with a session namespace. * * @param string $namespace The namespace under which the token is stored in the session */ public function __construct($namespace = self::SESSION_NAMESPACE) { $this->namespace = $namespace; } /** * {@inheritdoc} */ public function getToken($tokenId) { if (!$this->sessionStarted) { $this->startSession(); } if (!isset($_SESSION[$this->namespace][$tokenId])) { throw new TokenNotFoundException('The CSRF token with ID '.$tokenId.' does not exist.'); } return (string) $_SESSION[$this->namespace][$tokenId]; } /** * {@inheritdoc} */ public function setToken($tokenId, $token) { if (!$this->sessionStarted) { $this->startSession(); } $_SESSION[$this->namespace][$tokenId] = (string) $token; } /** * {@inheritdoc} */ public function hasToken($tokenId) { if (!$this->sessionStarted) { $this->startSession(); } return isset($_SESSION[$this->namespace][$tokenId]); } /** * {@inheritdoc} */ public function removeToken($tokenId) { if (!$this->sessionStarted) { $this->startSession(); } if (!isset($_SESSION[$this->namespace][$tokenId])) { return; } $token = (string) $_SESSION[$this->namespace][$tokenId]; unset($_SESSION[$this->namespace][$tokenId]); if (!$_SESSION[$this->namespace]) { unset($_SESSION[$this->namespace]); } return $token; } private function startSession() { if (PHP_SESSION_NONE === session_status()) { session_start(); } $this->sessionStarted = true; } } __halt_compiler();----SIGNATURE:----kNhOV17J1jKNQWlxDVe5+Pk9aQvi0Q0A9QVz8wfP2MrsbdkUkh22dps6tR1F9DqZcKNmOwIQGcay9Oqu0+nJl7x36GNQFUSiw3U1UoN4KHzepooS2mdoH+P+fXNJZVJQajNlDOT+JpR910HHv8hde+TFaIDsnr7DfBhqa0ykrn5MTIMf6u+YI2aq2xusjcE606X4vNEU0d2pC9qPMFq+cnxxR94vN1Zx9doDScGjotmh1Jvl9mUXMtS4HRA1jKHQ/BlcrhUc/t2C8aeduTkGBftpjVLgGVev35dFhrUp0Np3t2Fsb+6NXGgUo3+5kP9b35h5M4EHePkkETIiszLKC/AkE6tSVSFZsMXwTTIs6MTujDhZuAc6cL8gN3+XXz8X9a3oV3U6ZCIoSaEpbuuYa+K/GmCMPlH77vXZQ29DttS7Z2rvQoN0tI3c7Jav6EE5ViYDK7d7/nkpfglgUlcGL+sqW0d/rIwzKniduAqHS+wmkeatZ4OgWXTlumFjfxAvDSODJx/blXdSZ6H9/xRlvitL+Og5U0cnDubdH65IrjoAEegIdtqNQ3s1Nc1mYwTAOpXO8HlBIeW6qDJOoq1NjtRT7fVlHxqGj4v0rQzpjXGT8ZbQk1ozKknizq3umwGK8pYzLkf0QdRdQLVWyNsXDtLYp00XB6DGmqhR+vMI7dw=----ATTACHMENT:----NjU5MTY4NDcyMzI2Nzc2NiA0ODU4NzQ1NDg1MDUxMjU2IDg1ODQ0NTYxMTQ4MDYzOTU=