/** * {@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) { if ($this->isSessionWritable()) { return $this->wrappedSessionHandler->write($session_id, $session_data); } else { return TRUE; } }
/** * @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; }
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); } }
protected function collectGarbage() { $probability = $this->options->getInt('gc_probability'); if ($probability < 0) { return; } $divisor = $this->options->getInt('gc_divisor'); $rand = mt_rand(0, $divisor); if ($rand < $probability) { $this->handler->gc($this->options->getInt('gc_maxlifetime')); } }
/** * Tests that other invocations are passed unmodified to the wrapped handler. * * @covers ::setSessionWritable * @covers ::open * @covers ::read * @covers ::close * @covers ::destroy * @covers ::gc * @dataProvider providerTestOtherMethods */ public function testOtherMethods($method, $expected_result, $args) { $invocation = $this->wrappedSessionHandler->expects($this->exactly(2))->method($method)->will($this->returnValue($expected_result)); // Set the parameter matcher. call_user_func_array([$invocation, 'with'], $args); // Test with writable session. $this->assertSame($this->sessionHandler->isSessionWritable(), TRUE); $actual_result = call_user_func_array([$this->sessionHandler, $method], $args); $this->assertSame($expected_result, $actual_result); // Test with non-writable session. $this->sessionHandler->setSessionWritable(FALSE); $this->assertSame($this->sessionHandler->isSessionWritable(), FALSE); $actual_result = call_user_func_array([$this->sessionHandler, $method], $args); $this->assertSame($expected_result, $actual_result); }
/** * Set the request on the handler instance. * * @param \Symfony\Component\HttpFoundation\Request $request * @return void */ public function setRequestOnHandler(Request $request) { if ($this->handlerNeedsRequest()) { $this->handler->setRequest($request); } }
/** * {@inheritdoc} */ public function gc($maxlifetime) { return (bool) $this->handler->gc($maxlifetime); }
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 gc($max_lifetime) { return $this->sessionHandler->gc($max_lifetime); }
/** * 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))); }