/** * {@inheritdoc} */ public function write($sessionId, $sessionData) { if (isset($this->readSessions[$sessionId]) && $sessionData === $this->readSessions[$sessionId]) { return true; } return $this->wrappedSessionHandler->write($sessionId, $sessionData); }
/** * {@inheritdoc} */ public function write($session_id, $session_data) { $trace = \Drupal::service('session_test.session_handler_proxy_trace'); $trace[] = ['BEGIN', $this->optionalArgument, __FUNCTION__, $session_id]; $result = $this->sessionHandler->write($session_id, $session_data); $trace[] = ['END', $this->optionalArgument, __FUNCTION__, $session_id]; return $result; }
/** * {@inheritdoc} */ public function write($session_id, $session_data) { if ($this->isSessionWritable()) { return $this->wrappedSessionHandler->write($session_id, $session_data); } else { return TRUE; } }
/** * @param ResponseInterface $response * @param Storage $storage * @return ResponseInterface */ public function writeToResponse(ResponseInterface $response, Storage $storage) { $this->handler->write($this->id, $storage->toArray()); if ($this->reset) { return $response->withHeader('Set-Cookie', "{$this->name}={$this->id}"); } return $response; }
/** * @param \Wandu\Http\Contracts\SessionInterface $session * @param \Wandu\Http\Contracts\CookieJarInterface $cookieJar * @return \Wandu\Http\Contracts\SessionInterface $session */ public function toCookieJar(SessionInterface $session, CookieJarInterface $cookieJar) { $sessionName = $this->config['name']; // save to handler $this->handler->write($session->getId(), serialize($session->getRawParams())); // apply to cookie-jar $cookieJar->set($sessionName, $session->getId(), (new DateTime())->setTimestamp(time() + $this->config['timeout'])); // garbage collection $pick = rand(1, max(1, $this->config['gc_frequency'])); if ($pick === 1) { $this->handler->gc($this->config['timeout']); } return $session; }
/** * {@inheritdoc} */ public function save() { $this->addBagDataToSession(); $this->ageFlashData(); $this->handler->write($this->getId(), $this->prepareForStorage(serialize($this->attributes))); $this->started = false; }
protected function write() { $data = $this->serializer->serialize($this->data); if ($this->options->getBoolean('lazy_write', false) && $this->handler instanceof LazyWriteHandlerInterface && md5($data) === $this->dataHash) { $this->handler->updateTimestamp($this->id, $data); } else { $this->handler->write($this->id, $data); } }
public function testGarbageCollection() { $countOfSessionFiles = $this->getCountOfSessionFiles(); $this->adapter->write('1', 'string 1'); $this->adapter->write('2', 'string 2'); $this->adapter->write('3', 'string 3'); // increase 3 files $this->assertEquals($this->getCountOfSessionFiles(), $countOfSessionFiles + 3); $this->assertTrue($this->adapter->gc(1)); $this->assertEquals('string 1', $this->adapter->read('1')); $this->assertEquals('string 2', $this->adapter->read('2')); $this->assertEquals('string 3', $this->adapter->read('3')); sleep(2); $this->assertTrue($this->adapter->gc(1)); // decrease 3 files $this->assertEquals($this->getCountOfSessionFiles(), $countOfSessionFiles); $this->assertEquals('', $this->adapter->read('1')); $this->assertEquals('', $this->adapter->read('2')); $this->assertEquals('', $this->adapter->read('3')); }
/** * {@inheritdoc} */ public function save() { if (!$this->started || $this->closed) { throw new \RuntimeException('Trying to save a session that was not started yet or was already closed'); } $data = $this->serializer->serialize($this->data); $this->handler->write($this->id, $data); $this->handler->close(); $this->closed = true; $this->started = false; }
/** * {@inheritdoc} */ public function write($sessionId, $data) { return (bool) $this->handler->write($sessionId, $data); }
/** * Write values to handler. */ private function writeToHandler() { $values = $this->values; $values[self::METADATA_NAMESPACE] = ['firstTrace' => $this->firstTrace, 'lastTrace' => $this->lastTrace, 'regenerationTrace' => $this->regenerationTrace, 'requestsCount' => $this->requestsCount, 'fingerprint' => $this->fingerprint]; $this->handler->write($this->id, $this->encrypter->encrypt(json_encode($values, \JSON_PRESERVE_ZERO_FRACTION))); }