Skip to content

Latest commit

 

History

History
34 lines (23 loc) · 772 Bytes

File metadata and controls

34 lines (23 loc) · 772 Bytes

Usage

comphp/config-yaml provides CommonPHP\Drivers\Config\YAML\YamlConfigurationDriver for YAML configuration files.

Encode and Decode

use CommonPHP\Drivers\Config\YAML\YamlConfigurationDriver;

$driver = new YamlConfigurationDriver();

$config = [
    'name' => 'demo',
    'database' => [
        'host' => 'localhost',
    ],
];

$data = $driver->encode($config);
$decoded = $driver->decode($data);

Read and Write

$driver->write(__DIR__ . '/config.yaml', $config);
$config = $driver->read(__DIR__ . '/config.yaml');

Notes

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.