本文整理汇总了PHP中Symfony\Component\HttpFoundation\Session\Session::isStarted方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::isStarted方法的具体用法?PHP Session::isStarted怎么用?PHP Session::isStarted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Session\Session
的用法示例。
在下文中一共展示了Session::isStarted方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startSession
/**
* Starts the session if it does not exist.
*
* @return void
*/
protected function startSession()
{
// Check that the session hasn't already been started
if ($this->session->isStarted()) {
$this->session->start();
}
}
示例2: getSessionId
/**
* {@inheritdoc}
*/
protected function getSessionId()
{
if (!$this->session->isStarted()) {
$this->session->start();
}
return $this->session->getId();
}
示例3: isSessionStarted
/**
* {@inheritDoc}
*/
public function isSessionStarted()
{
if (!$this->session->isStarted()) {
$this->session->start();
}
return $this->session->isStarted();
}
示例4: onKernelResponse
/**
* Moves flash messages from the session to a cookie inside a Response Kernel listener.
*
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if ($event->getRequestType() !== HttpKernel::MASTER_REQUEST) {
return;
}
// Flash messages are stored in the session. If there is none, there
// can't be any flash messages in it. $session->getFlashBag() would
// create a session, we need to avoid that.
if (!$this->session->isStarted()) {
return;
}
$flashBag = $this->session->getFlashBag();
$flashes = $flashBag->all();
if (empty($flashes)) {
return;
}
$response = $event->getResponse();
$cookies = $response->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
if (isset($cookies[$this->options['host']][$this->options['path']][$this->options['name']])) {
$rawCookie = $cookies[$this->options['host']][$this->options['path']][$this->options['name']]->getValue();
$flashes = array_merge($flashes, json_decode($rawCookie));
}
$cookie = new Cookie($this->options['name'], json_encode($flashes), 0, $this->options['path'], $this->options['host'], $this->options['secure'], false);
$response->headers->setCookie($cookie);
}
示例5: __construct
public function __construct(Mysql $db, Session $session)
{
$this->db = $db;
$this->session = $session;
if (!$this->session->isStarted()) {
$this->session->start();
}
}
示例6: __construct
/**
* Session constructor.
*
* @param string|null $namespace
*/
public function __construct($namespace = null)
{
@session_start();
$this->session = new SymfonySession(new PhpBridgeSessionStorage());
if (!$this->session->isStarted()) {
$this->session->start();
}
$this->setSessionValues($namespace);
}
示例7: __construct
public function __construct(Mysql $db, Session $session, LoginService $login)
{
$this->db = $db;
$this->session = $session;
$this->login = $login;
if (!$this->session->isStarted()) {
$this->session->start();
}
}
示例8: indexAction
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
$session = new Session();
if ($session->isStarted() == true) {
$session->start();
}
$products = $this->getDoctrine()->getRepository('AppBundle:Product')->findAll();
$prodId = $request->request->get('prod', 'noone');
$inBasket[] = "Empty Basket, please select a product";
if ($prodId != 'noone') {
$product = $this->getDoctrine()->getRepository('AppBundle:Product')->find($prodId);
$session->set($product->getId(), $product->getName());
$log = new Log();
$log->setProdName($product->getName());
$log->setDate(new \DateTime());
$em = $this->getDoctrine()->getManager();
$em->persist($log);
$em->flush();
echo "Dev : Log saved to database. Product name - " . $product->getName() . " Current time - " . $log->getDate()->format('H:i:s \\O\\n Y-m-d');
$inBasket = $session->all();
} else {
if ($session->count() != 0) {
$inBasket = $session->all();
echo "Please select a Product before submitting !!!";
}
}
return $this->render('default/index.html.twig', ['products' => $products, 'basketProds' => $inBasket]);
}
示例9: generateTokenString
/**
* Generate token string
*/
private function generateTokenString()
{
if ($this->session->isStarted() === false) {
$this->session->start();
}
return sha1($this->secret . $this->session->getId());
}
示例10: getSession
public function getSession($request)
{
if (($session = $request->getSession()) === NULL) {
$session = new Session();
}
if (!$session->isStarted()) {
$session->start();
}
return $session;
}
示例11: register
/**
* Register the service provider.
*
* @return object
*/
public function register()
{
$this->app->singleton('session', function () {
$storage = new NativeSessionStorage($this->getOptions(), $this->getHandler(), new MetadataBag());
$session = new SfSession($storage, new AttributeBag('_group_attributes'), new FlashBag());
if (!$session->isStarted()) {
$session->start();
}
return new SessionService($session);
});
}
示例12: addMessage
/**
* @param $type
* @param null $header
* @param null $title
* @param null $message
* @param null $buttonMessage
* @return bool
*/
private function addMessage($type, $header = null, $title = null, $message = null, $buttonMessage = null)
{
if (!$this->flashBag && $this->session->isStarted()) {
$this->flashBag = $this->session->getFlashBag();
}
if ($this->flashBag) {
$this->flashBag->add($type, new FlashMessage($header, $title, $message, $buttonMessage));
return true;
}
return false;
}
示例13: applySessionStrategy
/**
* Apply the Session Strategy
*
* @return void
*/
protected function applySessionStrategy()
{
if (!$this->session->isStarted()) {
return $this->session->start();
}
switch ($this->strategy) {
case self::STRATEGY_MIGRATE:
$this->session->migrate();
break;
case self::STRATEGY_INVALIDATES:
$this->session->invalidate();
break;
default:
throw new \RuntimeException('Session strategy should be "migrate" or "invalidate"');
}
}
示例14: indexAction
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
$session = $request->getSession();
if ($session == null) {
$session = new Session();
}
if (!$session->isStarted()) {
$session->start();
}
//new sessionID if session existed already.
$session->migrate();
if ($session->has('originalSessionID')) {
$session->remove('originalSessionID');
}
return $this->render('default/index.html.twig');
}
示例15: getLoginUrls
public function getLoginUrls()
{
$socialNetworks = $this->socialNetworkRepository->findBy(array('enabled' => true, 'loginEnabled' => true));
try {
$session = new Session();
if (!$session->isStarted()) {
$session->start();
}
} catch (\Exception $e) {
}
$urls = array();
$provider_prefix = "socialhub_provider_";
foreach ($socialNetworks as $socialNetwork) {
$socialProvider = $this->container->get($provider_prefix . $socialNetwork->getType());
$loginUrl = $socialProvider->getLoginUrl();
$urls[] = array('name' => $socialNetwork->getName(), 'type' => $socialNetwork->getType(), 'label' => "label." . $socialNetwork->getType(), 'url' => $loginUrl);
}
return $urls;
}