PHP Classes

xconfig: Parse configuration values as key value pairs

Recommend this page to a friend!
  Info   View files Example   Demos   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 243 All time: 7,981 This week: 190Up
Version License PHP version Categories
xconfig 2.0.2GNU Lesser Genera...7PHP 5, Files and Folders, Systems adm..., C..., P...
Description 

Author

This class can parse configuration values defined as key value pairs.

It can take a string of configuration values on which each key is separate from the value using a = sign and there is one configuration value per line.

Lines starting with # are taken as comment lines, so they are ignored.

The parser can take an array of default values for pre-defined keys.

Configuration parameters can be retrieved like class variables. The class also provides an array interface that can be counted and iterated.

Picture of philippe thomassigny
  Performance   Level  
Name: philippe thomassigny <contact>
Classes: 6 packages by
Country: Mexico Mexico
Age: 54
All time rank: 120613 in Mexico Mexico
Week rank: 587 Up9 in Mexico Mexico Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php

echo '<h1>XConfig examples</h1>';

include_once
'../include/xconfig/XConfig.class.php';

$config = new \xconfig\XConfig(file_get_contents('myconfig.conf'), array('defparam1' => 'defvalue1', 'defparam2' => 'defvalue2', 'defparam3' => 'defvalue3'));

echo
'<h2>content of $config:</h2>';
print
$config;
echo
'<br />';

echo
'<h3>get a parameter to a local variable:</h3>';
$param1 = $config->parameter1;
echo
$param1 . '<br />';
echo
'<br />';

echo
'<h3>use directly a parameter into a sentence:</h3>';
foreach(
$config->parameter2 as $p)
  echo
$p . '<br />';
echo
'<br />';

echo
'<h3>set a new parameter:</h3>';
echo
'parameter3=value3<br />';
$config->parameter3 = 'value3';
echo
'<br />';

echo
'<h3>new content of $config:</h3>';
print
$config;
echo
'<br />';

echo
'<h3>iterate the $config:</h3>';
print
$config;
echo
'<br />';
 
echo
'<h2>Merge two config files:</h2>';

$globalconfig = new \xconfig\XConfig(file_get_contents('myglobalconfig.conf'));
$localconfig = new \xconfig\XConfig(file_get_contents('mylocalconfig.conf'));
$globalconfig->merge($localconfig);

echo
'<h3>Content of merged configuration:</h3>';
print
$globalconfig;
echo
'<br />';

?>


  Demo XConfigExternal page  
  Files folder image Files  
File Role Description
Files folder imageexample (4 files)
Files folder imageinclude (1 directory)
Accessible without login Plain text file README.md Doc. Auxiliary data

  Files folder image Files  /  example  
File Role Description
  Accessible without login Plain text file index.php Example Example script
  Accessible without login Plain text file myconfig.conf Data Auxiliary data
  Accessible without login Plain text file myglobalconfig.conf Data Auxiliary data
  Accessible without login Plain text file mylocalconfig.conf Data Auxiliary data

  Files folder image Files  /  include  
File Role Description
Files folder imagexconfig (1 file)

  Files folder image Files  /  include  /  xconfig  
File Role Description
  Plain text file XConfig.class.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:243
This week:0
All time:7,981
This week:190Up