Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function __invoke(ServerRequestInterface $request, Closure $next)
 {
     $cookieJar = $this->cookieJarFactory->fromServerRequest($request);
     $session = $this->sessionFactory->fromCookieJar($cookieJar);
     $request = $request->withAttribute('cookie', $cookieJar)->withAttribute('session', $session);
     // run next
     try {
         $response = $next($request);
     } catch (HttpException $exception) {
         $response = $exception->getResponse();
         $this->sessionFactory->toCookieJar($session, $cookieJar);
         $exception->setResponse($this->cookieJarFactory->toResponse($cookieJar, $response));
         throw $exception;
     }
     $this->sessionFactory->toCookieJar($session, $cookieJar);
     return $this->cookieJarFactory->toResponse($cookieJar, $response);
 }
Esempio n. 2
0
 public function testCreateSessionFromCookieJarAndOtherSessionName()
 {
     $mockery = Mockery::mock(\SessionHandlerInterface::class);
     $mockery->shouldReceive('read')->once()->with('wdsess_id5678')->andReturn(serialize(['hello' => 'world']));
     // nothing
     $factory = new SessionFactory($mockery, ['name' => 'WanduSessionId']);
     $cookieJar = new CookieJar(['WanduSessionId' => 'wdsess_id5678']);
     $session = $factory->fromCookieJar($cookieJar);
     $this->assertEquals(['hello' => 'world'], $session->getRawParams());
 }