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

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 Commercial License (PCL)
  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 PCL
  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. final 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|null
  101.      */
  102.     public static function get(string $namespace 'pimcore_admin')
  103.     {
  104.         $bag = static::getHandler()->loadAttributeBag($namespace);
  105.         if ($bag instanceof AttributeBagInterface) {
  106.             return $bag;
  107.         }
  108.         return null;
  109.     }
  110.     /**
  111.      * @param string $namespace
  112.      *
  113.      * @return AttributeBagInterface
  114.      */
  115.     public static function getReadOnly(string $namespace 'pimcore_admin'): AttributeBagInterface
  116.     {
  117.         return static::getHandler()->getReadOnlyAttributeBag($namespace);
  118.     }
  119.     /**
  120.      * Saves the session if it is the last admin session which was opene
  121.      */
  122.     public static function writeClose()
  123.     {
  124.         return static::getHandler()->writeClose();
  125.     }
  126. }