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

Convert PHP Array Config to PHP ConfigBuilder #4

Open
alexander-schranz opened this issue Aug 14, 2022 · 5 comments
Open

Convert PHP Array Config to PHP ConfigBuilder #4

alexander-schranz opened this issue Aug 14, 2022 · 5 comments
Labels
feature New feature or request
Milestone

Comments

@alexander-schranz
Copy link
Member

alexander-schranz commented Aug 14, 2022

Since Symfony 5.3 there exist a new way of configuring packages. The config builders:

https://symfony.com/blog/new-in-symfony-5-3-config-builder-classes

It would be great as we are currently having done the step from yaml to php configs. To do the next step from PHP array configs to PHP config builder configs.

Not sure how easy possible without knowing the Builder class and only the array this is even possible.

@alexander-schranz alexander-schranz added the feature New feature or request label Aug 14, 2022
@alexander-schranz alexander-schranz added this to the future milestone Aug 14, 2022
@weaverryan
Copy link

I had the same thought... and also not sure if it's possible. Well, those config builders are built from the config tree/Configuration classes... so in theory it might be possible.

But these seems important. If we're going to allow PHP config, I think the config builders need to be used from day 1 or never at all. Switching to it later would be a second nightmare of updating docs, getting people to migrate again and trying to get recipes:update to work.

@alexander-schranz alexander-schranz modified the milestones: future, 1.0 Aug 17, 2022
@alexander-schranz
Copy link
Member Author

Understand your point, I added it also to the release milestone. I already had a quick chat with @Nyholm about the ConfigBuilders as I think he knows most about them. He already mention that the yaml has some shortcuts, if he got some time he will add his thoughts about it.

@alexander-schranz
Copy link
Member Author

alexander-schranz commented Nov 27, 2022

There is still a long way in front of us but already created a prototype to convert PHP Array Configs to ConfigBuilder.

First results:

 <?php

 declare(strict_types=1);
+use Symfony\Config\FrameworkConfig;

 use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

-return static function (ContainerConfigurator $containerConfigurator): void {
-    $containerConfigurator->extension('framework', [
-        'session' => [
-            'handler_id' => null,
-            'cookie_secure' => 'auto',
-            'cookie_samesite' => 'lax',
-            'storage_factory_id' => 'session.storage.factory.native',
-        ],
-    ]);
+return static function (FrameworkConfig $frameworkConfig): void {
+    $frameworkConfig->session()->handlerId(null)->cookieSecure('auto')->cookieSamesite('lax')->storageFactoryId('session.storage.factory.native');
     if ($containerConfigurator->env() === 'test') {
-        $containerConfigurator->extension('framework', [
-            'session' => [
-                'storage_factory_id' => 'session.storage.factory.mock_file',
-            ],
-        ]);
+        $frameworkConfig->session()->storageFactoryId('session.storage.factory.mock_file');
     }
 };

Test Repo: https://github.com/alexander-schranz/prototype-config-builder-refractor

Currently it is very abstract and is not aware of the ConfigBuilder class. I could not yet find out how to load the ConfigBuilder classes as they seems not registered via the autoloader, which will be required so I can find the correct methods which I need to call.

@weaverryan
Copy link

That's impressive! Even Tobias, who created the ConfigBuilder, thought that this type of conversion would likely be impossible.

I'm not sure about the autoloader part... I do know these classes are compiled into the cache, so they must be required some "other" way by Symfony itself.

Do you think this approach could actually work? There are a lot of different config and config builders. I want it to work - but I know it's complex!

@alexander-schranz
Copy link
Member Author

alexander-schranz commented Nov 28, 2022

@Nyholm could already help me with the autoloader. There is some generator which is currently handling this.

The config transformer is currently very dumb and not aware of the edge cases. But we really has the advantages that we can test the converter against all currently provided Recipes. I will mostly spend the next time working on a Test Setup which will mostly work this way:

  • Install Symfony Skeleton
  • Install a Package (which install the package Yaml Recipe)
  • Write bin/console debug:config this_package into a variable
  • Run the Config Transformer to transfer yaml -> php array config
  • Check if bin/console debug:config this_package is same
  • Run convert of php array config -> php config builder
  • Check if bin/console debug:config this_package is same

This way and running it against all already existing packages should help us find all edge cases :)

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

No branches or pull requests

2 participants