Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/php-strict/config
Storage and loader for configuration object
https://github.com/php-strict/config
config configuration php php-library php7
Last synced: 25 days ago
JSON representation
Storage and loader for configuration object
- Host: GitHub
- URL: https://github.com/php-strict/config
- Owner: php-strict
- License: gpl-3.0
- Created: 2019-03-20T10:48:51.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-16T05:55:27.000Z (about 5 years ago)
- Last Synced: 2024-05-06T21:46:27.978Z (8 months ago)
- Topics: config, configuration, php, php-library, php7
- Language: PHP
- Size: 34.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Config
[![Software License][ico-license]](LICENSE.txt)
[![Build Status][ico-travis]][link-travis]
[![codecov][ico-codecov]][link-codecov]
[![Codacy Badge][ico-codacy]][link-codacy]Storage and loader for configuration object.
Allows be initialised with defaults and load saved configuration from PHP, INI, JSON file.## Requirements
* PHP >= 7.1
## Install
Install with [Composer](http://getcomposer.org):
```bash
composer require php-strict/config
```## Usage
Define your own application configuration class by extending Config class:
```php
use PhpStrict\Config\Configclass AppConfig extends Config
{
/**
* Project root
*
* @var string
*/
public $root = '/';
/**
* Debug enable|disable
*
* @var bool
*/
public $debug = false;
/**
* Database settings
*/
public $dbServer = '';
public $dbUser = '';
public $dbPassword = '';
public $dbName = '';
public $dbCharset = '';
public $dbTablePrefix = ''
/*
* another configuration fields here
*/
}
```Example of configuration file content:
```ini
DEBUG=trueDB_SERVER=localhost
DB_USER=root
DB_PASSWORD=
DB_NAME=testproject
DB_CHARSET=utf8
DB_TABLE_PREFIX=CACHE=true
```Create and fill your configuration object with data from saved configuration file:
```php
$config = new AppConfig();
$config->loadFromFile('config.ini');
```Use configuration object fields directly on demand:
```php
mysqli::__construct(
$config->dbServer,
$config->dbUser,
$config->dbPassword,
$config->dbName
);
```Get subconfig by fields prefix:
```php
$dbConfig = $config->getSlice('db');mysqli::__construct(
$dbConfig->server,
$dbConfig->user,
$dbConfig->password,
$dbConfig->name
);
```## Tests
To execute the test suite, you'll need [Codeception](https://codeception.com/).
```bash
vendor\bin\codecept run
```[ico-license]: https://img.shields.io/badge/license-GPL-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/php-strict/config/master.svg?style=flat-square
[link-travis]: https://travis-ci.org/php-strict/config
[ico-codecov]: https://codecov.io/gh/php-strict/config/branch/master/graph/badge.svg
[link-codecov]: https://codecov.io/gh/php-strict/config
[ico-codacy]: https://api.codacy.com/project/badge/Grade/9348a8df8ccf47bcb5b6c11695b7cac3
[link-codacy]: https://www.codacy.com/app/php-strict/config?utm_source=github.com&utm_medium=referral&utm_content=php-strict/config&utm_campaign=Badge_Grade