https://github.com/acgrid/config.php
PHP configuration manager
https://github.com/acgrid/config.php
apcu configuration-management php-library php72
Last synced: 7 days ago
JSON representation
PHP configuration manager
- Host: GitHub
- URL: https://github.com/acgrid/config.php
- Owner: acgrid
- License: mit
- Created: 2018-09-25T11:09:04.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-12T15:56:54.000Z (over 6 years ago)
- Last Synced: 2025-06-05T22:41:36.223Z (30 days ago)
- Topics: apcu, configuration-management, php-library, php72
- Language: PHP
- Size: 15.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Config.php
## Features
* Collection for configuration items
* Deferred item definition, item is never defined until it is used
* Self-descriptive, with IDE auto-completion powered
* Deferred resolution of current and default value
* Enumeration and export for administrative script and manager
* Full control for populating pre-loaded data
* Caching via PHP's ultra-fast APCu with write-back on demand
* Shipped with some helpers for quick reader and writer## Usage
### Definition
Extend `Collection` with each definition a public functionAn Live Template of PHPStorm like this can be added to make a shortcut
```php
public function $CONF_NAME$(): Item
{
return $this->make(__FUNCTION__, $DEF_VALUE$, $READER$, $WRITER$);
}
```
### Source
Instantiate your own `Loader` with a callback that return the array of raw data of configuration. The key shall be the Collection's FQN. Just `require` the dumped file in case of using a saved php configuration file. Call `setApcu('key_prefix')` to enable APCu caching.### Routines
Instantiate needed children instance of `Collection`, which a DI container is suggested to fulfil the task. Pass the loader in previous step. Then you call get the configuration by `$collection->item()()`. Note that `__invoke()` is used. Otherwise what you get is a `Item` object having many useful methods like `def()` and `raw()`.See tests for more detailed usage.