Skip to content

v2.5.0

Choose a tag to compare

@ttsuru ttsuru released this 16 Oct 07:25
· 15 commits to 2.x since this release
v2.5.0
11f0287

Important

The .env files are now loaded as in Symfony, with symfony/dotenv, and only from config/. Applications created from an earlier skeleton keep working until they update config/core.php; see the migration steps below.

.env files loaded as in Symfony (PR #34)

  • config/core.php loads the .env files with one line, (new Dotenv())->usePutenv()->bootEnv(CONFIG . '.env') (symfony/dotenv), instead of josegonzalez/dotenv.
  • Files, all in config/, merged in this order (a later file wins, real environment variables win over all files):
    • config/.env: committed defaults of the application (APP_ENV=dev)
    • config/.env.local: values of one machine and secrets (ignored by Git; not loaded when APP_ENV=test)
    • config/.env.{APP_ENV}, e.g. config/.env.test: committed values of an environment
    • config/.env.{APP_ENV}.local: values of one machine for that environment (ignored by Git)
  • The root .env is no longer read, and config/.env.example is gone: config/.env itself is committed with the defaults. .gitignore ignores only config/.env.local, config/.env.local.php and config/.env.*.local.
  • APP_ENV comes from the real environment, else from the files, and defaults to dev. vendor/bin/phpunit, bin/cake test and webroot/test.php run with APP_ENV=test.
  • DEBUG defaults to 0 when APP_ENV=prod and to 2 otherwise; an explicit DEBUG wins. In production, set APP_ENV=prod.
  • config/.env.test holds only what the tests change (DATABASE_URL, MAILER_DSN).
  • Real environment variables now also win in the web server of the End-to-End tests (pieceofcake2/panther): the previous loader could write a .env value into $_ENV next to a different real value.

Dependencies

  • New: symfony/dotenv ^5.4 || ^6.4 || ^7.0 || ^8.0 (PHP 8.0 gets 5.4; symfony/dotenv 8 needs PHP 8.4.1). Removed: josegonzalez/dotenv.
  • Requires pieceofcake2/cakephp ^2.12.7 (unchanged). Dev: pieceofcake2/phpstan-cakephp2 ^1.0.

Migrating from an earlier skeleton

  1. composer remove josegonzalez/dotenv and composer require symfony/dotenv.
  2. Replace the .env loading at the top of config/core.php with:
    use Symfony\Component\Dotenv\Dotenv;
    
    (new Dotenv())->usePutenv()->bootEnv(CONFIG . '.env');
    and the debug line with Configure::write('debug', env('DEBUG') ?? (env('APP_DEBUG') ? 2 : 0));.
  3. Move a root .env to config/. Commit config/.env with the defaults and APP_ENV=dev, and move the values of your machine and the secrets to config/.env.local.
  4. Keep only what the tests change in config/.env.test, and only what differs on your machine in config/.env.test.local (the files are merged now).
  5. In .gitignore, ignore /config/.env.local, /config/.env.local.php and /config/.env.*.local instead of config/.env and the root .env files.
  6. In production, set APP_ENV=prod and the other settings as real environment variables.

See Environment Variables in the documentation.

Installation

composer create-project pieceofcake2/app my_app

Full Changelog: v2.4.3...v2.5.0