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

@@ -11,15 +11,13 @@
namespace Symfony\Component\HttpKernel;
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
use Symfony\Component\Config\Builder\ConfigBuilderGenerator;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\Debug\DebugClassLoader as LegacyDebugClassLoader;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\Compiler\RemoveBuildParametersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
@@ -68,25 +66,25 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
protected $booted = false;
protected $startTime;
private $projectDir;
private $warmupDir;
private $requestStackSize = 0;
private $resetServices = false;
private string $projectDir;
private ?string $warmupDir = null;
private int $requestStackSize = 0;
private bool $resetServices = false;
/**
* @var array<string, bool>
*/
private static $freshCache = [];
private static array $freshCache = [];
public const VERSION = '5.4.20';
public const VERSION_ID = 50420;
public const MAJOR_VERSION = 5;
public const VERSION = '6.4.0';
public const VERSION_ID = 60400;
public const MAJOR_VERSION = 6;
public const MINOR_VERSION = 4;
public const RELEASE_VERSION = 20;
public const RELEASE_VERSION = 0;
public const EXTRA_VERSION = '';
public const END_OF_MAINTENANCE = '11/2024';
public const END_OF_LIFE = '11/2025';
public const END_OF_MAINTENANCE = '11/2026';
public const END_OF_LIFE = '11/2027';
public function __construct(string $environment, bool $debug)
{
@@ -106,7 +104,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
}
/**
* {@inheritdoc}
* @return void
*/
public function boot()
{
@@ -137,7 +135,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
}
/**
* {@inheritdoc}
* @return void
*/
public function reboot(?string $warmupDir)
{
@@ -147,7 +145,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
}
/**
* {@inheritdoc}
* @return void
*/
public function terminate(Request $request, Response $response)
{
@@ -161,7 +159,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
}
/**
* {@inheritdoc}
* @return void
*/
public function shutdown()
{
@@ -181,10 +179,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
$this->resetServices = false;
}
/**
* {@inheritdoc}
*/
public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true)
public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true): Response
{
if (!$this->booted) {
$container = $this->container ?? $this->preBoot();
@@ -207,26 +202,18 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/**
* Gets an HTTP kernel from the container.
*
* @return HttpKernelInterface
*/
protected function getHttpKernel()
protected function getHttpKernel(): HttpKernelInterface
{
return $this->container->get('http_kernel');
}
/**
* {@inheritdoc}
*/
public function getBundles()
public function getBundles(): array
{
return $this->bundles;
}
/**
* {@inheritdoc}
*/
public function getBundle(string $name)
public function getBundle(string $name): BundleInterface
{
if (!isset($this->bundles[$name])) {
throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled. Maybe you forgot to add it in the "registerBundles()" method of your "%s.php" file?', $name, get_debug_type($this)));
@@ -235,10 +222,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
return $this->bundles[$name];
}
/**
* {@inheritdoc}
*/
public function locateResource(string $name)
public function locateResource(string $name): string
{
if ('@' !== $name[0]) {
throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
@@ -262,30 +246,22 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
}
/**
* {@inheritdoc}
*/
public function getEnvironment()
public function getEnvironment(): string
{
return $this->environment;
}
/**
* {@inheritdoc}
*/
public function isDebug()
public function isDebug(): bool
{
return $this->debug;
}
/**
* Gets the application root dir (path of the project's composer file).
*
* @return string
*/
public function getProjectDir()
public function getProjectDir(): string
{
if (null === $this->projectDir) {
if (!isset($this->projectDir)) {
$r = new \ReflectionObject($this);
if (!is_file($dir = $r->getFileName())) {
@@ -305,10 +281,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
return $this->projectDir;
}
/**
* {@inheritdoc}
*/
public function getContainer()
public function getContainer(): ContainerInterface
{
if (!$this->container) {
throw new \LogicException('Cannot retrieve the container from a non-booted kernel.');
@@ -320,48 +293,33 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/**
* @internal
*/
public function setAnnotatedClassCache(array $annotatedClasses)
public function setAnnotatedClassCache(array $annotatedClasses): void
{
file_put_contents(($this->warmupDir ?: $this->getBuildDir()).'/annotations.map', sprintf('<?php return %s;', var_export($annotatedClasses, true)));
}
/**
* {@inheritdoc}
*/
public function getStartTime()
public function getStartTime(): float
{
return $this->debug && null !== $this->startTime ? $this->startTime : -\INF;
}
/**
* {@inheritdoc}
*/
public function getCacheDir()
public function getCacheDir(): string
{
return $this->getProjectDir().'/var/cache/'.$this->environment;
}
/**
* {@inheritdoc}
*/
public function getBuildDir(): string
{
// Returns $this->getCacheDir() for backward compatibility
return $this->getCacheDir();
}
/**
* {@inheritdoc}
*/
public function getLogDir()
public function getLogDir(): string
{
return $this->getProjectDir().'/var/log';
}
/**
* {@inheritdoc}
*/
public function getCharset()
public function getCharset(): string
{
return 'UTF-8';
}
@@ -377,6 +335,8 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/**
* Initializes bundles.
*
* @return void
*
* @throws \LogicException if two bundles share a common name
*/
protected function initializeBundles()
@@ -396,6 +356,8 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
* The extension point similar to the Bundle::build() method.
*
* Use this method to register compiler passes and manipulate the container during the building process.
*
* @return void
*/
protected function build(ContainerBuilder $container)
{
@@ -405,10 +367,8 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
* Gets the container class.
*
* @throws \InvalidArgumentException If the generated classname is invalid
*
* @return string
*/
protected function getContainerClass()
protected function getContainerClass(): string
{
$class = static::class;
$class = str_contains($class, "@anonymous\0") ? get_parent_class($class).str_replace('.', '_', ContainerBuilder::hash($class)) : $class;
@@ -425,10 +385,8 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
* Gets the container's base class.
*
* All names except Container must be fully qualified.
*
* @return string
*/
protected function getContainerBaseClass()
protected function getContainerBaseClass(): string
{
return 'Container';
}
@@ -438,6 +396,8 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
*
* The built version of the service container is used when fresh, otherwise the
* container is built.
*
* @return void
*/
protected function initializeContainer()
{
@@ -467,13 +427,13 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
try {
is_dir($buildDir) ?: mkdir($buildDir, 0777, true);
if ($lock = fopen($cachePath.'.lock', 'w')) {
if ($lock = fopen($cachePath.'.lock', 'w+')) {
if (!flock($lock, \LOCK_EX | \LOCK_NB, $wouldBlock) && !flock($lock, $wouldBlock ? \LOCK_SH : \LOCK_EX)) {
fclose($lock);
$lock = null;
} elseif (!is_file($cachePath) || !\is_object($this->container = include $cachePath)) {
$this->container = null;
} elseif (!$oldContainer || \get_class($this->container) !== $oldContainer->name) {
} elseif (!$oldContainer || $this->container::class !== $oldContainer->name) {
flock($lock, \LOCK_UN);
fclose($lock);
$this->container->set('kernel', $this);
@@ -521,7 +481,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
// Remove frames added by DebugClassLoader.
for ($i = \count($backtrace) - 2; 0 < $i; --$i) {
if (\in_array($backtrace[$i]['class'] ?? null, [DebugClassLoader::class, LegacyDebugClassLoader::class], true)) {
if (DebugClassLoader::class === ($backtrace[$i]['class'] ?? null)) {
$backtrace = [$backtrace[$i + 1]];
break;
}
@@ -563,7 +523,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
$this->container = require $cachePath;
$this->container->set('kernel', $this);
if ($oldContainer && \get_class($this->container) !== $oldContainer->name) {
if ($oldContainer && $this->container::class !== $oldContainer->name) {
// Because concurrent requests might still be using them,
// old container files are not removed immediately,
// but on a next dump of the container.
@@ -579,29 +539,27 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
touch($oldContainerDir.'.legacy');
}
$preload = $this instanceof WarmableInterface ? (array) $this->warmUp($this->container->getParameter('kernel.cache_dir')) : [];
$preload = $this instanceof WarmableInterface ? (array) $this->warmUp($this->container->getParameter('kernel.cache_dir'), $buildDir) : [];
if ($this->container->has('cache_warmer')) {
$preload = array_merge($preload, (array) $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir')));
$preload = array_merge($preload, (array) $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'), $buildDir));
}
if ($preload && method_exists(Preloader::class, 'append') && file_exists($preloadFile = $buildDir.'/'.$class.'.preload.php')) {
if ($preload && file_exists($preloadFile = $buildDir.'/'.$class.'.preload.php')) {
Preloader::append($preloadFile, $preload);
}
}
/**
* Returns the kernel parameters.
*
* @return array
*/
protected function getKernelParameters()
protected function getKernelParameters(): array
{
$bundles = [];
$bundlesMetadata = [];
foreach ($this->bundles as $name => $bundle) {
$bundles[$name] = \get_class($bundle);
$bundles[$name] = $bundle::class;
$bundlesMetadata[$name] = [
'path' => $bundle->getPath(),
'namespace' => $bundle->getNamespace(),
@@ -612,6 +570,10 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
'kernel.environment' => $this->environment,
'kernel.runtime_environment' => '%env(default:kernel.environment:APP_RUNTIME_ENV)%',
'kernel.runtime_mode' => '%env(query_string:default:container.runtime_mode:APP_RUNTIME_MODE)%',
'kernel.runtime_mode.web' => '%env(bool:default::key:web:default:kernel.runtime_mode:)%',
'kernel.runtime_mode.cli' => '%env(not:default:kernel.runtime_mode.web:)%',
'kernel.runtime_mode.worker' => '%env(bool:default::key:worker:default:kernel.runtime_mode:)%',
'kernel.debug' => $this->debug,
'kernel.build_dir' => realpath($buildDir = $this->warmupDir ?: $this->getBuildDir()) ?: $buildDir,
'kernel.cache_dir' => realpath($cacheDir = ($this->getCacheDir() === $this->getBuildDir() ? ($this->warmupDir ?: $this->getCacheDir()) : $this->getCacheDir())) ?: $cacheDir,
@@ -626,11 +588,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/**
* Builds the service container.
*
* @return ContainerBuilder
*
* @throws \RuntimeException
*/
protected function buildContainer()
protected function buildContainer(): ContainerBuilder
{
foreach (['cache' => $this->getCacheDir(), 'build' => $this->warmupDir ?: $this->getBuildDir(), 'logs' => $this->getLogDir()] as $name => $dir) {
if (!is_dir($dir)) {
@@ -645,11 +605,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
$container = $this->getContainerBuilder();
$container->addObjectResource($this);
$this->prepareContainer($container);
if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
trigger_deprecation('symfony/http-kernel', '5.3', 'Returning a ContainerBuilder from "%s::registerContainerConfiguration()" is deprecated.', get_debug_type($this));
$container->merge($cont);
}
$this->registerContainerConfiguration($this->getContainerLoader($container));
$container->addCompilerPass(new AddAnnotatedClassesToCachePass($this));
@@ -658,6 +614,8 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/**
* Prepares the ContainerBuilder before it is compiled.
*
* @return void
*/
protected function prepareContainer(ContainerBuilder $container)
{
@@ -688,10 +646,8 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/**
* Gets a new ContainerBuilder instance used to build the service container.
*
* @return ContainerBuilder
*/
protected function getContainerBuilder()
protected function getContainerBuilder(): ContainerBuilder
{
$container = new ContainerBuilder();
$container->getParameterBag()->add($this->getKernelParameters());
@@ -702,9 +658,6 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
if ($this instanceof CompilerPassInterface) {
$container->addCompilerPass($this, PassConfig::TYPE_BEFORE_OPTIMIZATION, -10000);
}
if (class_exists(\ProxyManager\Configuration::class) && class_exists(RuntimeInstantiator::class)) {
$container->setProxyInstantiator(new RuntimeInstantiator());
}
return $container;
}
@@ -714,14 +667,35 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
*
* @param string $class The name of the class to generate
* @param string $baseClass The name of the container's base class
*
* @return void
*/
protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, string $class, string $baseClass)
{
// cache the container
$dumper = new PhpDumper($container);
if (class_exists(\ProxyManager\Configuration::class) && class_exists(ProxyDumper::class)) {
$dumper->setProxyDumper(new ProxyDumper());
$buildParameters = [];
foreach ($container->getCompilerPassConfig()->getPasses() as $pass) {
if ($pass instanceof RemoveBuildParametersPass) {
$buildParameters = array_merge($buildParameters, $pass->getRemovedParameters());
}
}
$inlineFactories = false;
if (isset($buildParameters['.container.dumper.inline_factories'])) {
$inlineFactories = $buildParameters['.container.dumper.inline_factories'];
} elseif ($container->hasParameter('container.dumper.inline_factories')) {
trigger_deprecation('symfony/http-kernel', '6.3', 'Parameter "%s" is deprecated, use ".%1$s" instead.', 'container.dumper.inline_factories');
$inlineFactories = $container->getParameter('container.dumper.inline_factories');
}
$inlineClassLoader = $this->debug;
if (isset($buildParameters['.container.dumper.inline_class_loader'])) {
$inlineClassLoader = $buildParameters['.container.dumper.inline_class_loader'];
} elseif ($container->hasParameter('container.dumper.inline_class_loader')) {
trigger_deprecation('symfony/http-kernel', '6.3', 'Parameter "%s" is deprecated, use ".%1$s" instead.', 'container.dumper.inline_class_loader');
$inlineClassLoader = $container->getParameter('container.dumper.inline_class_loader');
}
$content = $dumper->dump([
@@ -730,6 +704,8 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
'file' => $cache->getPath(),
'as_files' => true,
'debug' => $this->debug,
'inline_factories' => $inlineFactories,
'inline_class_loader' => $inlineClassLoader,
'build_time' => $container->hasParameter('kernel.container_build_time') ? $container->getParameter('kernel.container_build_time') : time(),
'preload_classes' => array_map('get_class', $this->bundles),
]);
@@ -752,10 +728,8 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/**
* Returns a loader for the container.
*
* @return DelegatingLoader
*/
protected function getContainerLoader(ContainerInterface $container)
protected function getContainerLoader(ContainerInterface $container): DelegatingLoader
{
$env = $this->getEnvironment();
$locator = new FileLocator($this);
@@ -778,7 +752,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
$this->startTime = microtime(true);
}
if ($this->debug && !isset($_ENV['SHELL_VERBOSITY']) && !isset($_SERVER['SHELL_VERBOSITY'])) {
putenv('SHELL_VERBOSITY=3');
if (\function_exists('putenv')) {
putenv('SHELL_VERBOSITY=3');
}
$_ENV['SHELL_VERBOSITY'] = 3;
$_SERVER['SHELL_VERBOSITY'] = 3;
}
@@ -805,10 +781,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
* We don't use the PHP php_strip_whitespace() function
* as we want the content to be readable and well-formatted.
*
* @return string
* @deprecated since Symfony 6.4 without replacement
*/
public static function stripComments(string $source)
public static function stripComments(string $source): string
{
trigger_deprecation('symfony/http-kernel', '6.4', 'Method "%s()" is deprecated without replacement.', __METHOD__);
if (!\function_exists('token_get_all')) {
return $source;
}
@@ -862,14 +840,14 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
return $output;
}
/**
* @return array
*/
public function __sleep()
public function __sleep(): array
{
return ['environment', 'debug'];
}
/**
* @return void
*/
public function __wakeup()
{
if (\is_object($this->environment) || \is_object($this->debug)) {