Description
A lightweight PHP static class with zero dependencies.
Supports multiple configs and multidimensional arrays.
Built-in support for PHP, INI and JSON files.
LiteConfig alternatives and similar libraries
Based on the "Dependency Management Extras" category.
Alternatively, view LiteConfig alternatives based on common mentions on social networks and blogs.
-
Satis
Simple static Composer repository generator - For a full private Composer repo use Private Packagist -
Composed
Easily parse your project's Composer configuration, and those of its dependencies, at runtime
InfluxDB - Power Real-Time Data Analytics at Scale
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of LiteConfig or a related project?
README
LiteConfig
A lightweight PHP static class with zero dependencies.
Supports multiple configs and multidimensional arrays.
Built-in support for PHP, INI and JSON files.
Supports YAML and anything else you can parse to an array, see below.
Requirements
- PHP 7.0 +
Install
composer require xy2z/lite-config
Examples
require 'path/to/vendor/autoload.php';
use xy2z\LiteConfig\LiteConfig as Config;
Array
Config::loadArray([
'version' => '1.0',
'app' => [
'name' => 'Example'
]
]);
echo Config::get('version'); # 1.0
echo Config::get('app'); # Array('name' => 'Example')
echo Config::get('app.name', 'default name'); # Example
echo Config::get('app.type', 'Desktop'); # Desktop
Directory
# config/settings.php
return [
'app_name' => 'Example',
];
# index.php
Config::loadDir('config/', true);
echo Config::get('settings.app_name'); # key is 'filename.key'
Single file
# No key prefix
Config::loadFile('config/settings.php');
echo Config::get('key');
# Prefix filename to key
Config::loadFile('config/db.ini', true);
echo Config::get('db.key');
YAML
composer require symfony/yaml
use xy2z\LiteConfig\LiteConfig as Config;
use Symfony\Component\Yaml\Yaml;
Config::loadArray(Yaml::parseFile(__DIR__ . '/config/file.yml'));
echo Config::get('key');
Methods
get(string $key, $default = null)
Get value of key.all()
Returns a complete array.exists(string $key)
Does key exist?loadDir(string $path, bool $prefix_filename = false, string $prefix = null)
Loads all files in dir.loadFile(string $path, bool $prefix_filename = false, string $custom_prefix = null)
Load a single file.loadArray(array $array, string $prefix = null)
Loads a php array.