Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Config] ParamConfigurator is not longer respected as scalar-string-value #54852

Closed
michaljusiega opened this issue May 6, 2024 · 3 comments · Fixed by #54970 or #54977
Closed

[Config] ParamConfigurator is not longer respected as scalar-string-value #54852

michaljusiega opened this issue May 6, 2024 · 3 comments · Fixed by #54970 or #54977

Comments

@michaljusiega
Copy link
Contributor

michaljusiega commented May 6, 2024

Symfony version(s) affected

7.1.0-BETA1

Description

After update to BETA released version, I got an error for configuration, where ParamConfigurator is not anymore respected as scalar value.

I don't know what changes cause this issue.

How to reproduce

One of:

use Symfony\Config\FrameworkConfig;

use function Symfony\Component\DependencyInjection\Loader\Configurator\param;

return static function (FrameworkConfig $frameworkConfig): void {
    $frameworkConfig->phpErrors()
        ->log(value: param(name: 'kernel.debug'));
};

Possible Solution

Cast ParamConfigurator to string anyway, when the configuration allows you to pass an object.

use Symfony\Config\FrameworkConfig;

use function Symfony\Component\DependencyInjection\Loader\Configurator\param;

return static function (FrameworkConfig $frameworkConfig): void {
    $frameworkConfig->phpErrors()
        ->log(value: (string) param(name: 'kernel.debug'));
};

Additional Context

obraz
obraz

@nicolas-grekas
Copy link
Member

Can you figure out which change trigger this regression?

@michaljusiega
Copy link
Contributor Author

michaljusiega commented May 7, 2024

No, I cannot.

As far as I know is:

7.0:
obraz
7.1
obraz

#52843 this change is the closest to regression, but I could be wrong.

Edit: I think, I found something !

In 7.0 (https://github.com/symfony/symfony/blob/7.0/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php#L150) each ConfigBuilder instance after callback is processed further by ContainerConfigurator which array result was wrapped by AbstractConfigurator::processValue() in https://github.com/symfony/symfony/blob/7.0/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php#L58

In 7.1 collected configs are loaded directly by https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php#L157 without processing values by using AbstractConfigurator::processValue()

My suggestion to fix this problem:

Subject: [PATCH] Fixed non-processed configs
diff --git a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php
--- a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php
+++ b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php
@@ -27,6 +27,7 @@
 use Symfony\Component\DependencyInjection\Definition;
 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
 use Symfony\Component\DependencyInjection\Exception\LogicException;
+use Symfony\Component\DependencyInjection\Loader\Configurator\AbstractConfigurator;
 
 /**
  * FileLoader is the abstract class used by all built-in loaders that are file based.
@@ -229,6 +230,8 @@
 
     final protected function loadExtensionConfig(string $namespace, array $config): void
     {
+        $config = AbstractConfigurator::processValue($config);
+
         if (!$this->prepend) {
             $this->container->loadFromExtension($namespace, $config);

@michaljusiega
Copy link
Contributor Author

michaljusiega commented May 17, 2024

@nicolas-grekas Can We move further this issue ? I think it's important blocker, somebody who using PHP config.

fabpot added a commit that referenced this issue May 21, 2024
…ig loader (yceruto)

This PR was merged into the 7.1 branch.

Discussion
----------

[DependencyInjection] Fix prepending strategy for php config loader

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #54852
| License       | MIT

working towards fixing #54970

Commits
-------

a7ecb85 Fix prepending strategy for php config loader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants