https://github.com/tinyappsde/yaml-config
Simple PHP library for using yaml config files
https://github.com/tinyappsde/yaml-config
config php php-library yaml
Last synced: 5 months ago
JSON representation
Simple PHP library for using yaml config files
- Host: GitHub
- URL: https://github.com/tinyappsde/yaml-config
- Owner: tinyappsde
- License: mit
- Created: 2021-10-08T16:32:47.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-05-15T15:33:05.000Z (about 4 years ago)
- Last Synced: 2025-09-17T12:57:02.803Z (9 months ago)
- Topics: config, php, php-library, yaml
- Language: PHP
- Homepage:
- Size: 49.8 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/tinyappsde/yaml-config/actions/workflows/unit-test.yml)
# YAML Config
Simple PHP library for conveniently using yaml config files and (optional) loading into environment variables.
## Requirements
PHP ^8.0 or ^8.1 ~~and php-yaml extension~~ (v1.2.0 is based on symfony/yaml instead)
You can use v1.0.2 or lower for PHP 7.4 compatibility (requires the php-yaml extension though).
## Installation
`composer require tinyapps/yaml-config`
## Usage
### Config
```php
$config = new \TinyApps\YamlConfig\Config(__DIR__ . '/config.yml');
var_dump($config->get('your_variable')); // or
var_dump($config['your_variable']); // or
var_dump($config->your_variable);
// You can also set the config directory once for easier access
\TinyApps\YamlConfig\Config::setConfigDir(__DIR__ . '/example-configs');
$config = new Config('example'); // will read example-configs/example.yml
$config = new Config('sub/test'); // will read example-configs/sub/test.yml
```
### Load into environment variables
```php
TinyApps\YamlConfig\EnvLoader::init(__DIR__ . '/env.yml');
var_dump(getenv('your_environment_variable'));
```
### Get a single value from a config (static context)
```php
TinyApps\YamlConfig\Config::getConfigValue('example', 'property'); // returns the "property" value from example config
```