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

[TwigComponent] Configuration with PHP ConfigBuilders fails #1304

Closed
rarila opened this issue Nov 28, 2023 · 6 comments · Fixed by #1314
Closed

[TwigComponent] Configuration with PHP ConfigBuilders fails #1304

rarila opened this issue Nov 28, 2023 · 6 comments · Fixed by #1314

Comments

@rarila
Copy link

rarila commented Nov 28, 2023

I use configuration with PHP ConfigBuilders and tried to add configuration for symfony/ux. That failed, TwigComponentConfig could not be loaded.

So I was digging around (not knowing anything about it), comparing how others do it and finally found a working solution:

I created

ux/src/TwigComponent/src/DependencyInjection/Configuration.php

with content like this

class Configuration implements ConfigurationInterface
{
}

and then moved the getConfigTreeBuilder() method from

ux/src/TwigComponent/src/DependencyInjection/TwigComponentExtension.php

into that class.

I don’t know if this the correct way, if that would break anything else, but at least now TwigComponentConfig gets built and configuration works.

@smnandre
Copy link
Member

Normally, the TwigComponentConfig class is generated in your var/cache/dev/Symfony/Config directory... is that not the case ?

@rarila
Copy link
Author

rarila commented Nov 29, 2023

@smnandre It is. But clearing the cache crashes.

Just to be safe that not something else in my app is wrong, I just set up a clean v6.3 skeleton+webapp project and added ux-twig-component.

Then I replaced twig_component.yaml with twig_component.php

<?php

use Symfony\Config\TwigComponentConfig;

return static function (TwigComponentConfig $cnf): void {
};

Then I ran php bin/console cache:clear and ended up with:

[critical] Uncaught Error: Symfony\Component\Config\Builder\ConfigBuilderGenerator::build(): Argument #1 ($configuration) must be of type Symfony\Component\Config\Definition\ConfigurationInterface, null given, called in /foo/bar/vendor/symfony/dependency-injection/Loader/PhpFileLoader.php on line 195

@smnandre
Copy link
Member

Ok i see the problem and reproduced, thanks for the details :)

I'd like to have @weaverryan and @kbond inputs.. because we could either add a Configuration class as you suggested, or keep a single Extension class and move things a bit to implement ConfigurableExtension, but i'm not sure what is the best way forward ?

(i personnaly like the separated Configuration classes)

@smnandre
Copy link
Member

In the Extension, we just have to add this method and everything seems to work

// src/DependencyInjection/TwigComponentExtension.php

final class TwigComponentExtension extends Extension implements ConfigurationInterface
{

// ...

public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface
    {
        return $this;
    }

Can you confirm it works for you @rarila ?

@rarila
Copy link
Author

rarila commented Nov 29, 2023

@smnandre Works! 👍

Looks like I’m the only one using ConfigBuilders 😄

@smnandre
Copy link
Member

@rarila do you use other UX Packages ? 👼

You may be the only one... but you are a great beta-tester :)

@kbond kbond closed this as completed in bb32456 Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants