mirror of
https://github.com/jimeh/dlist.git
synced 2026-02-18 23:46:39 +00:00
created a configuration object model, and other minor changes...
git-svn-id: file:///Users/jimeh/Desktop/dlist/trunk@6 a5845835-ea0f-0410-a762-dd0bfe9bfde8
This commit is contained in:
64
libs/config.lib.php
Normal file
64
libs/config.lib.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
class config {
|
||||
|
||||
/*
|
||||
|
||||
Class: config v0.1 beta
|
||||
|
||||
Copyright © 2006 Jim Myhrberg. All rights reserved.
|
||||
zynode@gmail.com
|
||||
|
||||
*/
|
||||
|
||||
|
||||
function config ($input=false) {
|
||||
if ( !empty($input) ) $this->parse($input);
|
||||
}
|
||||
|
||||
function parse ($input, $overwrite=true) {
|
||||
if ( is_array($input) ) {
|
||||
$this->parse_array($input, $overwrite);
|
||||
} elseif ( is_string($input) ) {
|
||||
if ( preg_match("/.php$/", $input) ) {
|
||||
$this->parse_php_file($input, 'config', $overwrite);
|
||||
} else {
|
||||
$this->parse_ini_file($input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function parse_array ($input, $overwrite=true) {
|
||||
if ( is_array($input) ) {
|
||||
foreach( $input as $key => $value ) {
|
||||
if ( is_array($value) ) {
|
||||
foreach( $value as $k => $v ) {
|
||||
if ( ($empty = empty($this->$key)) || $overwrite ) {
|
||||
$this->$key = ( $empty ) ? array($k=>$v) : array_merge($this->$key, array($k=>$v)) ;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( $overwrite || empty($this->$key) ) $this->$key = $value;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
function parse_php_file ($file, $var='config', $overwrite=true) {
|
||||
if ( is_readable($file) ) {
|
||||
include($file);
|
||||
$this->parse_array($$var, $overwrite);
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
function parse_ini_file ($file, $overwrite=true) {
|
||||
if ( is_readable($file) ) {
|
||||
$this->parse_array(parse_ini_file($file, true), $overwrite);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user