public function testEverything() { $id = new SessionId('foo'); $this->assertSame('foo', $id->getId()); $this->assertSame('foo', (string) $id); $id->setId('bar'); $this->assertSame('bar', $id->getId()); $this->assertSame('bar', (string) $id); }
/** * @param SessionId $id Session ID object * @param SessionInfo $info Session info to populate from * @param CachedBagOStuff $store Backend data store * @param LoggerInterface $logger * @param int $lifetime Session data lifetime in seconds */ public function __construct(SessionId $id, SessionInfo $info, CachedBagOStuff $store, LoggerInterface $logger, $lifetime) { $phpSessionHandling = \RequestContext::getMain()->getConfig()->get('PHPSessionHandling'); $this->usePhpSessionHandling = $phpSessionHandling !== 'disable'; if ($info->getUserInfo() && !$info->getUserInfo()->isVerified()) { throw new \InvalidArgumentException("Refusing to create session for unverified user {$info->getUserInfo()}"); } if ($info->getProvider() === null) { throw new \InvalidArgumentException('Cannot create session without a provider'); } if ($info->getId() !== $id->getId()) { throw new \InvalidArgumentException('SessionId and SessionInfo don\'t match'); } $this->id = $id; $this->user = $info->getUserInfo() ? $info->getUserInfo()->getUser() : new User(); $this->store = $store; $this->logger = $logger; $this->lifetime = $lifetime; $this->provider = $info->getProvider(); $this->persist = $info->wasPersisted(); $this->remember = $info->wasRemembered(); $this->forceHTTPS = $info->forceHTTPS(); $this->providerMetadata = $info->getProviderMetadata(); $blob = $store->get(wfMemcKey('MWSession', (string) $this->id)); if (!is_array($blob) || !isset($blob['metadata']) || !is_array($blob['metadata']) || !isset($blob['data']) || !is_array($blob['data'])) { $this->data = []; $this->dataDirty = true; $this->metaDirty = true; $this->logger->debug('SessionBackend "{session}" is unsaved, marking dirty in constructor', ['session' => $this->id]); } else { $this->data = $blob['data']; if (isset($blob['metadata']['loggedOut'])) { $this->loggedOut = (int) $blob['metadata']['loggedOut']; } if (isset($blob['metadata']['expires'])) { $this->expires = (int) $blob['metadata']['expires']; } else { $this->metaDirty = true; $this->logger->debug('SessionBackend "{session}" metadata dirty due to missing expiration timestamp', ['session' => $this->id]); } } $this->dataHash = md5(serialize($this->data)); }