Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Move loading .env files to bootstrap.php #491

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

Merged
1 commit merged into from
Nov 15, 2018
Merged

Move loading .env files to bootstrap.php #491

1 commit merged into from
Nov 15, 2018

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 12, 2018

Q A
License MIT

In #481, we completely forgot about apps that migrate to flex.
#481 relies on the Kernel being created at the same time as eg bin/console; but apps migrating to flex already have a Kernel, and it won't be updated automatically.

Here is a radically simpler approach: let's factorize loading .env files in a new bootstrap.php file that is used as instead of vendor/autoload.php to bootstrap the app.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link
Member Author

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self review for tomorrow :)

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Nov 13, 2018

PR tested locally, works like a charm. The critical feature this PR provides is decoupling recipes. As explained in the description, the current recipes are broken because they make too many assumptions.

Note that this PR introduces a new bootstrap.php file that should be used to setup both the autoload and load .env files.
In order to reduce duplication while still providing decoupling of recipes, this PR uses symbolic links to ship the bootstrap.php in several recipes.
Works transparently with the flex server.

PR ready. Votes pending.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

@nicolas-grekas nicolas-grekas dismissed fabpot’s stale review November 15, 2018 13:20

comments addressed

@ghost ghost merged commit 7ff5021 into symfony:master Nov 15, 2018
ghost pushed a commit that referenced this pull request Nov 15, 2018
@nicolas-grekas nicolas-grekas deleted the config-bootstrap branch November 15, 2018 13:20
@bendavies
Copy link
Contributor

for anyone running paratest, this will break your tests.
src/.bootstrap.php is loaded by paratest before <env name="APP_ENV" value="test" /> is read in phpunit.xml.dist, so the wrong .env files are read.

Still looking for a solution.

@nicolas-grekas
Copy link
Member Author

You need to define APP_ENV=test before running paratest.
Dunno how this can be achieved when using paratest.
A different bootstrap file would do it of course:

// tests/bootstrap.php
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = 'test');
require dirname(__DIR__).'/src/.bootstrap.php');

@bendavies
Copy link
Contributor

Yep - lovely, thankyou. Have submitted an issue to paratest.

@bendavies
Copy link
Contributor

bendavies commented Nov 22, 2018

@nicolas-grekas is there a bug in bin/console here?

These two should be equivalent, shouldn't they?

> APP_ENV=prod APP_DEBUG=0 bin/console cache:clear --no-warmup
> bin/console cache:clear --no-warmup --env=prod --no-debug

The 2nd will result in

Fatal error: Uncaught RuntimeException: The "APP_ENV" environment variable is not set to "prod". Please run "composer require symfony/dotenv" to load the ".env" files configuring the application. in project/src/.bootstrap.php on line 13

Edit:

Reproducer:

> composer create-project symfony/skeleton skeleton 
> cd skeleton
> rm -rf vendor
> composer install --no-dev #error will be here too.
> bin/console cache:clear --no-warmup --env=prod --no-debug

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.