* * 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:----mZ+WDYHnFalJ/OCv3o2GxCtjlEbpLV9aRdcB+DmWiAS1I9vkI+8AqufE9JUlwhJpmBcsSfge3Ac6iRGimmdXLXkSjLqobrSPGN8TG9tDWxo5CbMEoPJQN27ByE5pbpPQxTlNeseUCYAmXkNTyLjdlpo6Sai3D/QMOG2Vat7HA2GwljtEzyBL0ZVzoBd9tJxm6HIwVxv8ENtj7nYzPUDe1fbrRJIBl//BwSoTFwL/j32AyRVop8hoitEl4AB3/CddPgx0VBncnIEMwNmdHPY1GWj3iVPDL7C8ZI26741HMArjhMdKfIMV2iWicCc2zgYEuk0GeUc68foCgTr0sPyy7kQHvMZvV+6secczHmMj8A1emxii3PgEovkIDQtE3bHYNgODnCRhOSgBpOpMg/TjFJxHKJx7EgquNwwpHB6uCKkSEYtmFo8m1chw+b7C1k4XXPkz0cnuBYA7Ct7DbMXWw5ga+caCEbCE77R/P7vec51ppXWCa4SGZYfW4vhpGrYziEdRKeMAHYJllgcADEq+SlWaCockzIBEqyTj2UYabJ4rh/TisynjGHo++cfDtrgGRsMmXU6RAOmuf740basJjIl1+hDJMQ3UO2dlJJ26Z7HSlFTtzn7BdDqYgGBM6N3Fi3A0ztwsPtBmDXICKSgY9iCVdjaw/AI7RtxGBlpnwtU=----ATTACHMENT:----MTcyOTYxNjA3NTM5MjU2OCAyOTg0MDkyNDc0NzY3NjMyIDEwMjM0MDQxNzY0OTg1Nzg=