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:
bdalsass
2023-12-05 13:56:56 +01:00
committed by GitHub
parent 863ab4560c
commit 27ce51ab07
1392 changed files with 44869 additions and 27799 deletions

View File

@@ -0,0 +1,10 @@
<?php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $container) {
// kernel.secret
$container->parameters()->set('kernel.secret', MetaModel::GetConfig()->Get('application.secret'));
};

View File

@@ -1,5 +1,5 @@
framework:
secret: '%env(APP_SECRET)%'
#secret: (part of iTop general configuration, will be set dynamically via bridge.php)
#default_locale: en
#csrf_protection: true
#http_method_override: true

View File

@@ -52,6 +52,9 @@ services:
$aCombodoPortalInstanceConf: '%combodo.portal.instance.conf%'
$sCombodoPortalInstanceAbsoluteUrl: '%env(string:COMBODO_PORTAL_INSTANCE_ABSOLUTE_URL)%'
# Allow container service injection
Symfony\Component\DependencyInjection\ContainerInterface: '@service_container'
# Makes classes in src/ available to be used as services
# This creates a service per class whose id is the fully-qualified class name
Combodo\iTop\Portal\:
@@ -68,8 +71,6 @@ services:
_instanceof:
Combodo\iTop\Portal\EventListener\UserProvider:
tags: [{ name: 'kernel.event_listener', event: 'kernel.request', priority: 500 }]
calls:
- [setContainer, ['@service_container']]
Combodo\iTop\Portal\EventListener\ApplicationContextSetUrlMakerClass:
tags: [{ name: 'kernel.event_listener', event: 'kernel.request', priority: 400 }]
Combodo\iTop\Portal\EventListener\ApplicationContextSetPluginPropertyClass:
@@ -78,8 +79,7 @@ services:
tags: [{ name: 'kernel.event_listener', event: 'kernel.request', priority: 200 }]
Combodo\iTop\Portal\EventListener\ExceptionListener:
tags: [{ name: 'kernel.event_listener', event: 'kernel.exception', priority: 500 }]
calls:
- [setContainer, ['@service_container']]
# Add more service definitions when explicit configuration is needed
# Please note that last definitions always *replace* previous ones
@@ -103,6 +103,10 @@ services:
decorates: 'router'
arguments: ['@Combodo\iTop\Portal\Routing\UrlGenerator.inner']
# UI extension helper
Combodo\iTop\Portal\Helper\UIExtensionsHelper:
arguments: ['@service_container']
# Standard services
combodo.current_contact.photo_url:
public: true

View File

@@ -24,13 +24,12 @@ namespace Combodo\iTop\Portal\EventListener;
use Dict;
use ExceptionLog;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Twig\Environment;
/**
* Class ExceptionListener
@@ -39,19 +38,28 @@ use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
* @package Combodo\iTop\Portal\EventListener
* @since 2.7.0
*/
class ExceptionListener implements ContainerAwareInterface
class ExceptionListener
{
/** @var \Symfony\Component\DependencyInjection\ContainerInterface $container */
private $oContainer;
/**
* @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $oEvent
* Constructor.
*
* @param \Twig\Environment $oTwig
*/
public function __construct(
protected Environment $oTwig
)
{
}
/**
* @param ExceptionEvent $oEvent
*
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function onKernelException(ExceptionEvent $oEvent)
public function onKernelException(ExceptionEvent $oEvent) : void
{
// Get the exception object from the received event
$oException = $oEvent->getThrowable();
@@ -112,7 +120,7 @@ class ExceptionListener implements ContainerAwareInterface
else
{
$oResponse = new Response();
$oResponse->setContent($this->oContainer->get('twig')->render('itop-portal-base/portal/templates/errors/layout.html.twig', $aData));
$oResponse->setContent($this->oTwig->render('itop-portal-base/portal/templates/errors/layout.html.twig', $aData));
}
$oResponse->setStatusCode($iStatusCode);
@@ -156,11 +164,5 @@ class ExceptionListener implements ContainerAwareInterface
return str_replace($sNormalizedAppRoot, '', $sNormalizedInputPath);
}
/**
* @inheritDoc
*/
public function setContainer(ContainerInterface $oContainer = null)
{
$this->oContainer = $oContainer;
}
}

View File

@@ -36,14 +36,12 @@ use UserRights;
* @package Combodo\iTop\Portal\EventListener
* @since 2.7.0
*/
class UserProvider implements ContainerAwareInterface
class UserProvider
{
/** @var \ModuleDesign $oModuleDesign */
private $oModuleDesign;
/** @var string $sPortalId */
private $sPortalId;
/** @var \Symfony\Component\DependencyInjection\ContainerInterface $container */
private $oContainer;
/** @var \User $oUser */
private $oUser;
/** @var array $aAllowedPortals */
@@ -133,11 +131,5 @@ class UserProvider implements ContainerAwareInterface
return $this->aAllowedPortals;
}
/**
* @inheritDoc
*/
public function setContainer(ContainerInterface $oContainer = null)
{
$this->oContainer = $oContainer;
}
}

View File

@@ -43,7 +43,7 @@ class Kernel extends BaseKernel
/**
* @return string
*/
public function getCacheDir()
public function getCacheDir(): string
{
$cacheDir = $_ENV['PORTAL_ID'].'-'.$this->environment;
@@ -53,8 +53,8 @@ class Kernel extends BaseKernel
/**
* @return string
*/
public function getLogDir()
{
public function getLogDir(): string
{
$logDir = $_ENV['PORTAL_ID'] . '-' . $this->environment;
return utils::GetLogPath() . "/portals/$logDir";
@@ -63,8 +63,8 @@ class Kernel extends BaseKernel
/**
* @return \Generator|iterable|\Symfony\Component\HttpKernel\Bundle\BundleInterface[]
*/
public function registerBundles()
{
public function registerBundles(): iterable
{
$contents = require $this->getProjectDir().'/config/bundles.php';
foreach ($contents as $class => $envs) {
if (isset($envs[$this->environment]) || isset($envs['all'])) {
@@ -83,6 +83,7 @@ class Kernel extends BaseKernel
$confDir = '../config';
$container->import(new FileResource($this->getProjectDir().'/config/bundles.php'));
$container->import($confDir.'/bridge.php');
$container->parameters()->set('container.dumper.inline_class_loader', true);
$container->import($confDir.'/{packages}/*'.self::CONFIG_EXTS);

View File

@@ -48,7 +48,7 @@ class UrlGenerator implements RouterInterface
/**
* @inheritDoc
*/
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH): string
{
$parameters = $this->getExtraParams($parameters);
@@ -66,7 +66,7 @@ class UrlGenerator implements RouterInterface
/**
* @inheritDoc
*/
public function getContext()
public function getContext(): RequestContext
{
return $this->router->getContext();
}
@@ -82,7 +82,7 @@ class UrlGenerator implements RouterInterface
/**
* @inheritDoc
*/
public function match($pathinfo)
public function match($pathinfo): array
{
return $this->router->match($pathinfo);
}