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

after using this took, symfony is not finding my new php config files by default #37

Closed
arderyp opened this issue Feb 16, 2024 · 6 comments

Comments

@arderyp
Copy link

arderyp commented Feb 16, 2024

Symdony 5.4

config structure

config/
--services.php
--packages/
----a.php
----b.php
----...
--routes/
----...

behavior

service.php is imported here. But the code block above that handles importing config/packages/* only handles yaml files. Likewise with routing, despite the docblock indicating {yaml,php}.

I can import the files manually, by adding the following to my config/services.php, for example:

# config/services.php
$containerConfigurator->import('packages/*.php');

# config/routes.php
$routingConfigurator->import('routes/*.php');

Am I doing this right, or missing something? Does symfony not support these types of php config files out of the box?

I know you talk about adding loader logic in your blog post here, but I don't have any such extension and am not entirely sure where you are using this extension.

Thanks for yet another cool tool @TomasVotruba !

@arderyp
Copy link
Author

arderyp commented Feb 16, 2024

Adding those lines to services.php and routes.php seem to solve the issue of imports when running the app.

however, now my phpunit fails before running any tests with:

Symfony\Component\Config\Exception\LoaderLoadException: There is no extension able to load the configuration for "services" (in "/home/arderyp/repo/config/services.php"). Looked for namespace "services", found "api", "dama_doctrine_test", "doctrine", "doctrine_migrations", "sensio_framework_extra", "framework", "monolog", "security", "twig", "web_profiler", "webpack_encore" in /home/arderyp/repo/config/services.php (which is being imported from "/home/arderyp/repo/src/Kernel.php").

I'm still trying to figure this one out. It may be coming from the following in services.php:

    $services->alias(ContainerInterface::class, 'service_container');
    if ($containerConfigurator->env() === 'test') {
        $containerConfigurator->extension('services', [
            '_defaults' => [
                'public' => true,
            ],
        ]);
    }

EDIT

resolved by converting above to:

$services->alias(ContainerInterface::class, 'service_container');
    if ($containerConfigurator->env() === 'test') {
        $services->defaults()->public();
    }

@arderyp
Copy link
Author

arderyp commented Feb 17, 2024

nevermind, I see the a answer to my main question here: https://symfony.com/doc/5.x/configuration.html#configuration-formats

@TomasVotruba
Copy link
Member

I'm glad you've found the solution 👍

Yes, the Kernel needs to be updated as Symfony unfortunatelly hardcodes the config loading format.

It's in the section 3 of the post:
https://tomasvotruba.com/blog/2020/07/27/how-to-switch-from-yaml-xml-configs-to-php-today-with-migrify/

@arderyp
Copy link
Author

arderyp commented Feb 18, 2024

@TomasVotruba have you struggled with yaml config options that are straight up missing or unavaialle in PHP? I've run into at least three so far, all on the FirewallConfig, and I presume there are many more. Example: symfony/symfony#53987

@TomasVotruba
Copy link
Member

Not yet, as afaik the configs are generated from your current Symfony version.

@arderyp
Copy link
Author

arderyp commented Feb 18, 2024

my issue is confirmed and the fix is working for me :) symfony/symfony#53989

The bug is causing the generated cached config files to be incomplete

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

No branches or pull requests

2 participants