https://github.com/vmassalov/config
Configuration service
https://github.com/vmassalov/config
config yaml
Last synced: 5 months ago
JSON representation
Configuration service
- Host: GitHub
- URL: https://github.com/vmassalov/config
- Owner: vmassalov
- License: mit
- Created: 2024-01-25T20:23:36.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-23T15:25:51.000Z (over 2 years ago)
- Last Synced: 2025-03-21T14:40:39.339Z (over 1 year ago)
- Topics: config, yaml
- Language: PHP
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Config
Library for matching rulesets based on file configs
The main goal of this package is to move out endless sequences of business logic 'elseif' outside of the code. It can be mapping exception classes to error codes, discount calculation rules, or any other strategy conditions. All conditions that do not change often enough and are not worth putting in the database can be conveniently transferred to the configs.
## Install
Via composer
```shell
composer require vmassalov/config
```
## Quick usage
Create yaml config file, e.g.:
```yaml
- conditions:
dayOfWeek:
- monday
- tuesday
- wednesday
- thursday
- friday
projectPriority:
- normal
- minor
result:
salaryRate: 1
needOvertimeApprove: true
- conditions:
dayOfWeek:
- monday
- tuesday
- wednesday
- thursday
- friday
projectPriority: critical
result:
salaryRate: 1
needOvertimeApprove: false
- conditions:
projectPriority: critical
result:
salaryRate: 2
needOvertimeApprove: false
```
All result blocks should contain same keys. All condition block can contain a different keys with single or multiple options.
```php
$configClient = \VMassalov\Config\ClientFactory::build('filesystem://./path/to/configs');
$configClient->find(
'config.yaml',
[
'dayOfWeek' => 'sunday',
'projectPriority' => 'critical',
],
);
```
Client will return a result of first full match item based on passed criteria
## Configuration
### DSN
filesystem://
### Config syntax
See examples in tests/functional/stubs/yaml/baseConfig.yaml
## Test
Run unit and functional test in docker
```shell
make build && make test
```
Run unit and functional test locally
```shell
php ./vendor/bin/phpunit
```
## Roadmap
* [ ] Add JSON support
* [ ] Add XML support