本文整理汇总了PHP中Symfony\Component\HttpFoundation\Session\SessionInterface::save方法的典型用法代码示例。如果您正苦于以下问题:PHP SessionInterface::save方法的具体用法?PHP SessionInterface::save怎么用?PHP SessionInterface::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Session\SessionInterface
的用法示例。
在下文中一共展示了SessionInterface::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function it_logs_user_out(SessionInterface $session, CookieSetterInterface $cookieSetter)
{
$session->set('_security_shop', null)->shouldBeCalled();
$session->save()->shouldBeCalled();
$session->getName()->willReturn('MOCKEDSID');
$session->getId()->willReturn('xyzc123');
$cookieSetter->setCookie('MOCKEDSID', 'xyzc123')->shouldBeCalled();
$this->logOut();
}
示例2: logInUser
/**
* @param UserInterface $user
*/
private function logInUser(UserInterface $user)
{
$token = new UsernamePasswordToken($user, $user->getPassword(), 'randomstringbutnotnull', $user->getRoles());
$this->session->set($this->sessionTokenVariable, serialize($token));
$this->session->save();
$this->cookieSetter->setCookie($this->session->getName(), $this->session->getId());
}
示例3: save
/**
* Save the translations in the session
*
* @param Translations $translations
* @param string $key
* @return bool
*/
public function save(Translations $translations, $key = self::DEFAULT_KEY)
{
$rawTranslations = $translations->getRawData();
$this->session->set($key, $rawTranslations);
$this->session->save();
return true;
}
示例4: onResponse
/**
* Add the session cookie to the response if it is started.
*
* @param FilterResponseEvent $event
*/
public function onResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest() || !$this->session->isStarted()) {
return;
}
$this->session->save();
$cookie = $this->generateCookie();
$event->getResponse()->headers->setCookie($cookie);
}
示例5: handle
/**
* @inheritDoc
*/
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
$this->startSession($request);
$request->setSession($this->session);
$response = $this->wrapped->handle($request, $type, $catch);
$this->session->save();
$this->writeSessionTo($response);
return $response;
}
示例6: logIn
/**
* {@inheritdoc}
*/
public function logIn($email, $providerKey, Session $minkSession)
{
$user = $this->userRepository->findOneBy(['username' => $email]);
if (null === $user) {
throw new \InvalidArgumentException(sprintf('There is no user with email %s', $email));
}
$token = new UsernamePasswordToken($user, $user->getPassword(), $providerKey, $user->getRoles());
$this->session->set('_security_user', serialize($token));
$this->session->save();
$minkSession->setCookie($this->session->getName(), $this->session->getId());
}
示例7: sendContent
/**
* {@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;
}
示例8: setToken
/**
* @param TokenInterface $token
*/
private function setToken(TokenInterface $token)
{
$serializedToken = serialize($token);
$this->session->set($this->sessionTokenVariable, $serializedToken);
$this->session->save();
$this->cookieSetter->setCookie($this->session->getName(), $this->session->getId());
}
示例9: closeSession
protected function closeSession(Request $request, Response $response)
{
// save all session data
$this->session->save();
// attach the session cookie
$response->headers->setCookie($this->makeCookie($request));
}
示例10:
function it_does_not_log_user_in_if_user_was_not_found(UserRepositoryInterface $userRepository, SessionInterface $session, CookieSetterInterface $cookieSetter)
{
$userRepository->findOneBy(['username' => 'sylius@example.com'])->willReturn(null);
$session->set(Argument::cetera())->shouldNotBeCalled();
$session->save()->shouldNotBeCalled();
$cookieSetter->setCookie(Argument::cetera())->shouldNotBeCalled();
$this->shouldThrow(new \InvalidArgumentException(sprintf('There is no user with email sylius@example.com')))->during('logIn', ['sylius@example.com']);
}
示例11: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
if (null !== $options['crop_by_ratio'] && null !== $options['crop_by_size'] && true === (bool) $options['allow_crop']) {
throw new \InvalidArgumentException('Multiple crop strategies at the same field are not allowed.');
}
if (null !== $options['crop_by_size'] && (!is_array($options['crop_by_size']) || !isset($options['crop_by_size']['w']) || !isset($options['crop_by_size']['h']))) {
throw new \InvalidArgumentException('crop_by_size requires array [w => [int], h => [int]].');
}
$uniqueKey = md5(microtime() . rand());
$sessionData = array('handler' => $options['handler'], 'imagine_filter' => $options['imagine_filter'], 'options' => array('accept_file_type' => $options['accept_file_type'], 'allow_multiple' => $options['allow_multiple'], 'allow_crop' => $options['allow_crop'], 'crop_by_size' => $options['crop_by_size'], 'crop_by_ratio' => $options['crop_by_ratio']), 'handler_options' => array('save_path' => $options['save_path'], 'web_path' => $options['web_path']));
$this->session->set($uniqueKey, $sessionData);
$this->session->save();
$view->vars['unique_key'] = $uniqueKey;
$view->vars['imagine_filter'] = $options['imagine_filter'];
$view->vars['allow_crop'] = $options['allow_crop'];
$view->vars['crop_by_ratio'] = $options['crop_by_ratio'];
$view->vars['crop_by_size'] = $options['crop_by_size'];
}
示例12: login
/**
* @param BaseUser $user
* @param SessionInterface $session
* @param $firewall
* @throws UnsupportedDriverActionException
*/
public function login(BaseUser $user, SessionInterface $session, $firewall)
{
$driver = $this->getDriver();
if (!$driver instanceof BrowserKitDriver) {
//Fall back to manual login if BrowserKitDriver is not used
throw new UnsupportedDriverActionException("Not supported by the current driver", $driver);
}
$client = $driver->getClient();
$client->getCookieJar()->set(new Cookie(session_name(), true));
$token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$client->getCookieJar()->set($cookie);
}
示例13: sendContent
/**
* {@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;
}
示例14: testSave
public function testSave()
{
$this->session->start();
$this->session->save();
}
示例15: setSerializedToken
/**
* @param string $token
*/
private function setSerializedToken($token)
{
$this->session->set($this->sessionTokenVariable, $token);
$this->session->save();
}