im/vendor/clagiordano/weblibs-configmanager
weiz 22d166de26 update 2023-09-26 18:09:46 +08:00
..
.github/workflows update 2023-09-26 18:09:46 +08:00
src update 2023-09-26 18:09:46 +08:00
tests update 2023-09-26 18:09:46 +08:00
testsdata update 2023-09-26 18:09:46 +08:00
.gitignore update 2023-09-26 18:09:46 +08:00
.travis.yml update 2023-09-26 18:09:46 +08:00
README.md update 2023-09-26 18:09:46 +08:00
composer.json update 2023-09-26 18:09:46 +08:00
composer.lock update 2023-09-26 18:09:46 +08:00
phpunit.xml update 2023-09-26 18:09:46 +08:00

README.md

BuildStatus License

weblibs-configmanager

weblibs-configmanager is a tool library for easily read and access to php config array file and direct read/write configuration file / object.

SensioLabsInsight

Why use weblibs-configmanager ?

The purpose of this project is to propose a simple and lightweight library to manage php hierarchical configuration files.

Installation

The recommended way to install weblibs-configmanager is through Composer.

composer require clagiordano/weblibs-configmanager

Usage examples

Write a sample config file like this

<?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',
      ),
    ),
  ),
);

Instance ConfigManager object

use clagiordano\weblibs\configmanager\ConfigManager;

/**
 * Instance object to read argument file
 */
$config = new ConfigManager("configfile.php");

Check if a value exists into config file

/**
 * Check if a value exists into config file
 */
$value = $config->existValue('app');

Read a simple element from config file

/**
 * Read a simple element from config file
 */
$value = $config->getValue('app');

Access to a nested element from config

/**
 * Access to a nested element from config
 */
$nestedValue = $config->getValue('other.multi.deep.nested');

Change config value at runtime

/**
 * Change config value at runtime
 */
$this->config->setValue('other.multi.deep.nested', "SUPERNESTED");

Save config file with original name (OVERWRITE)

/**
 * Save config file with original name (OVERWRITE) 
 */
$this->config->saveConfigFile();

Or save config file with a different name

/**
 * 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

/**
 * 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

/**
 * Load another configuration file without reinstance ConfigManager
 */
$this->config->loadConfig('another_config_file.php');

Copyright (C) Claudio Giordano claudio.giordano@autistici.org