phpactor / config-loader
Library to load (user) configuration
Installs: 37 508
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 2
Requires
- php: ^7.3 || ^8.0
- dnoegel/php-xdg-base-dir: ^0.1.0
- webmozart/path-util: ^2.3
Requires (Dev)
- ergebnis/composer-normalize: ^2.0
- friendsofphp/php-cs-fixer: ^2.17
- phpactor/test-utils: ~1.1.3
- phpbench/phpbench: dev-master
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ~0.12.0
- phpunit/phpunit: ^9.0
- symfony/yaml: ^4.2
This package is auto-updated.
Last update: 2022-03-20 17:02:09 UTC
README
Library to load an application configuration file
Usage
$loader = new ConfigLoader( new Deserializers([ 'json' => new JsonDeserializer(), ]), new PathCandidates([ new XdgPathCandidate('myapp', 'config.json', 'json'), new AbsolutePathCandidate(getcwd() . '/' . 'myapp.json', 'json'), ]) ); $config = $loader->load();
The above will:
- Load existing config from XDG config directory for
myapp
(e.g.$HOME/.config/myapp/config.json
). - Merge existing config from the current working directory if it exists.
Deserializers
- JsonDeserializer: Deserializes using
json_decode
. Very fast. - YamlDeserializer: Deserializes using the Symfony YAML parser requires
symfony/yaml
Path Candidates
- XdgPathCandidate: Represents candidate config file in the XDG config path for an application.
- AbsolutePathCandidate: Represents an arbitrary config file at an absolute path.
Contributing
This package is open source and welcomes contributions! Feel free to open a pull request on this repository.
Support
- Create an issue on the main Phpactor repository.
- Join the
#phpactor
channel on the Slack Symfony Devs channel.