public function setUp() { parent::setUp(); $encrypter = new Encrypter(Key::createNewRandomKey()); $config = $this->mock(ConfigContract::class); $config->shouldReceive('get')->with('cache.drivers', []); $config->shouldReceive('get')->with('cache.namespace'); $manager = new SessionManager($config, $encrypter); $manager->setContainer(new ArrayContainer([JarContract::class => $this->mock(JarContract::class), CacheManagerContract::class => new CacheManager($config)])); $this->manager = $manager; }
/** * Determine if a session driver has been configured. * * @return bool */ private function isSessionConfigured() : bool { return $this->manager->getConfig()->get('session::driver', null) !== null; }
/** * Add the CSRF token to the response cookies. * * @param \Psr\Http\Message\ResponseInterface $response * * @return \Psr\Http\Message\ResponseInterface */ protected function addCookieToResponse(ResponseInterface $response) : ResponseInterface { $config = $this->manager->getConfig(); $setCookie = new Cookie('XSRF-TOKEN', $this->tokenService->generate(), $config->get('session::csrf.livetime', Chronos::now()->getTimestamp() + 60 * 120), $config->get('path'), $config->get('domain'), $config->get('secure', false), false, $config->get('session::csrf.samesite', false)); return $response->withAddedHeader('Set-Cookie', (string) $setCookie); }
public static function createSessionManager(ContainerInterface $container) : SessionManager { $manager = new SessionManager($container->get(ConfigManager::class), $container->get(Encrypter::class)); $manager->setContainer($container); return $manager; }