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

Allow referencing env variables in project config #1918

Closed
marcospassos opened this issue Feb 21, 2019 · 14 comments
Closed

Allow referencing env variables in project config #1918

marcospassos opened this issue Feb 21, 2019 · 14 comments

Comments

@marcospassos
Copy link

For CI environment, it would be nice to have an option to specify the temporary directory when running PHPStan. Currently, it can only be configured through the configuration file.

@ondrejmirtes
Copy link
Member

Yes, and why is that not sufficient? :)

@marcospassos
Copy link
Author

Because the CI server requires a specific cache directory.

@ondrejmirtes
Copy link
Member

You can make a local phpstan.neon file and put the versioned one into includes section. Like I do for example here: https://github.com/phpstan/phpstan/blob/master/conf/config.level2.neon#L1-L2

It's a pretty common practice that allows you to override project configuration with local machine's specific settings.

@marcospassos
Copy link
Author

marcospassos commented Feb 21, 2019

@ondrejmirtes the path to the cache is acessed via an environment variable.

@ondrejmirtes
Copy link
Member

We could change this feature request to "make environment variables accessible in the neon config".

@marcospassos
Copy link
Author

it's ok for me, but why passing it as an argument is a problem?

@ondrejmirtes
Copy link
Member

I don't want to overload it with too many options, I allowed the paths and level to be in both CLI options and in the neon config with screeching teeth :) I don't want to do it for everything.

@marcospassos
Copy link
Author

I understand your point, but allowing it as an option would be much more flexible IMHO.

@ondrejmirtes
Copy link
Member

I think that my suggestion will make everything much more flexible :) BTW right now you could generate .neon config based on your env variable and use that. I do a similar thing right here: https://github.com/phpstan/phpstan/blob/master/build.xml#L193-L223

@ondrejmirtes ondrejmirtes changed the title Add CLI option for specifying temporary directory Allow referencing env variables in project config Feb 26, 2019
@tbmatuka
Copy link

@ondrejmirtes I figured I could do a PR for this because I might need it, but I do have a couple of questions:

  1. Do you have any preference for how the variables should be named? Do you want to namespace them like env: or something like that?
  2. It looks to me like the only thing needed to make this work is to add the variables as parameters in DependencyInjection\LoaderFactory. Is that it, or am I missing anything?

@ondrejmirtes
Copy link
Member

@tbmatuka Adding it to LoaderFactory would help you to only reference it in includes section. To be able to reference them in parameters section, you should add it to ContainerFactory::create() - there's call to $configurator->addParameters where it should be added. The environment variables should be in env array, so they can be referenced with %env.foo%.

@ondrejmirtes
Copy link
Member

This is now as simple as phpstan/phpstan-src#2559 but it's blocked by nette/di#291.

Most of the work was unblocked by phpstan/phpstan-src#2558

@ondrejmirtes
Copy link
Member

Implemented: phpstan/phpstan-src#2559

@github-actions
Copy link

github-actions bot commented Oct 1, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants