php-cooper-laravel

LoadEnvironmentVariables extends LoadEnvironmentVariables
in package

Laravel's `.env` loading, done by Cooper: bound in `bootstrap/app.php` in place of `Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables` (see README.md), which both kernels resolve from the container.

Cooper's Dotenv::export() puts what the files say into the process environment, so env(), $_ENV, $_SERVER and getenv() -- which Laravel and its packages read -- find it. That is the only reason it is exported: the CASC document reads the same files by itself. One loader, one set of rules, so the two never disagree:

  1. .env
  2. .env.<COOPER_ENV> -- .env.dev, .env.test, .env.prod; COOPER_ENV falls back to APP_ENV, local read as dev, testing as test, production as prod;
  3. .env.local;
  4. the real environment, which always wins: a variable it already has is never overwritten.

php artisan --env=X counts as APP_ENV=X (see NamedEnvironment). The files are read from $app->environmentPath(). A cached configuration reads none, as in Laravel.

Table of Contents

Properties

$options  : array<string|int, mixed>

Methods

__construct()  : mixed
bootstrap()  : void
Exports the `.env` files, unless the configuration is cached.

Properties

Methods

__construct()

public __construct([array<string, mixed> $options = [] ]) : mixed
Parameters
$options : array<string, mixed> = []

Cooper's .env options (dotenv, dotenvEnv, dotenvFiles, dotenvDir, dotenvOverride, env); give LoadConfiguration the same ones

bootstrap()

Exports the `.env` files, unless the configuration is cached.

public bootstrap(Application $app) : void
Parameters
$app : Application

the application being bootstrapped

Tags
throws
CooperError

(stage dotenv) on a malformed .env file

LogicException

when $app is not Laravel's application

On this page

Search results