vendor/pimcore/pimcore/lib/Tool/Session.php line 130

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Enterprise License (PEL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  14.  */
  15. namespace Pimcore\Tool;
  16. use Pimcore\Bundle\AdminBundle\Session\Handler\AdminSessionHandler;
  17. use Pimcore\Bundle\AdminBundle\Session\Handler\AdminSessionHandlerInterface;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
  20. class Session
  21. {
  22.     /**
  23.      * @var AdminSessionHandlerInterface
  24.      */
  25.     private static $handler;
  26.     public static function getHandler(): AdminSessionHandlerInterface
  27.     {
  28.         if (null === static::$handler) {
  29.             static::$handler = \Pimcore::getContainer()->get(AdminSessionHandler::class);
  30.         }
  31.         return static::$handler;
  32.     }
  33.     public static function setHandler(AdminSessionHandlerInterface $handler)
  34.     {
  35.         static::$handler $handler;
  36.     }
  37.     /**
  38.      * @param callable $func
  39.      * @param string $namespace
  40.      *
  41.      * @return mixed
  42.      */
  43.     public static function useSession($funcstring $namespace 'pimcore_admin')
  44.     {
  45.         return static::getHandler()->useSessionAttributeBag($func$namespace);
  46.     }
  47.     /**
  48.      * @return string
  49.      */
  50.     public static function getSessionId()
  51.     {
  52.         return static::getHandler()->getSessionId();
  53.     }
  54.     /**
  55.      * @return string
  56.      */
  57.     public static function getSessionName()
  58.     {
  59.         return static::getHandler()->getSessionName();
  60.     }
  61.     /**
  62.      * @return bool
  63.      */
  64.     public static function invalidate(): bool
  65.     {
  66.         return static::getHandler()->invalidate();
  67.     }
  68.     /**
  69.      * @return bool
  70.      */
  71.     public static function regenerateId(): bool
  72.     {
  73.         return static::getHandler()->regenerateId();
  74.     }
  75.     /**
  76.      * @param Request $request
  77.      * @param bool    $checkRequestParams
  78.      *
  79.      * @return bool
  80.      */
  81.     public static function requestHasSessionId(Request $requestbool $checkRequestParams false): bool
  82.     {
  83.         return static::getHandler()->requestHasSessionId($request$checkRequestParams);
  84.     }
  85.     /**
  86.      * @param Request $request
  87.      * @param bool    $checkRequestParams
  88.      *
  89.      * @return string
  90.      */
  91.     public static function getSessionIdFromRequest(Request $requestbool $checkRequestParams false)
  92.     {
  93.         return static::getHandler()->getSessionIdFromRequest($request$checkRequestParams);
  94.     }
  95.     /**
  96.      * Start session and get an attribute bag
  97.      *
  98.      * @param string $namespace
  99.      *
  100.      * @return AttributeBagInterface
  101.      */
  102.     public static function get(string $namespace 'pimcore_admin'): AttributeBagInterface
  103.     {
  104.         return static::getHandler()->loadAttributeBag($namespace);
  105.     }
  106.     /**
  107.      * @param string $namespace
  108.      *
  109.      * @return AttributeBagInterface
  110.      */
  111.     public static function getReadOnly(string $namespace 'pimcore_admin'): AttributeBagInterface
  112.     {
  113.         return static::getHandler()->getReadOnlyAttributeBag($namespace);
  114.     }
  115.     /**
  116.      * Saves the session if it is the last admin session which was opene
  117.      */
  118.     public static function writeClose()
  119.     {
  120.         return static::getHandler()->writeClose();
  121.     }
  122. }