Sets the Session.
public setSession ( Symfony\Component\HttpFoundation\Session\SessionInterface $session ) | ||
$session | Symfony\Component\HttpFoundation\Session\SessionInterface | The Session |
/** * Sets a flash notice * * @param string $level The level of the message: success, warning, danger * @param string $message The message */ public function setFlash($level, $message) { if (!$this->request->hasSession()) { $this->request->setSession(new Session()); } $this->flash_notices[] = ['level' => $level, 'message' => $message]; $this->request->getSession()->getFlashBag()->set('notice', $this->flash_notices); }
public function setUp() { $this->request = new Request(); $storage = new \Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage(); $session = new \Symfony\Component\HttpFoundation\Session\Session($storage); $this->request->setSession($session); $this->tokenProcessor = TokenProcessor::getInstance(); }
/** * Runner constructor. */ public function __construct() { static::$request = Request::createFromGlobals(); if (!static::$request->hasPreviousSession()) { $session = new Session(); $session->start(); static::$request->setSession($session); } }
public function setup() { $this->requestStack = new RequestStack(); $this->session = $this->prophesize('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface'); $this->provider = $this->prophesize('League\\OAuth2\\Client\\Provider\\AbstractProvider'); $this->request = new Request(); $this->request->setSession($this->session->reveal()); $this->requestStack->push($this->request); }
protected function setUp() { $this->action = new \Phruts\Action\Action(); $this->actionKernel = $this->getMockBuilder('\\Phruts\\Action\\ActionKernel')->disableOriginalConstructor()->getMock(); $this->action->setActionKernel($this->actionKernel); $this->request = new \Symfony\Component\HttpFoundation\Request(); $storage = new \Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage(); $session = new \Symfony\Component\HttpFoundation\Session\Session($storage); // $session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->disableOriginalConstructor()->getMock(); $this->request->setSession($session); }
protected function runSessionOnKernelResponse($newToken, $original = null) { $session = new Session(new ArraySessionStorage()); if ($original !== null) { $session->set('_security_session', $original); } $this->securityContext->setToken($newToken); $request = new Request(); $request->setSession($session); $event = new FilterResponseEvent( $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST, new Response() ); $listener = new ContextListener($this->securityContext, array(), 'session'); $listener->onKernelResponse($event); return $session; }
protected function createSession(Request $request) { $session = new Session(); $request->setSession($session); $session->setName('sitegear.test'); return $session; }
/** * {@inheritdoc} */ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) { // always set the session onto the request object. $request->setSession($this->session); // we only need to manage the session for the master request. // subrequests will have the session available anyways, but we will // be closing and setting the cookie for the master request only. if ($type !== HttpKernelInterface::MASTER_REQUEST) { return $this->kernel->handle($request, $type, $catch); } // the session may have been manually started before the middleware is // invoked - in this case, we cross our fingers and hope the session has // properly initialised itself if (!$this->session->isStarted()) { $this->initSession($request); } $response = $this->kernel->handle($request, $type, $catch); // if the session has started, save it and attach the session cookie. if // the session has not started, there is nothing to save and there is no // point in attaching a cookie to persist it. if ($this->session->isStarted()) { $this->closeSession($request, $response); } return $response; }
protected function createEvent(\Exception $e) { $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface'); $request = new Request(); $request->setSession($this->session); $event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $e); return $event; }
public function _initNativeSession(Request $request) { if (!$request->hasSession()) { $sesOption = array('cache_limiter' => 'nocache', 'cookie_domain' => 'localhost.com', 'cookie_httponly' => '1', 'cookie_lifetime' => '1800', 'cookie_path' => '/', 'cookie_secure' => '0', 'entropy_file' => '/dev/urandom', 'entropy_length' => '1024', 'gc_divisor' => '100', 'gc_maxlifetime' => '1800', 'gc_probability' => '100', 'hash_bits_per_character' => '4', 'hash_function' => '1', 'name' => 'NODEPHP', 'referer_check' => '', 'serialize_handler' => 'php', 'use_cookies' => '1', 'use_only_cookies' => '1', 'use_trans_sid' => '0', 'upload_progress.enabled' => '1', 'upload_progress.cleanup' => '1', 'upload_progress.prefix' => 'upload_progress_', 'upload_progress.name' => 'PHP_SESSION_UPLOAD_PROGRESS', 'upload_progress.freq' => '1%', 'upload_progress.min-freq' => '1', 'url_rewriter.tags' => 'a=href,area=href,frame=src,form=,fieldset='); $session = new Session(new NativeSessionStorage($sesOption, new NativeFileSessionHandler('/tmp;/tmp'), new MetadataBag('nodephp_meta')), new AttributeBag('nodephp_attributes'), new FlashBag('nodephp_flashes')); $request->setSession($session); } }
public function __construct(Request $request, $openPlatformAppId, $openPlatformToken, $clientId, $clientSecret, $redirectUrl = null) { $session = new Session(); $request->setSession($session); parent::__construct($request, new \Overtrue\Socialite\Config([]), $clientId, $clientSecret, $redirectUrl); $this->openPlatformAppId = $openPlatformAppId; $this->openPlatformToken = $openPlatformToken; }
/** * @param \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token */ function it_should_return_the_correct_redirect_response_after_authentication_success($token) { $session = new Session(); $this->request->setSession($session); $this->onAuthenticationSuccess($this->request, $token, 'foo')->getTargetUrl()->shouldEqual('/'); $session->set('_security.main.target_path', '/foo'); $this->onAuthenticationSuccess($this->request, $token, 'foo')->getTargetUrl()->shouldEqual('/foo'); }
/** * Creates a Container with a Session-containing Request service. * * @return Container */ protected function getContainer() { $container = new Container(); $request = new Request(); $session = new Session(new ArraySessionStorage()); $request->setSession($session); $container->set('request', $request); return $container; }
/** * @group legacy */ public function testLegacyWithLoginUrl() { $request = new Request(); $request->setSession($this->getMock('Symfony\\Component\\HttpFoundation\\Session\\Session')); $authenticator = new LegacyFormLoginAuthenticator(); /** @var RedirectResponse $actualResponse */ $actualResponse = $authenticator->onAuthenticationSuccess($request, $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'), 'provider_key'); $this->assertEquals('/default_url', $actualResponse->getTargetUrl()); }
private function filterResponse(Request $request, $type = HttpKernelInterface::MASTER_REQUEST) { $request->setSession($this->session); $response = new Response(); $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'); $event = new FilterResponseEvent($kernel, $request, $type, $response); $this->listener->onKernelResponse($event); $this->assertSame($response, $event->getResponse()); }
/** * @return \Symfony\Component\HttpKernel\Event\GetResponseEvent */ private function getGetResponseEvent() { $kernel = $this->getKernel(); $session = $this->getContainer()->get('session'); $request = new Request(); $request->setSession($session); $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); return $event; }
protected function setUp() { $request = new Request(); $session = new Session(new MockArraySessionStorage()); $session->set('foobar', 'bar'); $session->getFlashBag()->set('notice', 'bar'); $request->setSession($session); $this->requestStack = new RequestStack(); $this->requestStack->push($request); }
public function testKernelResponseDoesNotStartSession() { $kernel = $this->getMock(HttpKernelInterface::class); $request = new Request(); $session = new Session(new MockArraySessionStorage()); $request->setSession($session); $response = new Response(); $c = new RequestDataCollector(); $c->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response)); $this->assertFalse($session->isStarted()); }
protected function prepareRequest(Request $request) { $session = $this->container->get(Session::class); $request->setSession($session); if ($request->getContentType() == 'json') { if ($data = json_decode($request->getContent(), true)) { $request->request->replace($data); } } $this->container->add(Request::class, $request); }
/** * {@inheritdoc} */ public final function handle(Request $request) { if (!$this->booted) { $this->boot(); } if ($this->container->has('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface')) { $request->setSession($this->container->get('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface')); } $this->container->set('Symfony\\Component\\HttpFoundation\\Request', $request); return $this->doHandle($request); }
public function testLogoutNotRest() { $session = $this->getMock('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface'); $session->expects($this->never())->method('getName'); $request = new Request(); $request->setSession($session); $response = new Response(); $response->headers = $this->getMock('Symfony\\Component\\HttpFoundation\\ResponseHeaderBag'); $response->headers->expects($this->never())->method('clearCookie'); $logoutHandler = new RestLogoutHandler(); $logoutHandler->logout($request, $response, $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface')); }
public function testItSavesSessionAtKernelResponseEvent() { $session = $this->getMock(SessionInterface::class); $session->expects($this->once())->method('isStarted')->willReturn(true); $session->expects($this->once())->method('save'); $request = new Request(); $request->setSession($session); $event = $this->getMockBuilder(FilterResponseEvent::class)->disableOriginalConstructor()->getMock(); $event->expects($this->once())->method('getRequestType')->willReturn(HttpKernelInterface::MASTER_REQUEST); $event->expects($this->once())->method('getRequest')->willReturn($request); $this->sut->onKernelResponse($event); }
/** * Creates an event object for the test of LocaleListener. * * @param array $query an array of query parameters for URL * @param array $headers HTTP headers to request * @param boolean $session creates a session in the request * * @return GetResponseEvent */ private function createEvent(array $query = array(), array $headers = array(), $session = false) { $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'); $kernel->handle(new Request()); $request = new Request($query); $request->headers->add($headers); if ($session) { $session = new Session(new MockArraySessionStorage()); $request->setSession($session); } return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); }
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) { if ($type == HttpKernelInterface::MASTER_REQUEST) { if (null === ($session = self::$session)) { $event = new SessionEvent($this->cacheDir, $this->debug, $this->env); $this->eventDispatcher->dispatch(TheliaKernelEvents::SESSION, $event); self::$session = $session = $event->getSession(); } $session->start(); $request->setSession($session); } return $this->app->handle($request, $type, $catch); }
/** * Cookie not opened */ public function testCookieNotOpened() { $session = $this->getMock('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface'); $headers = $this->getMock('Symfony\\Component\\HttpFoundation\\ResponseHeaderBag'); $headers->expects($this->any())->method('clearCookie'); $headers->expects($this->any())->method('setCookie'); $response = new Response(); $request = new Request(); $request->setSession($session); $response->headers = $headers; $this->handler->onKernelRequest(new GetResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST)); $this->handler->onKernelResponse(new FilterResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response)); }
/** * {@inheritdoc} */ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { if ($type === self::MASTER_REQUEST && PHP_SAPI !== 'cli') { $session = $this->container->get($this->sessionServiceName); $session->start(); $request->setSession($session); } $result = $this->httpKernel->handle($request, $type, $catch); if ($type === self::MASTER_REQUEST && $request->hasSession()) { $request->getSession()->save(); } return $result; }
protected function initializeSession(Request $request, $master) { if (!$master) { return; } // inject the session object if none is present if (null === $request->getSession()) { $request->setSession($this->container->get('session')); } // starts the session if a session cookie already exists in the request... if ($request->hasSession()) { $request->getSession()->start(); } }
private function prepareEnvironment($fakeRequest = true) { if ($fakeRequest) { // twig asset helpers require a request scope, // which is not provided in a CLI context $request = new Request(); $request->setSession(new Session()); $this->container->enterScope('request'); $this->container->set('request', $request, 'request'); $this->container->get('request_stack')->push($request); } // replace default asset extension to collect assets // (*Note*: removeExtension is deprecated) $this->twig->removeExtension('assets'); $this->twig->addExtension($this->assetExtension); }
public function testGetAccessToken() { $requestStack = $this->prophesize('Symfony\\Component\\HttpFoundation\\RequestStack'); $session = $this->prophesize('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface'); $request = new Request(); $request->query->set('state', 'THE_STATE'); $request->query->set('code', 'CODE_ABC'); $request->setSession($session->reveal()); $requestStack->getCurrentRequest()->willReturn($request); $session->get(OAuth2Client::OAUTH2_SESSION_STATE_KEY)->willReturn('THE_STATE'); $expectedToken = $this->prophesize('League\\OAuth2\\Client\\Token\\AccessToken'); $provider = $this->prophesize('League\\OAuth2\\Client\\Provider\\AbstractProvider'); $provider->getAccessToken('authorization_code', array('code' => 'CODE_ABC'))->willReturn($expectedToken->reveal()); $client = new OAuth2Client($provider->reveal(), $requestStack->reveal()); $actualToken = $client->getAccessToken(); $this->assertSame($expectedToken->reveal(), $actualToken); }
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) { $request->setSession(new Session()); $container = new Container($request, $this->rootDirectory); $controller = new Controller($container); $pathInfo = $request->getPathInfo(); $method = $request->getMethod(); $response = null; if ($pathInfo === '/' && $method === 'GET') { $response = $controller->languageStep(); } elseif ($pathInfo === '/' && $method === 'POST') { $response = $controller->languageStepSubmit(); } elseif ($pathInfo === '/requirements' && $method === 'GET') { $response = $controller->requirementStep(); } elseif ($pathInfo === '/database' && $method === 'GET') { $response = $controller->databaseStep(); } elseif ($pathInfo === '/database' && $method === 'POST') { $response = $controller->databaseStepSubmit(); } elseif ($pathInfo === '/platform' && $method === 'GET') { $response = $controller->platformStep(); } elseif ($pathInfo === '/platform' && $method === 'POST') { $response = $controller->platformSubmitStep(); } elseif ($pathInfo === '/admin' && $method === 'GET') { $response = $controller->adminUserStep(); } elseif ($pathInfo === '/admin' && $method === 'POST') { $response = $controller->adminUserStepSubmit(); } elseif ($pathInfo === '/mailing' && $method === 'GET') { $response = $controller->mailingStep(); } elseif ($pathInfo === '/mailing' && $method === 'POST') { $response = $controller->mailingStepSubmit(); } elseif ($pathInfo === '/skip-mailing' && $method === 'GET') { $response = $controller->skipMailingStep(); } elseif ($pathInfo === '/install' && $method === 'GET') { $response = $controller->installStep(); } elseif ($pathInfo === '/install' && $method === 'POST') { $response = $controller->installSubmitStep(); } elseif ($pathInfo === '/status' && $method === 'GET') { $response = $controller->installStatusStep(); } elseif (preg_match('#^/status/(.+)$#', $pathInfo, $matches) && $method === 'GET') { $response = $controller->installStatusStep($matches[1]); } elseif (preg_match('#^/error/(.+)$#', $pathInfo, $matches) && $method === 'GET') { $response = $controller->failedInstallStep($matches[1]); } return $response ?: new Response('<h2>Page not found</h2>', 404); }