Skip to content

CompiledArtifact

Serializes a config handler’s declaration into the PHP file the on-disk cache holds.

A handler produces data; how that data is stored is the cache’s business, and this is the one place that turns it into source. The file is a header comment plus a single return <literal>;, so the only thing including it can ever do is hand back a value — and, unlike an eval()’d string, it is opcache-cacheable, so an unchanged config costs nothing to read again.

The single exception is a declaration holding a %env(...)% placeholder, where the literal is wrapped in one EnvPlaceholder::resolve() call so the environment is read at load rather than baked in at compile time — see CompiledArtifact::expression().

final class CompiledArtifact

Since4.0.0
SourceConfig/CompiledArtifact.php
MethodDescription
source(mixed $value, ?string $path = null, ?string $generatedBy = null): stringThe PHP source for a compiled configuration file.

public static function source(mixed $value, ?string $path = null, ?string $generatedBy = null): string

The PHP source for a compiled configuration file.

The handler class that compiled it, for the header comment.

ParameterTypeDescription
$valuemixedThe declaration the handler compiled.
$path?``stringThe configuration file it came from, for the header comment.
$generatedBy?``stringThe handler class that compiled it, for the header comment.

Returns string — PHP source that returns $value.

ThrowsWhen
CacheExceptionIf the declaration contains something no PHP literal can express.