A lightweight, type-safe configuration wrapper for Symfony applications. It provides dot-notation access to validated configuration values with runtime type assertions.
Symfony's parameter bag returns mixed values without type guarantees. Accessing nested configuration requires verbose array key handling and manual type checks scattered across the codebase.
Configuration wraps a single validated parameter array (dazzhub) and exposes it through a clean API with dot-notation paths and ConfigValueType assertions.
| File | Purpose |
|---|---|
Configuration.php |
Read-only service with has(), get(), and all() methods |
ConfigValueType.php |
Backed enum for type assertions (STRING, INT, FLOAT, BOOL, ARRAY) |
dazzhub_preferences.yaml |
Configuration values under the dazzhub parameter |
services.yaml |
Imports the preferences file |
// Injected via autowiring — no manual setup needed
public function __construct(
private readonly Configuration $config,
) {}
// Read a string (default type)
$model = $this->config->get('assessment.options.model');
// Read with explicit type assertion
$temp = $this->config->get('assessment.options.temperature', ConfigValueType::FLOAT);
// Check existence
if ($this->config->has('assessment.options.temperature')) { /* ... */ }
// With default value
$timeout = $this->config->get('http.timeout', ConfigValueType::INT, 30);
// Get everything
$all = $this->config->all();- The
dazzhubparameter is injected via#[Autowire(param: 'dazzhub')]. - Dot-notation paths (e.g.
a.b.c) are converted to Symfony PropertyAccess syntax ([a][b][c]). get()asserts the retrieved value matches the expectedConfigValueTypeusingwebmozart/assert. If the path doesn't exist and no default was provided, anOutOfBoundsExceptionis thrown.
- PHP 8.2+
- Symfony 7.x (
symfony/property-access,symfony/dependency-injection) webmozart/assert
Define your values in dazzhub_preferences.yaml:
parameters:
dazzhub:
pi: 3.14
assessment:
options:
model: "gpt-4"
temperature: 0.7Import it in services.yaml:
imports:
- { resource: dazzhub_preferences.yaml }The Configuration service is auto-registered via Symfony's autowiring — no additional service definition required.