Configuration driver for CommonPHP that encodes and decodes YAML configuration data.
- PHP
^8.5 comphp/config:^0.3symfony/yaml:^8.0
Once this package is available through your Composer repositories, install it with:
composer require comphp/config-yaml<?php
use CommonPHP\Drivers\Config\YAML\YamlConfigurationDriver;
$driver = new YamlConfigurationDriver();
$config = [
'app' => 'demo',
'debug' => true,
'database' => [
'host' => 'localhost',
],
];
$yaml = $driver->encode($config);
$decoded = $driver->decode($yaml);
$driver->write(__DIR__ . '/config.yaml', $config);
$fromFile = $driver->read(__DIR__ . '/config.yaml');This driver uses Symfony YAML. YAML mappings decode to arrays, empty YAML decodes to an empty array, and scalar-only YAML is rejected as configuration data.
Read, write, parse, validation, and unsupported value failures throw CommonPHP config exceptions such as ConfigReadException, ConfigWriteException, ConfigValidationException, or ConfigException.
MIT. See LICENSE.md.