/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $storage = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockArraySessionStorage')->setMethods(NULL)->getMock(); $this->session = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Session\\Session')->setConstructorArgs(array($storage))->setMethods(NULL)->getMock(); $this->session->start(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface'); $this->connection = $this->getMockBuilder('\\Drupal\\Core\\Database\\Connection')->disableOriginalConstructor()->getMock(); $storage = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockArraySessionStorage')->setMethods(NULL)->getMock(); $this->session = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Session\\Session')->setConstructorArgs(array($storage))->setMethods(NULL)->getMock(); $this->session->start(); $this->eventDispatcher = $this->getMockBuilder('\\Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->disableOriginalConstructor()->getMock(); }
public function onSiteAccessMatch(PostSiteAccessMatchEvent $event) { if (!$this->session || $event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) { return; } $sessionName = $this->session->getName(); $request = $event->getRequest(); if (!$this->session->isStarted() && !$request->hasPreviousSession() && $request->request->has($sessionName)) { $this->session->setId($request->request->get($sessionName)); $this->session->start(); } }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->urlGenerator = $this->getMock('\\Drupal\\Core\\Routing\\UrlGeneratorInterface'); $this->connection = $this->getMockBuilder('\\Drupal\\Core\\Database\\Connection')->disableOriginalConstructor()->getMock(); $this->loggerFactory = $this->getMock('\\Drupal\\Core\\Logger\\LoggerChannelFactory'); $this->loggerChannel = $this->getMockBuilder('\\Drupal\\Core\\Logger\\LoggerChannel')->disableOriginalConstructor()->getMock(); $this->loggerFactory->expects($this->any())->method('get')->with('cas')->will($this->returnValue($this->loggerChannel)); $storage = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockArraySessionStorage')->setMethods(NULL)->getMock(); $this->session = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Session\\Session')->setConstructorArgs(array($storage))->setMethods(NULL)->getMock(); $this->session->start(); }
/** * @return string */ public function getSessionId() { try { if ($this->startSession && !$this->session->isStarted()) { $this->session->start(); } if ($this->session->isStarted()) { return $this->session->getId(); } } catch (\RuntimeException $e) { } return self::SESSION_ID_UNKNOWN; }
/** * Set the session ID from request cookies * * @param GetResponseEvent $event */ public function onRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); $request->setSession($this->session); $this->appendRealmToName($request); $name = $this->session->getName(); if ($request->cookies->has($name)) { $this->session->setId($request->cookies->get($name)); $this->session->start(); } }
/** * {@inheritdoc} */ public function sendContent($content, array $attachments) { // First, gather the BigPipe placeholders that must be replaced. $placeholders = isset($attachments['big_pipe_placeholders']) ? $attachments['big_pipe_placeholders'] : []; $nojs_placeholders = isset($attachments['big_pipe_nojs_placeholders']) ? $attachments['big_pipe_nojs_placeholders'] : []; // BigPipe sends responses using "Transfer-Encoding: chunked". To avoid // sending already-sent assets, it is necessary to track cumulative assets // from all previously rendered/sent chunks. // @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.41 $cumulative_assets = AttachedAssets::createFromRenderArray(['#attached' => $attachments]); $cumulative_assets->setAlreadyLoadedLibraries($attachments['library']); // The content in the placeholders may depend on the session, and by the // time the response is sent (see index.php), the session is already closed. // Reopen it for the duration that we are rendering placeholders. $this->session->start(); // Find the closing </body> tag and get the strings before and after. But be // careful to use the latest occurrence of the string "</body>", to ensure // that strings in inline JavaScript or CDATA sections aren't used instead. $parts = explode('</body>', $content); $post_body = array_pop($parts); $pre_body = implode('', $parts); $this->sendPreBody($pre_body, $nojs_placeholders, $cumulative_assets); $this->sendPlaceholders($placeholders, $this->getPlaceholderOrder($pre_body, $placeholders), $cumulative_assets); $this->sendPostBody($post_body); // Close the session again. $this->session->save(); return $this; }
/** * {@inheritdoc} */ public function removeToken($tokenId) { if (!$this->session->isStarted()) { $this->session->start(); } return $this->session->remove($this->namespace . '/' . $tokenId); }
/** * Constructs a new facebook service * * @param \Facebook $facebook * @param SessionInterface $session * @param RouterInterface $router * @param string $fanPageUrl * @param array $requiredPermissions * @param string $sessionIdentifier */ public function __construct(\Facebook $facebook, SessionInterface $session, RouterInterface $router, $fanPageUrl, array $requiredPermissions = array("email"), $sessionIdentifier = "app") { $this->facebook = $facebook; $this->session = $session; $this->router = $router; $this->fanPageUrl = $fanPageUrl; $this->requiredPermissions = $requiredPermissions; $this->sessionIdentifier = (string) $sessionIdentifier; // force initialization of the facebook session to fix session related errors in conjunction with the Facebook SDK try { $this->session->start(); } catch (\RuntimeException $e) { // is thrown, when the session was already started by PHP. // The error is ignored, since this is exactly what is desired (to just start a session) } $this->initialize(); }
/** * Set the session ID from request cookies * * @param GetResponseEvent $event */ public function onRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); $request->setSession($this->session); $name = $this->session->getName(); if ($this->options->getBoolean('restrict_realm')) { $name .= md5($request->getHttpHost() . $request->getBaseUrl()); $this->session->setName($name); } if ($request->cookies->has($name)) { $this->session->setId($request->cookies->get($name)); $this->session->start(); } }
/** * {@inheritDoc} */ public function generate($key) { if (!is_string($key)) { throw new InvalidTypeException($key, 'string'); } if (empty($key)) { throw new \InvalidArgumentException('Argument must not be empty.'); } $token = $this->tokenStorage->getToken(); if ($token instanceof TokenInterface && !$token instanceof AnonymousToken) { $username = $token->getUsername(); if (!empty($username)) { return sprintf('user_%s_%s', $username, $key); } } // fallback to session id if (!$this->session->isStarted()) { $this->session->start(); } return sprintf('session_%s_%s', $this->session->getId(), $key); }
protected function initSession(Request $request) { // the name of the session cookie name. $sessionName = $this->session->getName(); // if a session cookie exists, load the appropriate session ID. if ($request->cookies->has($sessionName)) { $this->session->setId($request->cookies->get($sessionName)); } // in some rare cases you may want to force the session to start on // every request. if ($this->forceStart) { $this->session->start(); } }
/** * {@inheritdoc} */ public function create(array $batch) { // Ensure that a session is started before using the CSRF token generator. $this->session->start(); $try_again = FALSE; try { // The batch table might not yet exist. $this->doCreate($batch); } catch (\Exception $e) { // If there was an exception, try to create the table. if (!($try_again = $this->ensureTableExists())) { // If the exception happened for other reason than the missing table, // propagate the exception. throw $e; } } // Now that the table has been created, try again if necessary. if ($try_again) { $this->doCreate($batch); } }
/** * {@inheritdoc} */ public function sendContent($content, array $attachments) { // First, gather the BigPipe placeholders that must be replaced. $placeholders = isset($attachments['big_pipe_placeholders']) ? $attachments['big_pipe_placeholders'] : []; $nojs_placeholders = isset($attachments['big_pipe_nojs_placeholders']) ? $attachments['big_pipe_nojs_placeholders'] : []; // BigPipe sends responses using "Transfer-Encoding: chunked". To avoid // sending already-sent assets, it is necessary to track cumulative assets // from all previously rendered/sent chunks. // @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.41 $cumulative_assets = AttachedAssets::createFromRenderArray(['#attached' => $attachments]); $cumulative_assets->setAlreadyLoadedLibraries(explode(',', $attachments['drupalSettings']['ajaxPageState']['libraries'])); // The content in the placeholders may depend on the session, and by the // time the response is sent (see index.php), the session is already closed. // Reopen it for the duration that we are rendering placeholders. $this->session->start(); list($pre_body, $post_body) = explode('</body>', $content, 2); $this->sendPreBody($pre_body, $nojs_placeholders, $cumulative_assets); $this->sendPlaceholders($placeholders, $this->getPlaceholderOrder($pre_body), $cumulative_assets); $this->sendPostBody($post_body); // Close the session again. $this->session->save(); return $this; }
public function testGetId() { $this->assertEquals('', $this->session->getId()); $this->session->start(); $this->assertNotEquals('', $this->session->getId()); }
protected function __construct(\Symfony\Component\HttpFoundation\Session\SessionInterface $session) { $session->start(); $this->flashBag = $session->getFlashBag(); return $this; }
/** * {@inheritdoc} */ public function create(array $batch) { // Ensure that a session is started before using the CSRF token generator. $this->session->start(); $this->connection->insert('batch')->fields(array('bid' => $batch['id'], 'timestamp' => REQUEST_TIME, 'token' => $this->csrfToken->get($batch['id']), 'batch' => serialize($batch)))->execute(); }
/** * Start the session * * @return boolean * @throws RuntimeException If session fails to start. * @since 1.9 */ public function start() { $result = $this->storage->start(); $this->generateSessionToken(); return $result; }
/** * @Extra\Route("/login", name="weaving_the_web_user_facebook_login") */ public function loginAction() { $this->session->start(); $helper = $this->getFacebookRedirectLoginHelper(); return new RedirectResponse($helper->getLoginUrl(['user_birthday', 'user_religion_politics', 'user_relationships', 'user_relationship_details', 'user_hometown', 'user_location', 'user_likes', 'user_education_history', 'user_work_history', 'user_website', 'user_groups', 'user_managed_groups', 'user_events', 'user_photos', 'user_videos', 'user_friends', 'user_about_me', 'user_status', 'user_posts', 'read_stream', 'read_mailbox', 'email', 'ads_management', 'read_insights', 'manage_notifications', 'publish_actions', 'read_custom_friendlists', 'public_profile'])); }
function it_returns_specific_id_if_exception(SessionInterface $session) { $session->start()->willThrow("\\RuntimeException"); $this->getSessionId()->shouldReturn(SymfonySessionIdProvider::SESSION_ID_UNKNOWN); }
/** * Prepare and start the session instance with data from the given request. * * @param \Symfony\Component\HttpFoundation\Request $request * @return void */ protected function startSession(Request $request) { $this->session->setId($request->cookies->get('fluxbb_session')); $this->session->start(); }