Skip to content

Latest commit

 

History

History
34 lines (23 loc) · 768 Bytes

File metadata and controls

34 lines (23 loc) · 768 Bytes

Usage

comphp/config-php provides CommonPHP\Drivers\Config\PHP\PhpConfigurationDriver for PHP configuration files that return arrays.

Encode and Decode

use CommonPHP\Drivers\Config\PHP\PhpConfigurationDriver;

$driver = new PhpConfigurationDriver();

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

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

Read and Write

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

Notes

PHP config files are trusted code. Decoding and reading include and execute PHP, and the result must be an array.

Failures throw CommonPHP config exceptions instead of returning false.