Skip to content

FormatDriverRegistry

Maps a config file’s extension to the FormatDriver that understands it, and is itself the thing parent/imports references are resolved through — so a PHP-array config can have a YAML parent, a YAML config can import an XML-derived one, etc.

A registry is scoped to one config type (settings, factories, …), not global: which canonical array shape a .xml file resolves to depends entirely on which IArrayConfigHandler its XmlFormatDriver is bound to (see forHandler()). Mixing driver sets across config types would silently produce the wrong shape for whichever type didn’t match.

final class FormatDriverRegistry

Since1.0.0
SourceConfig/Format/FormatDriverRegistry.php

public function __construct(array<FormatDriverInterface> $drivers = []): mixed

Checked in the given order; the first whose supports() matches wins. Pass PHP-array before YAML before XML to get the priority order used for extension-agnostic discovery (see locate()).

ParameterTypeDescription
$driversarray``<FormatDriverInterface>Checked in the given order; the first whose supports() matches wins. Pass PHP-array before YAML before XML to get the priority order used for extension-agnostic discovery (see locate()).

Returns mixed

MethodDescription
forHandler(IArrayConfigHandler&IXmlConfigHandler $handler, array<string> $transformations = [], array<string, mixed> $validations = []): FormatDriverRegistryConvenience assembly for the common case: PHP array + YAML + XML, all producing the canonical array shape $handler defines, in the priority order extension-agnostic discovery uses (PHP > YAML > XML).
load(string $path, ?string $environment, ?string $context = null): array<string, mixed>
[`locate(string $basePathWithoutExtension): stringnull`](#locate)
register(FormatDriverInterface $driver): voidAppends a driver to the end of the resolution order.
resolve(string $path): FormatDriverInterfaceReturns the first registered driver that claims the given path.

public static function forHandler(IArrayConfigHandler&IXmlConfigHandler $handler, array<string> $transformations = [], array<string, mixed> $validations = []): FormatDriverRegistry

Convenience assembly for the common case: PHP array + YAML + XML, all producing the canonical array shape $handler defines, in the priority order extension-agnostic discovery uses (PHP > YAML > XML).

The handler’s declared XSD / RelaxNG / Schematron validations, forwarded to the XmlFormatDriver so XML resolved through this registry (including via parent/imports) is validated against its schemas exactly like a primary XML file; ignored by the PHP/YAML drivers.

ParameterTypeDescription
$handlerIArrayConfigHandler&IXmlConfigHandler
$transformationsarray``<``string``>XSL stylesheets applied to the XML path only (see XmlFormatDriver); irrelevant to PHP/YAML.
$validationsarray``<``string``, ``mixed``>The handler’s declared XSD / RelaxNG / Schematron validations, forwarded to the XmlFormatDriver so XML resolved through this registry (including via parent/imports) is validated against its schemas exactly like a primary XML file; ignored by the PHP/YAML drivers.

Returns FormatDriverRegistry

public function load(string $path, ?string $environment, ?string $context = null): array<string, mixed>

ParameterTypeDescription
$pathstring
$environment?``string
$context?``string

Returns array``<``string``, ``mixed``>

public function locate(string $basePathWithoutExtension): string|null

Extension-agnostic handler discovery: given a base path with no extension (e.g.

“%core.config_dir%/settings”), returns the first candidate that exists on disk, checked in registration order (PHP > YAML > XML by convention — see forHandler()). An explicit extension in the caller’s own pattern should bypass this entirely and be used as-is; this is only for the extension-less case.

ParameterTypeDescription
$basePathWithoutExtensionstring

Returns string``|``null — The resolved, existing path, or null if none of the candidate extensions exist.

public function register(FormatDriverInterface $driver): void

Appends a driver to the end of the resolution order.

Order matters: FormatDriverRegistry::resolve() returns the first driver whose supports() matches, and FormatDriverRegistry::locate() probes extensions in the same order. A driver that resolves nested parent/imports references is handed this registry, so those references can cross formats.

ParameterTypeDescription
$driverFormatDriverInterface

public function resolve(string $path): FormatDriverInterface

Returns the first registered driver that claims the given path.

Drivers are asked in registration order, so an earlier registration wins a tie.

ParameterTypeDescription
$pathstring

Returns FormatDriverInterface

ThrowsWhen
ConfigurationExceptionif no registered driver supports the path.