Skip to content

PHP config builder is using "var/", magic and is preferred over arrays in documentation #19178

Closed as not planned
@raitocz

Description

@raitocz

I saw that there was an already merged PR symfony/symfony#40600 which enables config builders for PHP configs.

So instead of writting arrays:

// config/packages/security.php
use App\Entity\User;

$container->loadFromExtension('security', [
    // ...

    'providers' => [
        // used to reload user from session & other features (e.g. switch_user)
        'app_user_provider' => [
            'entity' => [
                'class' => User::class,
                'property' => 'email',
            ],
        ],
    ],
]);

you can use:

// config/packages/security.php
use App\Entity\User;
use Symfony\Config\SecurityConfig;

return static function (SecurityConfig $security): void {
    // ...

    $security->provider('app_user_provider')
        ->entity()
            ->class(User::class)
            ->property('email')
    ;
};

I know that it is mentioned in https://symfony.com/doc/current/configuration.html#using-php-configbuilders as note:

In order to get ConfigBuilders autocompletion in your IDE/editor, make sure to not exclude the directory where these classes are generated (by default, in var/cache/dev/Symfony/Config/).

but I would rather prefer that there are 2 PHP configuration options mentioned trough documentation:

  • PHP trough ConfigBuilder
  • PHP trough Array

Reason is: I build many applications in containers and using builders means that the var directory is not warmed-up, thus IDE is missing the classes.

... and also I personally think that having some magic classes appearing in var/ directory is bad practice. But that is just my opinion to discuss.

I also found it very confusing how it works and while having most of my configs as PHP arrays I struggle in conversion from "symfony doc using builders" to "configs in arrays" as there is no actual reference.

The fact that most of the documentation when describing the config reference uses mashup of both confirms that it is not done properly:

Security - Firewalls (PHP tab using ConfigBuilder): https://symfony.com/doc/current/reference/configuration/security.html#firewalls
Security - Log out (PHP tab using Arrays): https://symfony.com/doc/current/reference/configuration/security.html#firewalls

Metadata

Metadata

Assignees

No one assigned

    Labels

    ConfighasPRA Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions