Fix get request session from legacy container

pull/4312/head
Angel Fernando Quiroz Campos 3 years ago
parent 32b5973485
commit b79420aeb0
  1. 3
      public/main/install/index.php
  2. 19
      src/CoreBundle/Framework/Container.php

@ -9,6 +9,7 @@ use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Session\Session as HttpSession;
use Symfony\Component\Translation\Loader\PoFileLoader;
use Symfony\Component\Translation\Translator;
@ -78,6 +79,8 @@ $translator->addResource(
);
Container::$translator = $translator;
Container::$session = new HttpSession();
// The function api_get_setting() might be called within the installation scripts.
// We need to provide some limited support for it through initialization of the
// global array-type variable $_setting.

@ -82,7 +82,8 @@ use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface as HttpSessionInterface;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Routing\Router;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
@ -100,6 +101,7 @@ class Container
public static ?Request $request = null;
public static ?TranslatorInterface $translator = null;
public static Environment $twig;
public static ?Session $session = null;
public static string $legacyTemplate = '@ChamiloCore/Layout/layout_one_col.html.twig';
public static function setContainer(ContainerInterface $container): void
@ -196,15 +198,24 @@ class Container
self::$request = $request;
}
public static function getSession(): SessionInterface|bool
public static function getSession(): Session|HttpSessionInterface|bool|null
{
if (!empty(self::$request)) {
return self::$request->getSession();
if (null !== self::$session) {
return self::$session;
}
if (null !== self::$container) {
return self::$container->get('request_stack')->getSession();
}
return false;
}
public static function setSession(Session $session): void
{
self::$session = $session;
}
/**
* @return AuthorizationChecker
*/

Loading…
Cancel
Save