php-cooper-laravel

LoadConfiguration extends LoadConfiguration
in package

Laravel's configuration, from CASC: bound in `bootstrap/app.php` in place of `Illuminate\Foundation\Bootstrap\LoadConfiguration` (see README.md), which both kernels resolve from the container.

What it reads

config/config.casc -- and whatever it imports -- instead of config/*.php, which are not read at all. Each top-level block is one configuration "file": database { connections.mysql.host = "..." } is config('database.connections.mysql.host'), as config/database.php was.

Underneath it, exactly as under the PHP files it replaces:

  • the framework's defaults (vendor/laravel/framework/config/), merged with Laravel's own rule -- a block replaces the default's top-level keys it sets, and database.connections, cache.stores, logging.channels and the other lists of named things are merged one level deeper, so a connection added keeps the default ones;
  • the packages' defaults, which their providers merge in later with mergeConfigFrom(), under whatever the document set.

Values arrive as plain PHP values (see ConfigValues): a byte size in bytes, a duration in milliseconds, an address as text, a secret revealed unless its block's cooper-secrets says otherwise.

The load

Every load has this integration's tags (see Tags): the path helpers, !php_const and !php. An application's own tag of the same name wins. COOPER_ENV -- which import "${COOPER_ENV}/*.casc" reads -- comes from the environment as LoadEnvironmentVariables left it, so Laravel's APP_ENV=local/testing/production read config/dev/, config/test/, config/prod/; php artisan --env=X counts as APP_ENV=X.

A missing document configures nothing beyond those defaults -- a fresh application has none yet, and php artisan cooper:init must be able to run. A document that does not load stops the boot with a ConfigError naming it.

config:cache

A cached configuration is used as Laravel uses it: this class only replaces how the files are read, so with bootstrap/cache/config.php present CASC is not read at all. php artisan config:cache caches what the document produced, !php results and path helpers as evaluated on the machine running it.

Table of Contents

Properties

$document  : string|null
$options  : array<string|int, mixed>

Methods

__construct()  : mixed
document()  : string
The document this loader reads, for `$app`.
loadOptions()  : array<string, mixed>
Cooper's options for a load of the document in `$app`: the application's own, this integration's tags under them, `.env` files from the environment path, `--env` as `APP_ENV`, and no in-memory cache.
loadConfigurationFiles()  : void
Fills `$repository` from the document, over the framework's defaults -- in place of Laravel's reading of `config/*.php`.
blocks()  : array<string|int, mixed>
The document's top-level blocks, as configuration values; none when there is no document.
overDefaults()  : array<string|int, mixed>
`$config` over the framework's `$defaults` for `$name`, by the rule Laravel applies to a `config/<name>.php` -- so moving a file into CASC changes nothing about what it overrides.

Properties

Methods

__construct()

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

Cooper's load options (resolvers, tags, modules, importSchemes, env, .env options); cache defaults to off

$document : string|null = null

the document's path; null for config/config.casc under the application's config path

document()

The document this loader reads, for `$app`.

public document(Application $app) : string
Parameters
$app : Application

the application

Tags
throws
LogicException

when $app is not Laravel's application

Return values
string —

an absolute path

loadOptions()

Cooper's options for a load of the document in `$app`: the application's own, this integration's tags under them, `.env` files from the environment path, `--env` as `APP_ENV`, and no in-memory cache.

public loadOptions(Application $app) : array<string, mixed>

The cache is off because it pays only where one process loads the document more than once, and Laravel's process loads it once -- per request, or once for a worker -- while config:cache is Laravel's own, better answer.

Parameters
$app : Application

the application the tags work for

Tags
throws
LogicException

when $app is not Laravel's application

Return values
array<string, mixed>

loadConfigurationFiles()

Fills `$repository` from the document, over the framework's defaults -- in place of Laravel's reading of `config/*.php`.

protected loadConfigurationFiles(Application $app, Repository $repository) : void
Parameters
$app : Application

the application being bootstrapped

$repository : Repository

its configuration

Tags
throws
ConfigError

when the document does not load, or a value cannot be converted

LogicException

when $app is not Laravel's application

blocks()

The document's top-level blocks, as configuration values; none when there is no document.

private blocks(Application $app) : array<string|int, mixed>
Parameters
$app : Application
Tags
throws
ConfigError
Return values
array<string|int, mixed>

overDefaults()

`$config` over the framework's `$defaults` for `$name`, by the rule Laravel applies to a `config/<name>.php` -- so moving a file into CASC changes nothing about what it overrides.

private overDefaults(string $name, array<string|int, mixed> $defaults, array<string|int, mixed> $config) : array<string|int, mixed>
Parameters
$name : string
$defaults : array<string|int, mixed>
$config : array<string|int, mixed>
Return values
array<string|int, mixed>
On this page

Search results