Skip to content

Pre-release 4.2.126 → 4.2.125 — task 4.5 (config): .env files load with v13's LoadEnvironmentVariables - #99

Merged
agissept merged 1 commit into
masterfrom
pre-release/4.2.126
Oct 6, 2026
Merged

agissept merged 1 commit into
masterfrom
pre-release/4.2.126

Conversation

@oonid

@oonid oonid commented Oct 1, 2026 •

Copy link
Copy Markdown

Task 4.5, config — .env files load with v13's LoadEnvironmentVariables

Stacks on #98. This is the third config slice. v13 reads the environment from a dotenv .env file. The fork read only the L4.2 .env.{env}.php arrays. The start script now loads .env first with v13's LoadEnvironmentVariables and vlucas/phpdotenv, then the .env.{env}.php file as before. That file still wins on the keys both define, so an application with no .env file sees no change. Environment files can then move to .env one deployment at a time, before the APP_ENV slice drops the hostname map.

Changes

  • Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables uses v13's name and file selection:

    • It reads .env from environmentPath(), the base path by default.
    • It reads .env.{env} instead when the console's --env option or the APP_ENV variable names an environment that has its own file.
    • Variables already in the process environment are kept: v13's Env repository is immutable.
    • A missing file loads nothing.
    • The config cache check and the invalid-file message are left out. They come with the flip.
  • The start script runs it just before the .env.{env}.php file loads, so the PHP file's values win on shared keys.

  • Application gains v13's environmentPath(), useEnvironmentPath(), loadEnvironmentFrom(), environmentFile() and environmentFilePath().

  • vlucas/phpdotenv ^5.6.1 becomes a requirement. It is what v13's Env class and the env() helper in illuminate/support need, so env() now works too.

  • Tests: a new FoundationLoadEnvironmentVariablesTest (7 tests) checks that:

    • .env loads into getenv(), $_ENV, $_SERVER and env();
    • --env and APP_ENV each pick .env.{env};
    • an environment without its own file falls back to .env;
    • variables already in the environment are kept;
    • a missing .env loads nothing;
    • useEnvironmentPath() moves where .env is read from.

    FoundationApplicationBuilderTest checks that the start script loads .env and that .env.testing.php wins on a shared key.

What changes

  • An invalid .env stops the app. phpdotenv rejects lines such as KEY=a b, and the start script lets its InvalidFileException through. In the dicoding app, artisan exits 255 with the message and a stack trace, and HTTP requests get a 500 with an empty body and the message in the server log. v13 prints "The environment file is invalid!" and exits 1. phpdotenv doesn't reject an unterminated quote such as KEY="abc; that line loads nothing.

Verification

  • Fork: the suite is 286 green on PHPUnit 11.5.56. The ratchet is green, with every pattern at its baseline.
  • The tests catch real breaks. Each of these 6 mutations fails at least one test:
    • the start script not loading .env;
    • --env ignored;
    • APP_ENV ignored;
    • a missing .env.{env} not checked;
    • useEnvironmentPath() ignored;
    • dotenv never loading.
  • Downstream: the dicoding app pair is dicoding-dev/dicoding#6003 (feature/platform/framework-4.2.126-rc1). It pins this release, and its lock gains vlucas/phpdotenv and its two dependencies. It ran with vendor installed from its lock, apart from the dev CLIs phpstan/phpstan and rector/rector, whose GitHub downloads are refused in this container:
    • config()->all() is byte-identical to 4.2.125 in production, local, testing and endtoend.
    • .env loading, probed by booting the app's console kernel: a valid .env reaches env() and getenv(), and none leaves them empty.
    • Psalm (full project, no cache): no errors.
    • Unit suite: 8964 green.
    • Integration suite: all 3023 tests. The only failures are the 4 long-standing ones. 191 are skipped and 5 incomplete, and no test is flagged risky.
    • The real entry points (php -S + server.php → index.php, and 7 artisan commands) and the 13 in-process request scenarios are identical to 4.2.125.
  • Checks ran in a cloud container without deck (PHP 8.4.26, MariaDB 10.11).

Tag

There's no 4.2.126 tag, as there are none for 4.2.119–4.2.125: tag pushes are refused for this session. The app pins the pre-release/4.2.126 branch (84d2f6ac).

🤖 Generated with Claude Code

https://claude.ai/code/session_0169SsatCE8LhaTsQTPiGtVo

@agissept
agissept force-pushed the pre-release/4.2.126 branch from 84d2f6a to a04aefa Compare October 2, 2026 09:20
@agissept
agissept added this pull request to stack #102 October 5, 2026 06:14
@agissept
agissept force-pushed the pre-release/4.2.126 branch 6 times, most recently from 4b64173 to 4dfedc8 Compare October 6, 2026 06:09
Base automatically changed from pre-release/4.2.125 to master October 6, 2026 06:09
@agissept
agissept marked this pull request as ready for review October 6, 2026 06:15
… (task 4.5)

The start script loads the application's .env file with v13's
LoadEnvironmentVariables bootstrapper and vlucas/phpdotenv, before the L4.2
.env.{env}.php file:

- .env is read from the base path, or .env.{env} when --env or APP_ENV names
  an environment that has its own file, as in v13. Variables already in the
  process environment are kept.
- The .env.{env}.php file still loads afterwards and wins on the keys both
  files define, so applications without a .env file see no change.
- Application gains v13's environmentPath(), useEnvironmentPath(),
  loadEnvironmentFrom(), environmentFile() and environmentFilePath().
- vlucas/phpdotenv becomes a requirement. It also makes illuminate/support's
  env() helper usable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0169SsatCE8LhaTsQTPiGtVo
@agissept
agissept force-pushed the pre-release/4.2.126 branch from 4dfedc8 to 33008e9 Compare October 6, 2026 06:16
@agissept
agissept merged commit 11b71a9 into master Oct 6, 2026
2 checks passed
@agissept
agissept deleted the pre-release/4.2.126 branch October 6, 2026 07:18
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.

3 participants