rollylni/liteconfig

This package is abandoned and no longer maintained. No replacement package was suggested.

simplified work with config

2.1.0 2020-11-02 18:13 UTC

This package is auto-updated.

Last update: 2021-12-09 20:03:18 UTC


README

Packagist

  • multifunctional
  • the ability to add your own formats
  • loading config by file extension
  • 5 formats available by default

Example usage

require "vendor/autoload.php";

$cfg = new LiteConfig\Config("File.json"); //detect format by extension
$cfg->load([
    "default_formats" => ["yaml", "json", "ini", "enum", "serialize"],
    "default_key" => "default_value"
]);
$cfg->set("key", "value");
$cfg->save();

File.json:

{
   "default_formats": ["yaml", "json", "ini", "enum", "serialize"],
   "default_key": "default_value",
   "key": "value"
}

Make your own format

require "vendor/autoload.php";

use LiteConfig\Format\Format;
use LiteConfig\Config;

class MyFormat extends Format {

    public function getName() {
        return "My own Format";
    }
    
    public function read(string $input): array {
         return json_decode(base64_decode($input));
    }
    
    public function write(array $input): string {
        return base64_encode(json_encode($input));
    }
}
$format = new MyFormat("json64");
$format->addAlias("js64");
Config::addFormat($format);