public function storeSession(Session $session) { $context = new Context(); if (!$context->IsCliInvocation) { session_start(); } $namespace = $session->getNamespace(); $_SESSION[$namespace] = $session->exportRawData(); // Close the session to make sure we aren't locking other process for this user, e.g. // simultaneous AJAX requests. if (!$context->IsCliInvocation) { session_write_close(); } }
public function testSessionGetsProvider() { Session::setDefaultSessionProviderClassName("Rhubarb\\Crown\\Tests\\Sessions\\UnitTestingSessionProvider"); $session = new UnitTestingSession(); $this->assertInstanceOf("Rhubarb\\Crown\\Tests\\Sessions\\UnitTestingSessionProvider", $session->testGetSessionProvider()); Session::setDefaultSessionProviderClassName("Rhubarb\\Crown\\Sessions\\SessionProviders\\PhpSessionProvider"); // Although we have changed the default provider, we already instantiated the session so the provider will not // have changed $this->assertInstanceOf("Rhubarb\\Crown\\Tests\\Sessions\\UnitTestingSessionProvider", $session->testGetSessionProvider()); }
public function extractSessionData() { $data = parent::extractSessionData(); $encrypted = []; $keySalt = $this->getEncryptionKeySalt(); $provider = Container::instance(EncryptionProvider::class); foreach ($data as $key => $value) { if (is_object($value) || is_array($value)) { continue; } $encrypted[$key] = $provider->encrypt($value, $keySalt); } return $encrypted; }
public function __get($propertyName) { $keySalt = $this->getEncryptionKeySalt(); $provider = EncryptionProvider::getEncryptionProvider(); return $provider->decrypt(parent::__get($propertyName), $keySalt); }