Popularity
1.0
Stable
Activity
6.5
-
6
3
4

Description

A lightweight PHP static class with zero dependencies.

Supports multiple configs and multidimensional arrays.

Built-in support for PHP, INI and JSON files.

Programming language: PHP
License: MIT License

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.

Do you think we are missing an alternative of LiteConfig or a related project?

Add another 'Dependency Management Extras' Library

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.