mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-26 03:58:45 +02:00
N°6934 - Symfony 6.4 - upgrade Symfony bundles to 6.4 (#580)
* Update Symfony lib to version ~6.4.0 * Update code missing return type * Add an iTop general configuration entry to store application secret (Symfony mandatory parameter) * Use dependency injection in ExceptionListener & UserProvider classes
This commit is contained in:
@@ -30,13 +30,10 @@ use Symfony\Component\Security\Core\User\UserInterface;
|
||||
*/
|
||||
class KernelBrowser extends HttpKernelBrowser
|
||||
{
|
||||
private $hasPerformedRequest = false;
|
||||
private $profiler = false;
|
||||
private $reboot = true;
|
||||
private bool $hasPerformedRequest = false;
|
||||
private bool $profiler = false;
|
||||
private bool $reboot = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(KernelInterface $kernel, array $server = [], History $history = null, CookieJar $cookieJar = null)
|
||||
{
|
||||
parent::__construct($kernel, $server, $history, $cookieJar);
|
||||
@@ -44,10 +41,8 @@ class KernelBrowser extends HttpKernelBrowser
|
||||
|
||||
/**
|
||||
* Returns the container.
|
||||
*
|
||||
* @return ContainerInterface
|
||||
*/
|
||||
public function getContainer()
|
||||
public function getContainer(): ContainerInterface
|
||||
{
|
||||
$container = $this->kernel->getContainer();
|
||||
|
||||
@@ -56,20 +51,16 @@ class KernelBrowser extends HttpKernelBrowser
|
||||
|
||||
/**
|
||||
* Returns the kernel.
|
||||
*
|
||||
* @return KernelInterface
|
||||
*/
|
||||
public function getKernel()
|
||||
public function getKernel(): KernelInterface
|
||||
{
|
||||
return $this->kernel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the profile associated with the current Response.
|
||||
*
|
||||
* @return HttpProfile|false|null
|
||||
*/
|
||||
public function getProfile()
|
||||
public function getProfile(): HttpProfile|false|null
|
||||
{
|
||||
if (null === $this->response || !$this->getContainer()->has('profiler')) {
|
||||
return false;
|
||||
@@ -82,6 +73,8 @@ class KernelBrowser extends HttpKernelBrowser
|
||||
* Enables the profiler for the very next request.
|
||||
*
|
||||
* If the profiler is not enabled, the call to this method does nothing.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enableProfiler()
|
||||
{
|
||||
@@ -95,6 +88,8 @@ class KernelBrowser extends HttpKernelBrowser
|
||||
*
|
||||
* By default, the Client reboots the Kernel for each request. This method
|
||||
* allows to keep the same kernel across requests.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disableReboot()
|
||||
{
|
||||
@@ -103,6 +98,8 @@ class KernelBrowser extends HttpKernelBrowser
|
||||
|
||||
/**
|
||||
* Enables kernel reboot between requests.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enableReboot()
|
||||
{
|
||||
@@ -110,43 +107,42 @@ class KernelBrowser extends HttpKernelBrowser
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserInterface $user
|
||||
* @param UserInterface $user
|
||||
* @param array<string, mixed> $tokenAttributes
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function loginUser(object $user, string $firewallContext = 'main'): self
|
||||
public function loginUser(object $user, string $firewallContext = 'main'/* , array $tokenAttributes = [] */): static
|
||||
{
|
||||
$tokenAttributes = 2 < \func_num_args() ? func_get_arg(2) : [];
|
||||
|
||||
if (!interface_exists(UserInterface::class)) {
|
||||
throw new \LogicException(sprintf('"%s" requires symfony/security-core to be installed.', __METHOD__));
|
||||
throw new \LogicException(sprintf('"%s" requires symfony/security-core to be installed. Try running "composer require symfony/security-core".', __METHOD__));
|
||||
}
|
||||
|
||||
if (!$user instanceof UserInterface) {
|
||||
throw new \LogicException(sprintf('The first argument of "%s" must be instance of "%s", "%s" provided.', __METHOD__, UserInterface::class, \is_object($user) ? \get_class($user) : \gettype($user)));
|
||||
throw new \LogicException(sprintf('The first argument of "%s" must be instance of "%s", "%s" provided.', __METHOD__, UserInterface::class, get_debug_type($user)));
|
||||
}
|
||||
|
||||
$token = new TestBrowserToken($user->getRoles(), $user, $firewallContext);
|
||||
// @deprecated since Symfony 5.4
|
||||
if (method_exists($token, 'setAuthenticated')) {
|
||||
$token->setAttributes($tokenAttributes);
|
||||
// required for compatibility with Symfony 5.4
|
||||
if (method_exists($token, 'isAuthenticated')) {
|
||||
$token->setAuthenticated(true, false);
|
||||
}
|
||||
|
||||
$container = $this->getContainer();
|
||||
$container->get('security.untracked_token_storage')->setToken($token);
|
||||
|
||||
if ($container->has('session.factory')) {
|
||||
$session = $container->get('session.factory')->createSession();
|
||||
} elseif ($container->has('session')) {
|
||||
$session = $container->get('session');
|
||||
} else {
|
||||
if (!$container->has('session.factory')) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$session = $container->get('session.factory')->createSession();
|
||||
$session->set('_security_'.$firewallContext, serialize($token));
|
||||
$session->save();
|
||||
|
||||
$domains = array_unique(array_map(function (Cookie $cookie) use ($session) {
|
||||
return $cookie->getName() === $session->getName() ? $cookie->getDomain() : '';
|
||||
}, $this->getCookieJar()->all())) ?: [''];
|
||||
$domains = array_unique(array_map(fn (Cookie $cookie) => $cookie->getName() === $session->getName() ? $cookie->getDomain() : '', $this->getCookieJar()->all())) ?: [''];
|
||||
foreach ($domains as $domain) {
|
||||
$cookie = new Cookie($session->getName(), $session->getId(), null, null, $domain);
|
||||
$this->getCookieJar()->set($cookie);
|
||||
@@ -156,13 +152,9 @@ class KernelBrowser extends HttpKernelBrowser
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
protected function doRequest(object $request)
|
||||
protected function doRequest(object $request): Response
|
||||
{
|
||||
// avoid shutting down the Kernel if no request has been performed yet
|
||||
// WebTestCase::createClient() boots the Kernel but do not handle a request
|
||||
@@ -184,13 +176,9 @@ class KernelBrowser extends HttpKernelBrowser
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
protected function doRequestInProcess(object $request)
|
||||
protected function doRequestInProcess(object $request): Response
|
||||
{
|
||||
$response = parent::doRequestInProcess($request);
|
||||
|
||||
@@ -208,10 +196,8 @@ class KernelBrowser extends HttpKernelBrowser
|
||||
* client and override this method.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getScript(object $request)
|
||||
protected function getScript(object $request): string
|
||||
{
|
||||
$kernel = var_export(serialize($this->kernel), true);
|
||||
$request = var_export(serialize($request), true);
|
||||
|
||||
Reference in New Issue
Block a user