|  | 2 年之前 | |
|---|---|---|
| .. | ||
| .github | 2 年之前 | |
| src | 2 年之前 | |
| tests | 2 年之前 | |
| testsdata | 2 年之前 | |
| .gitignore | 2 年之前 | |
| .travis.yml | 2 年之前 | |
| README.md | 2 年之前 | |
| composer.json | 2 年之前 | |
| composer.lock | 2 年之前 | |
| phpunit.xml | 2 年之前 | |
weblibs-configmanager is a tool library for easily read and access to php config array file and direct read/write configuration file / object.
The purpose of this project is to propose a simple and lightweight library to manage php hierarchical configuration files.
The recommended way to install weblibs-configmanager is through Composer.
composer require clagiordano/weblibs-configmanager
<?php
return array (
  'app' => 'app_name',
  'db' => 
  array (
    'host' => 'localhost',
    'user' => 'sample_user',
    'pass' => 'sample_pass',
    'port' => 3306,
  ),
  'other' => 
  array (
    'multi' => 
    array (
      'deep' => 
      array (
        'nested' => 'config_value',
      ),
    ),
  ),
);
use clagiordano\weblibs\configmanager\ConfigManager;
/**
 * Instance object to read argument file
 */
$config = new ConfigManager("configfile.php");
/**
 * Check if a value exists into config file
 */
$value = $config->existValue('app');
/**
 * Read a simple element from config file
 */
$value = $config->getValue('app');
/**
 * Access to a nested element from config
 */
$nestedValue = $config->getValue('other.multi.deep.nested');
/**
 * Change config value at runtime
 */
$this->config->setValue('other.multi.deep.nested', "SUPERNESTED");
/**
 * Save config file with original name (OVERWRITE) 
 */
$this->config->saveConfigFile();
/**
 * Save config file with original name (OVERWRITE) 
 */
$this->config->saveConfigFile('/new/file/name/or/path/test.php');
/**
 * Optionally you can also reload config file from disk after save
 */
$this->config->saveConfigFile('/new/file/name/or/path/test.php', true);
/**
 * Load another configuration file without reinstance ConfigManager
 */
$this->config->loadConfig('another_config_file.php');
Copyright (C) Claudio Giordano claudio.giordano@autistici.org