Skip to content

commonphp/config-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CommonPHP PHP Config Driver

Configuration driver for CommonPHP that writes and reads PHP files returning configuration arrays.

Requirements

  • PHP ^8.5
  • comphp/config:^0.3

Installation

Once this package is available through your Composer repositories, install it with:

composer require comphp/config-php

Usage

<?php

use CommonPHP\Drivers\Config\PHP\PhpConfigurationDriver;

$driver = new PhpConfigurationDriver();

$config = [
    'app' => 'demo',
    'debug' => true,
    'database' => [
        'host' => 'localhost',
    ],
];

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

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

Format Notes

PHP config files must return an array. This driver includes PHP files when decoding or reading, so configuration files are trusted code and are executed by PHP.

Error Handling

Read, write, parse, validation, and unsupported value failures throw CommonPHP config exceptions such as ConfigReadException, ConfigWriteException, ConfigValidationException, or ConfigException.

Documentation

License

MIT. See LICENSE.md.

About

Configuration Driver for CommonPHP which includes/builds PHP include files that return arrays

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages