Skip to content

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

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

Closed
Neirda24 opened this issue Oct 29, 2019 · 10 comments
Closed

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

Neirda24 opened this issue Oct 29, 2019 · 10 comments
Labels
Dotenv Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed) Stalled

Comments

@Neirda24
Copy link
Contributor

Neirda24 commented Oct 29, 2019

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 ?

@graftak
Copy link

graftak commented Oct 29, 2019

Yesterday I actually tried $container->getEnv('MY_ENV_VARIABLE') because I thought it would likely exist already. I think this would be a good idea but I'm not too familiar yet with the nuances of the differences with parameters etc.

@javiereguiluz javiereguiluz added Dotenv Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed) labels Oct 29, 2019
@ro0NL
Copy link
Contributor

ro0NL commented Oct 29, 2019

at this point, isnt using getenv() and do some casting in PHP sufficient?

maybe related to #33758

im a bit skeptical about making DI responsible for env var management (and e.g extract it standalone), so outside DI context it's just PHP, thus getenv()

@Neirda24
Copy link
Contributor Author

I think it is related. Like said in the linked issue, it would be nice to have access to processors.

Although I don't understand what you mean by making DI responsible for env var management as far as I know it is the case today and the source of my problem.

@ro0NL
Copy link
Contributor

ro0NL commented Nov 2, 2019

@Neirda24 ha, i meant not making DI responsible :) currently it's an implementation detail, which IMHO is a bit hard to abstract and separate. Just to have a better version of (int) getenv('INT_ISH')

the current architecture fits the DI component mostly.

@ro0NL
Copy link
Contributor

ro0NL commented Nov 2, 2019

hm actually it's only matter of changing the current visibility to solve your issue;

https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/DependencyInjection/Container.php#L389

the [DotEnv] part confused me (e.g. to separate all the logic)... not sure there's any technical blocker here... perhaps try and PR :)

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@falkenhawk
Copy link

Yes.

@carsonbot carsonbot removed the Stalled label Dec 18, 2020
@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@carsonbot
Copy link

Friendly ping? Should this still be open? I will close if I don't hear anything.

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dotenv Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed) Stalled
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants