8000 [Dotenv] Add support for a magic __DIR__ variable by voronkovich · Pull Request #23742 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Dotenv] Add support for a magic __DIR__ variable #23742

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
wants to merge 1 commit into from
Closed

[Dotenv] Add support for a magic __DIR__ variable #23742

wants to merge 1 commit into from

Conversation

voronkovich
Copy link
Contributor
Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

In the Symfony demo application (see symfony/demo#617) we need to set an absolute path to a database, but we can't get it in the .env file. This PR adds support for a "magic" environment variable __DIR__ which can be used to get the absolute path in the current .env file.

Example:

# .env
DATABASE_URL="sqlite:///${__DIR__}/var/data/blog.sqlite"

@jvasseur
Copy link
Contributor
jvasseur commented Aug 1, 2017

The .env file should contain only valid bash syntax: you should be able to do source .env and get the environment variables set in your current shell. If we introduce custom syntax like this we lose this property.

@voronkovich
Copy link
Contributor Author

@jvasseur, This PR doesn't introduce a custom syntax. Try to run in your shell:

$ echo "sqlite:///${__DIR__}/var/data/blog.sqlite" # It will output '/var/data/blog.sqlite'

@jvasseur
8000 Copy link
Contributor
jvasseur commented Aug 1, 2017

@voronkovich if I run your command I get sqlite:////var/data/blog.sqlite (which is normal since __DIR__ doesn't exists it get replaced by an empty string).

The syntax is valid shell but since it calls an inexistent env variable this means the result will be different between source .env and (new Dotenv())->load('.env');

@javiereguiluz
Copy link
Member

@voronkovich thanks for trying to solve this issue. However, as @jvasseur said, our .env must be 100% compatible with Bash (that's the promise we made). So, let's try to fix the original issue, which is that somehow, relative paths are not working for defining the DATABASE_URL, which is clearly a bug because you need that when using SQLite. Thanks!

@voronkovich
Copy link
Contributor Author

Ok, let's close this PR :)

@voronkovich voronkovich closed this Aug 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0