php-cooper-symfony

CooperRuntime extends SymfonyRuntime
in package

Symfony's runtime, with Cooper reading the `.env` files: named in the application's `composer.json` as `extra.runtime.class`.

Before the kernel exists, Cooper's Dotenv::export() puts what the .env files say into the process environment -- .env, .env.<COOPER_ENV>, .env.local, from the project directory, never over a variable the real environment already has -- so %env(...)% placeholders, $_SERVER['APP_DEBUG'] and anything else reading the environment find it. Symfony's own .env loading is always off: two loaders with two sets of rules would disagree about which file wins.

The environment's name

Symfony's environments are Cooper's: dev, test, prod. Whichever is named first decides both:

  1. the runtime's env option, or --env/-e on the command line -- Cooper reads that environment's .env.<env>;
  2. a real APP_ENV or COOPER_ENV -- Cooper's fallback reads APP_ENV when COOPER_ENV is unset;
  3. COOPER_ENV or APP_ENV from the .env files;
  4. dev.

APP_ENV, when nothing set it, is set to the COOPER_ENV so found. APP_DEBUG is read as Symfony reads it, from wherever it now is -- the real environment or a .env file -- and is on outside prod when neither sets it.

Every other option is Symfony's own (project_dir, prod_envs, env_var_name, debug_var_name, ...); dotenv_path, dotenv_overload and dotenv_extra_paths mean nothing here -- Cooper's .env layering is fixed (see JOetjen\Cooper\Dotenv).

Table of Contents

Methods

__construct()  : mixed
inEnvironment()  : bool
Whether `$name` is set in the process environment, where Symfony looks for it.
namedEnvironment()  : string|null
The environment the runtime is told to run, before any variable is consulted: its `env` option, else `--env`/`-e` on a command line -- the two places Symfony's runtime itself looks first.

Methods

__construct()

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

Symfony's runtime options; disable_dotenv is always set

Tags
throws
CooperError

(stage dotenv) on a malformed .env file

inEnvironment()

Whether `$name` is set in the process environment, where Symfony looks for it.

private static inEnvironment(string $name) : bool
Parameters
$name : string
Return values
bool

namedEnvironment()

The environment the runtime is told to run, before any variable is consulted: its `env` option, else `--env`/`-e` on a command line -- the two places Symfony's runtime itself looks first.

private static namedEnvironment(array<string, mixed> $options) : string|null
Parameters
$options : array<string, mixed>
Return values
string|null
On this page

Search results