Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/puzzle-org/configuration
Configuration as a service
https://github.com/puzzle-org/configuration
configuration library oop php yaml
Last synced: 2 months ago
JSON representation
Configuration as a service
- Host: GitHub
- URL: https://github.com/puzzle-org/configuration
- Owner: puzzle-org
- Created: 2013-11-17T22:58:15.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2023-03-28T07:08:09.000Z (almost 2 years ago)
- Last Synced: 2024-09-22T20:18:19.508Z (4 months ago)
- Topics: configuration, library, oop, php, yaml
- Language: PHP
- Homepage:
- Size: 69.3 KB
- Stars: 4
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Puzzle-configuration ![PHP >= 5.6](https://img.shields.io/badge/php-%3E%3D%205.6-blue.svg)
====================**_PHP 7.x users please use puzzle/configuration 4.x_**
**_PHP 5.6 users please use puzzle/configuration 3.x_**Hide configuration implementation behind common interface.
Some advantages :
* Application does not depend upon configuration implementation details
* Application does not have to manage filesystem issues (for filesystem based implementations)
* Application can be easily tested, even for configuration edge cases (missing or wrong configuration values)
* Define configuration as a service in your dependency injection containerQA
--[![SensioLabsInsight](https://insight.sensiolabs.com/projects/635b04b7-6238-4200-8526-72766767fd22/big.png)](https://insight.sensiolabs.com/projects/635b04b7-6238-4200-8526-72766767fd22)
Service | Result
--- | ---
**CI** | [![CI](https://github.com/puzzle-org/configuration/actions/workflows/ci.yml/badge.svg)](https://github.com/puzzle-org/configuration/actions/workflows/ci.yml)
**Scrutinizer** | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/puzzle-org/configuration/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/puzzle-org/configuration/?branch=master)
**Code coverage** | [![codecov](https://codecov.io/gh/puzzle-org/configuration/branch/master/graph/badge.svg)](https://codecov.io/gh/puzzle-org/configuration)
**Packagist** | [![Latest Stable Version](https://poser.pugx.org/puzzle/configuration/v/stable.png)](https://packagist.org/packages/puzzle/configuration) [![Total Downloads](https://poser.pugx.org/puzzle/configuration/downloads.svg)](https://packagist.org/packages/puzzle/configuration)Installation
------------
Use composer :
```json
{
"require": {
"puzzle/configuration" : "~4.0"
}
}
```Documentation
-------------### Configuration as a service ###
```php
read('app/detection/threshold');
}
}
```The way the configuration value is read depends on the chosen implementation.
Up to now, 2 implementations are provided :
* Memory (for unit testing purpose)
* Yaml (based on Symfony/Yaml).For YAML one, ```'app/detection/threshold'``` means ```detection[thresold]``` in app.yml file.
When you instanciate YamlConfiguration object, you need to provide where yaml files can be found :```php
2
);$example = new ExampleTest($config);
```
### Default values ###
```php
read('a/b/c', 'default value if a/b/c does not exist');
```But if ```a/b/c``` is required :
```php
readRequired('a/b/c');
```### Fallback strategy ###
```php
readFirstExisting('a/b/c', 'd/e/f', 'x/y/z');
```### Override configuration ###
If you need some configuration to (partially or not) override another one :
```php
overrideBy($defaultConfig)
->overrideBy($localConfig);// values will be read in localConfig first. They will be read in default config only if they don't exist in local one.
```Another example :
```php
2
);$config = new Puzzle\Configuration\Stacked();
$config->overrideBy($defaultConfig)
->overrideBy($overrideConfig);
```
You can add as many as configuration instances you want in the stack. The last inserted is the most prioritary.If you want to add the least prioritary, use the ```addBase()``` method :
```php
overrideBy($overrideConfig)
->addBase($defaultConfig);
```### Prefixed configuration ###
You can use automatic prefix decorator ```PrefixedConfiguration```. It can be useful for "namespace like" configurations such as loggers or multiple databases ones.
```yaml
# logger.ymlapp:
filename: app.log
verbosity: INFO
users:
filename: users.log
verbosity: WARNING
``````php
readRequired('filename');
$verbosity = $config->readRequired('verbosity');
```Changelog
---------**4.x --> 5.x**
- Drop php 7 support. Minimal version is 8.0
**3.x --> 4.x**- Drop php 5.6 & 7.0 support. Minimal version is 7.1.0
**2.x --> 3.x**- Drop php 5.5 support. Minimal version is 5.6.0
**1.x -> 2.x**- Drop php 5.4 support. Minimal version is 5.5.0