Skip to content

Simple PHP library for using yaml config files

License

Notifications You must be signed in to change notification settings

aelchaninov/yaml-config

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unit Tests

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

$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

TinyApps\YamlConfig\EnvLoader::init(__DIR__ . '/env.yml');
var_dump(getenv('your_environment_variable'));

Get a single value from a config (static context)

TinyApps\YamlConfig\Config::getConfigValue('example', 'property'); // returns the "property" value from example config

About

Simple PHP library for using yaml config files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%