CascFileLoader
extends FileLoader
in package
Loads a CASC document into a container: the Config component loader for `.casc` files, which `CooperKernelTrait` registers.
What the document configures
Each top-level block but one is a bundle's configuration, by the
bundle's extension alias -- framework { secret = ${APP_SECRET} } is
what framework: { secret: '%env(APP_SECRET)%' } was in
config/packages/framework.yaml -- handed to the bundle as one
configuration array, which its own configuration tree validates as
always. The one exception, parameters { ... }, sets container
parameters: each leaf by its dotted path (app.locales = [...] is the
parameter app.locales), a list being a leaf. Services are not
CASC's: config/services.yaml and attributes wire them as before.
When things are read
A ${NAME} written as a value becomes Symfony's %env(...)%
placeholder (see EnvPlaceholders), read whenever the container is
used. Everything else resolves now, at build, as Cooper resolves it:
imports, ${?NAME} guards, keys, @{...}, %{...}, tags, literals.
COOPER_ENV is the kernel's environment -- the container is built for
that one, whatever the process environment says -- so import "${COOPER_ENV}/*.casc" reads the overlay of the environment being
built.
A %name% in a string is Symfony's parameter syntax, as in YAML:
written in the document, it is resolved by Symfony (%% for a
literal %).
Freshness
Every file the load read, every glob import's expansion and every
environment variable read at build become container resources, so a
debug container is rebuilt when a CASC file is changed, added where a
glob looks, or deleted, or such a variable changes. A missing
document configures nothing -- a new application has none yet, and
bin/console cooper:init needs a container to run -- and is watched
for appearing.
Table of Contents
Constants
- PARAMETERS : mixed = 'parameters'
- The top-level block holding container parameters rather than a bundle's configuration.
- DOTENV_OPTIONS : mixed = ['env', 'dotenv', 'dotenvEnv', 'dotenvFiles', '...
- The options that shape the environment, kept with the env resource to build it again.
Properties
- $options : array<string|int, mixed>
Methods
- __construct() : mixed
- load() : null
- Loads the document at `$resource` into the container.
- supports() : bool
- apply() : void
- One top-level entry: the parameters, or a bundle's configuration.
- flatten() : array<string, mixed>
- Parameters by dotted path: a block's leaves, a list (or an empty block) being one.
- isAbsolute() : bool
- loadOptions() : array<string, mixed>
- Cooper's options for this load: the application's, with the kernel's environment as `COOPER_ENV` (an explicit `env` entry for it still wins), `.env` files read from the project, no cache of Cooper's own (the container is the cache), and `${NAME}` kept a placeholder.
- locate() : string|null
- The document's path, or `null` -- and a resource watching for it -- when an absolute path names no file. Anything else (a relative or `@Bundle` path) is the locator's to find, and to report.
- track() : void
- Every file, glob expansion and variable the load depended on, as the container's resources.
Constants
PARAMETERS
The top-level block holding container parameters rather than a bundle's configuration.
public
mixed
PARAMETERS
= 'parameters'
DOTENV_OPTIONS
The options that shape the environment, kept with the env resource to build it again.
private
mixed
DOTENV_OPTIONS
= ['env', 'dotenv', 'dotenvEnv', 'dotenvFiles', 'dotenvDir', 'dotenvOverride']
Properties
$options read-only
private
array<string|int, mixed>
$options
= []
Methods
__construct()
public
__construct(ContainerBuilder $container, FileLocatorInterface $locator[, string|null $env = null ][, array<string, mixed> $options = [] ]) : mixed
Parameters
- $container : ContainerBuilder
-
the container being built
- $locator : FileLocatorInterface
-
finds a document given by a relative or
@Bundlepath - $env : string|null = null
-
the kernel's environment,
COOPER_ENVfor the load - $options : array<string, mixed> = []
-
Cooper's load options (
resolvers,tags,modules,.envoptions, ...);cacheandenvValueare this loader's
load()
Loads the document at `$resource` into the container.
public
load(mixed $resource[, string|null $type = null ]) : null
Parameters
- $resource : mixed
-
the document's path
- $type : string|null = null
-
casc, ornullto go by the extension
Tags
Return values
nullsupports()
public
supports(mixed $resource[, string|null $type = null ]) : bool
Parameters
- $resource : mixed
-
the resource
- $type : string|null = null
-
the type the import asked for, if any
Return values
bool —whether $resource is a CASC document
apply()
One top-level entry: the parameters, or a bundle's configuration.
private
apply(string $key, mixed $value, string $path) : void
Parameters
- $key : string
- $value : mixed
- $path : string
Tags
flatten()
Parameters by dotted path: a block's leaves, a list (or an empty block) being one.
private
static flatten(array<string|int, mixed> $block, string $prefix) : array<string, mixed>
Parameters
- $block : array<string|int, mixed>
- $prefix : string
Return values
array<string, mixed>isAbsolute()
private
static isAbsolute(string $path) : bool
Parameters
- $path : string
Return values
boolloadOptions()
Cooper's options for this load: the application's, with the kernel's environment as `COOPER_ENV` (an explicit `env` entry for it still wins), `.env` files read from the project, no cache of Cooper's own (the container is the cache), and `${NAME}` kept a placeholder.
private
loadOptions(EnvPlaceholders $placeholders) : array<string, mixed>
Parameters
- $placeholders : EnvPlaceholders
Return values
array<string, mixed>locate()
The document's path, or `null` -- and a resource watching for it -- when an absolute path names no file. Anything else (a relative or `@Bundle` path) is the locator's to find, and to report.
private
locate(string $resource) : string|null
Parameters
- $resource : string
Return values
string|nulltrack()
Every file, glob expansion and variable the load depended on, as the container's resources.
private
track(LoadTrace $trace, array<string, mixed> $options) : void
Parameters
- $trace : LoadTrace
- $options : array<string, mixed>