comphp/config-yaml provides CommonPHP\Drivers\Config\YAML\YamlConfigurationDriver for YAML configuration files.
use CommonPHP\Drivers\Config\YAML\YamlConfigurationDriver;
$driver = new YamlConfigurationDriver();
$config = [
'name' => 'demo',
'database' => [
'host' => 'localhost',
],
];
$data = $driver->encode($config);
$decoded = $driver->decode($data);$driver->write(__DIR__ . '/config.yaml', $config);
$config = $driver->read(__DIR__ . '/config.yaml');This driver uses Symfony YAML. Empty YAML decodes to an empty array. Scalar-only YAML is not accepted as a configuration array.
Failures throw CommonPHP config exceptions instead of returning false.