Skip to content

[RFC][Dotenv] Add a way to retrieve env vars not only via DI #34173

Closed
@Neirda24

Description

@Neirda24

Description
Inspired by this: #25693
I understand that your application should not be aware of where your configuration come from. However at some point you had to configure it using env variables.
What I was thinking is being able to access env Variables through the container when it is booted.

Sometimes we need to configure a static property of a non service class that will depend on the OS (it might be because of bad design or whatever but still it happens).

Example

// ./src/Kernel.php
public function boot()
{
    parent::boot();

    // NOT WORKING AS IT RETURNS THE DEFAULT VALUE
    MyClass::$staticProperty = $this->getContainer()->getParameter('env(MY_ENV_VARIABLE)');
}

would be nice if we had something like

// ./src/Kernel.php
public function boot()
{
    parent::boot();

    // PROTECTED PROPERTY AS OF TODAY
    MyClass::$staticProperty = $this->getContainer()->getEnv('MY_ENV_VARIABLE');
}

or event just resolve env in the getParameter method.

I don't know if the need is clear enough. Please do not hesitate to tell me otherwise.

WDYT ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DotenvFeatureRFCRFC = Request For Comments (proposals about features that you want to be discussed)Stalled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions