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

[DotEnv] Cannot pass .env parameters in bundles config #39625

Closed
much-rebel opened this issue Dec 24, 2020 · 4 comments
Closed

[DotEnv] Cannot pass .env parameters in bundles config #39625

much-rebel opened this issue Dec 24, 2020 · 4 comments

Comments

@much-rebel
Copy link

Symfony version(s) affected: 4/5

Description
Anytime I try pass .env variables to bundle configs I get some sort of hashed values, f.e. for APP_LOCALE=en_US in the DI Extension class the value would be something like env_a47b1458111e54d0_APP_LOCALE_21afb7caede432771a62c6afa3f24e39. Which makes some bundles incompatible with environment dependant apps.

How to reproduce

  1. Install fresh version of symfony plus add doctrine phpcr bundle (execute recipe)
$: symfony new 5
$: cd 5
5$: composer.phar require doctrine/phpcr-bundle
  1. Replace .env with:
APP_ENV=dev
APP_SECRET=a7ea38db584af1423a361cb69a246f42
DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
PHPCR_USER=admin
PHPCR_PASSWORD=admin
PHPCR_WORKSPACE=default
APP_LOCALE=en_US
APP_LOCALES_OBJ="{\"en_US\":{}}"
  1. Replace config/packages/doctrine_phpcr.yaml with:
doctrine_phpcr:
    session:
        backend:
            type: jackrabbit
            url: 'localhost'
        workspace: '%env(PHPCR_WORKSPACE)%'
        username: '%env(PHPCR_USER)%'
        password: '%env(PHPCR_PASSWORD)%'

    odm:
        auto_mapping: true
        auto_generate_proxy_classes: false
        locales: '%env(json:APP_LOCALES_OBJ)%'
        locale_fallback: hardcoded
        default_locale: '%env(string:APP_LOCALE)%'
  1. Try access console:
5$: php bin/consle -vv

which will omit exception:

In DoctrinePHPCRExtension.php line 394:
                                                    
  [ErrorException]                                  
  Warning: Invalid argument supplied for foreach()  
                                                    

Exception trace:
  at ./5/vendor/doctrine/phpcr-bundle/src/DependencyInjection/DoctrinePHPCRExtension.php:394

if to add dd($config['locales']); before line 394 in DoctrinePHPCRExtension.php the output would be:

env_559c9450e41e23c7_json_APP_LOCALES_OBJ_1c159ebab1052f51822d2f70b32fa4e1

instead of array.

If using the same approach, but in parameters (add parameter locales: '%env(json:APP_LOCALES_OBJ)%' in services.yaml) and access it via container somewhere in the service like $this->container->getParameter('locales'); it will have a valid array value.

Possible solution
Don't know one, maybe it is supposed to be like that? But it seems to be quite a big limitation.

@much-rebel much-rebel changed the title Cannot pass .env parameters in bundles config [.env] Cannot pass .env parameters in bundles config Dec 24, 2020
@much-rebel much-rebel changed the title [.env] Cannot pass .env parameters in bundles config [DotEnv] Cannot pass .env parameters in bundles config Dec 24, 2020
@derrabus
Copy link
Member

I think, you should report this problem to https://github.com/doctrine/DoctrinePHPCRBundle instead.

@xabbuh xabbuh added the Dotenv label Dec 25, 2020
@much-rebel
Copy link
Author

This is not related to any specific bundle, I've used DoctrinePHPCRBundle only for illustrative purpose. Any bundle would fail the same way if dotenv parameters would be used.

@derrabus
Copy link
Member

derrabus commented Dec 26, 2020

The problem is that the extension reads and evaluates a setting (doctrine_phpcr.odm.locales) from the configuration without resolving env placeholders. This means that the bundle does not support env variables for this specific setting. This is indeed something that has to be fixed in the bundle, if configuring this setting via env vars is desirable at all.

@fabpot
Copy link
Member

fabpot commented Dec 28, 2020

Closing as not a bug in Symfony.

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

4 participants