Giter VIP home page Giter VIP logo

config-manager's Introduction

Specifications

Compatible cache systems

  • PHP and all others compatible data formats
  • MYSQL - MEMORY Storage Engine (working on)
  • MEMCACHE (working on)
  • MEMCACHED (working on)
  • APC (working on)
  • XCACHE (working on)

Compatible data formats

  • XML
  • PHP
  • JSON
  • INI
  • YAML
  • PDO
    • CUBRID
    • MS SQL
    • Firebird/Interbase
    • IBM
    • Informix
    • MySQL
    • Oracle
    • ODBC - DB2
    • PostgreSQL
    • SQLite
    • 4D

Basic usage tutorial:

Introduction

This is a configurations managers with automatic extension detection.

It is very easy and powerfull at the same time!

Don't warry about caching or others IO procedures, it manages them in atomic way: data is always ready, updated an served with a cache if possible.

All what you need to know are 2 thinks:

  • how istantiate the config-Manager: using the static method getInstance() with the data file as first parameter.
        <?php
         include 'ConfigManager.php';
         $myXmlConfigFile='myConfig.xml';
         $data=ConfigManager::getInstance($myXmlConfigFile);
        ?>
  • how you can manage your data: using the methods defined by this interface:
        <?php
        interface ExtensionManager
        {
                //return a value stored with the key passed as param
                public function get($key);
                //delete a value stored with the key passed as param 
                public function delete($key);
                //store an value that can be an object,array or basic type in the corrispective existing key, or store all variables inside an array or object passed like key  
                public function set($key, $value=false);
                //like before, but this time you can add new key only if not exist
                public function add($key, $value=false);
                //return true if the corrispective value exist
                public function exist($key);
                //return an associative array of key,value of all data
                public function asArray();
        }
        ?>

for example:

        <?php
         include 'ConfigManager.php';
         $myXmlConfigFile='myConfig.xml';
         $data=ConfigManager::getInstance($myXmlConfigFile);
         $data->get('aKey'); 
        ?>

Caching

To set on the caching you just need to provide the name of cached file(with php or preferred format extension) as second parameter of getInstance() method

for example:

        <?php
         include 'ConfigManager.php';
         $myXmlConfigFile='configs/myConfig.xml';
         $data=ConfigManager::getInstance($myXmlConfigFile,$myXmlConfigFile.'.php');
         $data->get('aKey'); 
        ?>

Working with third-party datastores

Sometimes you need to manage configuration in a database or save it in caching system like Memcached: in these cases you must provide to ConfigManager the path of the minimal required configuration to do the job as first parameter (and/or as second parameter for caching). The syntax is the same, but what must be wrote in the configuration file is declared by the Extension standard chapter

Example: managing database

main.php

    <?php
    
    $config = ConfigManager::getInstance('config.pdo','cache.php');
    
    ?>

config.pdo

    <?php

    return array(
      'db_type'        => 'mysql',
      'db_host'        => 'localhost',
      'db_name'        => 'game',
      'user_name'      => 'root',
      'user_password'  => '',
      'driver_options' => array(),
      'table'          => 'config',
      'key'            => 'config_name',
      'value'          => 'config_value'
    );

?>

Extensions standard

Some types of markup language require to follow conventions to work on ConfigManager:

  • XML: Must respect the format:
     <?xml version="1.0"?>
    <configurations>
        <config>
            <name>a key </name>
            <value>a value </value>
        </config>
    <configurations>
  • PHP: Must return an array :
        <?php
         return array(
         'a key' => 'a value'
         );
        ?>
  • PDO: You need a configuration file with database informations like
   <?php

   return array(
     'db_type'        => 'mysql',
     'db_host'        => 'localhost',
     'db_name'        => 'game',
     'user_name'      => 'root',
     'user_password'  => '',
     'driver_options' => array(),
     'table'          => 'config',
     'key'            => 'config_name',
     'value'          => 'config_value'
   );

   ?>

Advanced tutorial:

config-manager's People

Contributors

jstar88 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.