mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +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:
61
lib/symfony/http-kernel/Bundle/AbstractBundle.php
Normal file
61
lib/symfony/http-kernel/Bundle/AbstractBundle.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Bundle;
|
||||
|
||||
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\ConfigurableExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
/**
|
||||
* A Bundle that provides configuration hooks.
|
||||
*
|
||||
* @author Yonel Ceruto <yonelceruto@gmail.com>
|
||||
*/
|
||||
abstract class AbstractBundle extends Bundle implements ConfigurableExtensionInterface
|
||||
{
|
||||
protected string $extensionAlias = '';
|
||||
|
||||
public function configure(DefinitionConfigurator $definition): void
|
||||
{
|
||||
}
|
||||
|
||||
public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
|
||||
{
|
||||
}
|
||||
|
||||
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
|
||||
{
|
||||
}
|
||||
|
||||
public function getContainerExtension(): ?ExtensionInterface
|
||||
{
|
||||
if ('' === $this->extensionAlias) {
|
||||
$this->extensionAlias = Container::underscore(preg_replace('/Bundle$/', '', $this->getName()));
|
||||
}
|
||||
|
||||
return $this->extension ??= new BundleExtension($this, $this->extensionAlias);
|
||||
}
|
||||
|
||||
public function getPath(): string
|
||||
{
|
||||
if (null === $this->path) {
|
||||
$reflected = new \ReflectionObject($this);
|
||||
// assume the modern directory structure by default
|
||||
$this->path = \dirname($reflected->getFileName(), 2);
|
||||
}
|
||||
|
||||
return $this->path;
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,8 @@ namespace Symfony\Component\HttpKernel\Bundle;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||
|
||||
/**
|
||||
@@ -24,32 +24,35 @@ use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||
*/
|
||||
abstract class Bundle implements BundleInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
protected $name;
|
||||
protected $extension;
|
||||
protected $path;
|
||||
private $namespace;
|
||||
private string $namespace;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @var ContainerInterface|null
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @return void
|
||||
*/
|
||||
public function shutdown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* This method can be overridden to register compilation passes,
|
||||
* other extensions, ...
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function build(ContainerBuilder $container)
|
||||
{
|
||||
@@ -58,13 +61,11 @@ abstract class Bundle implements BundleInterface
|
||||
/**
|
||||
* Returns the bundle's container extension.
|
||||
*
|
||||
* @return ExtensionInterface|null
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function getContainerExtension()
|
||||
public function getContainerExtension(): ?ExtensionInterface
|
||||
{
|
||||
if (null === $this->extension) {
|
||||
if (!isset($this->extension)) {
|
||||
$extension = $this->createContainerExtension();
|
||||
|
||||
if (null !== $extension) {
|
||||
@@ -89,24 +90,18 @@ abstract class Bundle implements BundleInterface
|
||||
return $this->extension ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getNamespace()
|
||||
public function getNamespace(): string
|
||||
{
|
||||
if (null === $this->namespace) {
|
||||
if (!isset($this->namespace)) {
|
||||
$this->parseClassName();
|
||||
}
|
||||
|
||||
return $this->namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
public function getPath(): string
|
||||
{
|
||||
if (null === $this->path) {
|
||||
if (!isset($this->path)) {
|
||||
$reflected = new \ReflectionObject($this);
|
||||
$this->path = \dirname($reflected->getFileName());
|
||||
}
|
||||
@@ -119,23 +114,24 @@ abstract class Bundle implements BundleInterface
|
||||
*/
|
||||
final public function getName(): string
|
||||
{
|
||||
if (null === $this->name) {
|
||||
if (!isset($this->name)) {
|
||||
$this->parseClassName();
|
||||
}
|
||||
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function registerCommands(Application $application)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bundle's container extension class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getContainerExtensionClass()
|
||||
protected function getContainerExtensionClass(): string
|
||||
{
|
||||
$basename = preg_replace('/Bundle$/', '', $this->getName());
|
||||
|
||||
@@ -144,20 +140,21 @@ abstract class Bundle implements BundleInterface
|
||||
|
||||
/**
|
||||
* Creates the bundle's container extension.
|
||||
*
|
||||
* @return ExtensionInterface|null
|
||||
*/
|
||||
protected function createContainerExtension()
|
||||
protected function createContainerExtension(): ?ExtensionInterface
|
||||
{
|
||||
return class_exists($class = $this->getContainerExtensionClass()) ? new $class() : null;
|
||||
}
|
||||
|
||||
private function parseClassName()
|
||||
private function parseClassName(): void
|
||||
{
|
||||
$pos = strrpos(static::class, '\\');
|
||||
$this->namespace = false === $pos ? '' : substr(static::class, 0, $pos);
|
||||
if (null === $this->name) {
|
||||
$this->name = false === $pos ? static::class : substr(static::class, $pos + 1);
|
||||
}
|
||||
$this->name ??= false === $pos ? static::class : substr(static::class, $pos + 1);
|
||||
}
|
||||
|
||||
public function setContainer(?ContainerInterface $container): void
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
}
|
||||
|
||||
67
lib/symfony/http-kernel/Bundle/BundleExtension.php
Normal file
67
lib/symfony/http-kernel/Bundle/BundleExtension.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Bundle;
|
||||
|
||||
use Symfony\Component\Config\Definition\Configuration;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\ConfigurableExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
use Symfony\Component\DependencyInjection\Extension\ExtensionTrait;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
/**
|
||||
* @author Yonel Ceruto <yonelceruto@gmail.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BundleExtension extends Extension implements PrependExtensionInterface
|
||||
{
|
||||
use ExtensionTrait;
|
||||
|
||||
public function __construct(
|
||||
private ConfigurableExtensionInterface $subject,
|
||||
private string $alias,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface
|
||||
{
|
||||
return new Configuration($this->subject, $container, $this->getAlias());
|
||||
}
|
||||
|
||||
public function getAlias(): string
|
||||
{
|
||||
return $this->alias;
|
||||
}
|
||||
|
||||
public function prepend(ContainerBuilder $container): void
|
||||
{
|
||||
$callback = function (ContainerConfigurator $configurator) use ($container) {
|
||||
$this->subject->prependExtension($configurator, $container);
|
||||
};
|
||||
|
||||
$this->executeConfiguratorCallback($container, $callback, $this->subject);
|
||||
}
|
||||
|
||||
public function load(array $configs, ContainerBuilder $container): void
|
||||
{
|
||||
$config = $this->processConfiguration($this->getConfiguration([], $container), $configs);
|
||||
|
||||
$callback = function (ContainerConfigurator $configurator) use ($config, $container) {
|
||||
$this->subject->loadExtension($config, $configurator, $container);
|
||||
};
|
||||
|
||||
$this->executeConfiguratorCallback($container, $callback, $this->subject);
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Bundle;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||
|
||||
/**
|
||||
@@ -20,15 +20,19 @@ use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
interface BundleInterface extends ContainerAwareInterface
|
||||
interface BundleInterface
|
||||
{
|
||||
/**
|
||||
* Boots the Bundle.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot();
|
||||
|
||||
/**
|
||||
* Shutdowns the Bundle.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function shutdown();
|
||||
|
||||
@@ -36,36 +40,35 @@ interface BundleInterface extends ContainerAwareInterface
|
||||
* Builds the bundle.
|
||||
*
|
||||
* It is only ever called once when the cache is empty.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function build(ContainerBuilder $container);
|
||||
|
||||
/**
|
||||
* Returns the container extension that should be implicitly loaded.
|
||||
*
|
||||
* @return ExtensionInterface|null
|
||||
*/
|
||||
public function getContainerExtension();
|
||||
public function getContainerExtension(): ?ExtensionInterface;
|
||||
|
||||
/**
|
||||
* Returns the bundle name (the class short name).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
public function getName(): string;
|
||||
|
||||
/**
|
||||
* Gets the Bundle namespace.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNamespace();
|
||||
public function getNamespace(): string;
|
||||
|
||||
/**
|
||||
* Gets the Bundle directory path.
|
||||
*
|
||||
* The path should always be returned as a Unix path (with /).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPath();
|
||||
public function getPath(): string;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setContainer(?ContainerInterface $container);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user