本文整理汇总了PHP中Symfony\Component\HttpFoundation\Session\SessionInterface::start方法的典型用法代码示例。如果您正苦于以下问题:PHP SessionInterface::start方法的具体用法?PHP SessionInterface::start怎么用?PHP SessionInterface::start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Session\SessionInterface
的用法示例。
在下文中一共展示了SessionInterface::start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* {@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();
}
示例2: setUp
/**
* {@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();
}
示例3: onSiteAccessMatch
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();
}
}
示例4: setUp
/**
* {@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();
}
示例5: getSessionId
/**
* @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;
}
示例6: onRequest
/**
* 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();
}
}
示例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: removeToken
/**
* {@inheritdoc}
*/
public function removeToken($tokenId)
{
if (!$this->session->isStarted()) {
$this->session->start();
}
return $this->session->remove($this->namespace . '/' . $tokenId);
}
示例9: __construct
/**
* 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();
}
示例10: onRequest
/**
* 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();
}
}
示例11: generate
/**
* {@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);
}
示例12: initSession
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();
}
}
示例13: create
/**
* {@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);
}
}
示例14: 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;
}
示例15: testGetId
public function testGetId()
{
$this->assertEquals('', $this->session->getId());
$this->session->start();
$this->assertNotEquals('', $this->session->getId());
}