Skip to content

FrameworkConfig::router()::strictRequirements(null): final value is true #45782

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

Closed
steevanb opened this issue Mar 18, 2022 · 1 comment
Closed

Comments

@steevanb
Copy link

steevanb commented Mar 18, 2022

Symfony version(s) affected

6.0.5

Description

When i change yaml configuration file format to PHP in config/packages directory, i have this code for routing.php:

return static function (FrameworkConfig $config): void {
    $config
        ->router()
        ->strictRequirements(null);
};

But when i see var/cache/devSymfony/Framework/RouterConfig.php, i have this code in toArray():

        if (null !== $this->strictRequirements) {
            $output['strict_requirements'] = $this->strictRequirements;
        }

Problem: final value will not be null as configured and expected, but true, because it's the default value.
I can configure it in yaml, it works, and it's the default configuration when we create a project:

framework:
    router:
        strict_requirements: null

How to reproduce

Create a new project, then add in src/Kernel.php to read PHP configuration files:

    private function configureContainer(
        ContainerConfigurator $container,
        LoaderInterface $loader,
        ContainerBuilder $builder
    ): void {
        $configDir = $this->getConfigDir();

        $container->import($configDir.'/{packages}/*.yaml');
        $container->import($configDir.'/{packages}/'.$this->environment.'/*.yaml');

        $container->import($configDir.'/{packages}/*.php');
        $container->import($configDir.'/{packages}/'.$this->environment.'/*.php');

        if (is_file($configDir.'/services.yaml')) {
            $container->import($configDir.'/services.yaml');
            $container->import($configDir.'/{services}_'.$this->environment.'.yaml');
        } else {
            $container->import($configDir.'/{services}.php');
        }
    }

Another little problem: in the documentation (https://symfony.com/doc/current/configuration.html#using-php-configbuilders) we may think PHP configuration files are always readed, but that's not the case, we need to modify the Kernel to take this files into account.

Possible Solution

Allow passing null when configuration allow this value?

Additional Context

No response

@steevanb steevanb added the Bug label Mar 18, 2022
nicolas-grekas added a commit that referenced this issue Mar 22, 2022
This PR was merged into the 5.4 branch.

Discussion
----------

[Config] Fix using null values with config builders

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #45782
| License       | MIT
| Doc PR        | -

The generated config builders will no longer discard `null` values.

Commits
-------

1264225 [Config] Fix using null values with config builders
@gnutix
Copy link
Contributor

gnutix commented Apr 2, 2022

This probably fixes #42320 too (I've not tested yet though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants