mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38: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:
@@ -34,7 +34,7 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
|
||||
class PhpFileLoader extends FileLoader
|
||||
{
|
||||
protected $autoRegisterAliasesForSinglyImplementedInterfaces = false;
|
||||
private $generator;
|
||||
private ?ConfigBuilderGeneratorInterface $generator;
|
||||
|
||||
public function __construct(ContainerBuilder $container, FileLocatorInterface $locator, string $env = null, ConfigBuilderGeneratorInterface $generator = null)
|
||||
{
|
||||
@@ -42,10 +42,7 @@ class PhpFileLoader extends FileLoader
|
||||
$this->generator = $generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load($resource, string $type = null)
|
||||
public function load(mixed $resource, string $type = null): mixed
|
||||
{
|
||||
// the container and loader variables are exposed to the included file below
|
||||
$container = $this->container;
|
||||
@@ -74,10 +71,7 @@ class PhpFileLoader extends FileLoader
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports($resource, string $type = null)
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
{
|
||||
if (!\is_string($resource)) {
|
||||
return false;
|
||||
@@ -93,28 +87,23 @@ class PhpFileLoader extends FileLoader
|
||||
/**
|
||||
* Resolve the parameters to the $callback and execute it.
|
||||
*/
|
||||
private function executeCallback(callable $callback, ContainerConfigurator $containerConfigurator, string $path)
|
||||
private function executeCallback(callable $callback, ContainerConfigurator $containerConfigurator, string $path): void
|
||||
{
|
||||
if (!$callback instanceof \Closure) {
|
||||
$callback = \Closure::fromCallable($callback);
|
||||
}
|
||||
|
||||
$callback = $callback(...);
|
||||
$arguments = [];
|
||||
$configBuilders = [];
|
||||
$r = new \ReflectionFunction($callback);
|
||||
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
$attribute = null;
|
||||
foreach ($r->getAttributes(When::class) as $attribute) {
|
||||
if ($this->env === $attribute->newInstance()->env) {
|
||||
$attribute = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (null !== $attribute) {
|
||||
return;
|
||||
$attribute = null;
|
||||
foreach ($r->getAttributes(When::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
|
||||
if ($this->env === $attribute->newInstance()->env) {
|
||||
$attribute = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (null !== $attribute) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($r->getParameters() as $parameter) {
|
||||
$reflectionType = $parameter->getType();
|
||||
@@ -134,6 +123,12 @@ class PhpFileLoader extends FileLoader
|
||||
case self::class:
|
||||
$arguments[] = $this;
|
||||
break;
|
||||
case 'string':
|
||||
if (null !== $this->env && 'env' === $parameter->getName()) {
|
||||
$arguments[] = $this->env;
|
||||
break;
|
||||
}
|
||||
// no break
|
||||
default:
|
||||
try {
|
||||
$configBuilder = $this->configBuilder($type);
|
||||
@@ -174,20 +169,20 @@ class PhpFileLoader extends FileLoader
|
||||
return new $namespace();
|
||||
}
|
||||
|
||||
// If it does not start with Symfony\Config\ we dont know how to handle this
|
||||
if ('Symfony\\Config\\' !== substr($namespace, 0, 15)) {
|
||||
// If it does not start with Symfony\Config\ we don't know how to handle this
|
||||
if (!str_starts_with($namespace, 'Symfony\\Config\\')) {
|
||||
throw new InvalidArgumentException(sprintf('Could not find or generate class "%s".', $namespace));
|
||||
}
|
||||
|
||||
// Try to get the extension alias
|
||||
$alias = Container::underscore(substr($namespace, 15, -6));
|
||||
|
||||
if (false !== strpos($alias, '\\')) {
|
||||
if (str_contains($alias, '\\')) {
|
||||
throw new InvalidArgumentException('You can only use "root" ConfigBuilders from "Symfony\\Config\\" namespace. Nested classes like "Symfony\\Config\\Framework\\CacheConfig" cannot be used.');
|
||||
}
|
||||
|
||||
if (!$this->container->hasExtension($alias)) {
|
||||
$extensions = array_filter(array_map(function (ExtensionInterface $ext) { return $ext->getAlias(); }, $this->container->getExtensions()));
|
||||
$extensions = array_filter(array_map(fn (ExtensionInterface $ext) => $ext->getAlias(), $this->container->getExtensions()));
|
||||
throw new InvalidArgumentException(sprintf('There is no extension able to load the configuration for "%s". Looked for namespace "%s", found "%s".', $namespace, $alias, $extensions ? implode('", "', $extensions) : 'none'));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user