This repository has been archived by the owner on Mar 16, 2018. It is now read-only.
/
ConfigurationManager.php
91 lines (76 loc) · 2.03 KB
/
ConfigurationManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Configuration;
if (!defined('FaabBB'))
die;
use \ArrayAccess as ArrayAccess;
use Configuration\ConfigurationException as ConfigurationException;
/**
* The {@link ConfigurationManager} class is a blueprint for handling
* configuration of (for instance) the {@link Application} instance.
* If you initiate the {@link ConfigurationManager}, you'll get the default
* {@link ConfigurationManager}.
*
* @category configuration
* @version 3.010
* @since 3.010
* @copyright Copyright © 2011, FaabTech
* @author Fabian M.
*/
class ConfigurationManager implements ArrayAccess {
/**
* The properties of this {@link ConfigurationManager}.
*/
protected $properties;
/**
* Creates a new {@link ConfigurationManager} and
* loads the configuration into a map of properties.
*
* @since 3.010
* @param $file The file to load.
*/
public function __construct($file) {
// Does the configuration file exists?
if (!file_exists($file)) {
throw new ConfigurationException("File not found: " . $file);
} else if (!is_readable($file)) {
throw new ConfigurationException("Can't access file: " . $file);
}
// Parse ini file.
$parsed = parse_ini_file($file);
$this->properties = $parsed;
}
/** @Override */
public function __get($name) {
return isset($this->properties[$name]) ? $this->properties[$name]
: null;
}
/** @Override */
public function __set($name, $value) {
$this->properties[$name] = $value;
}
/** @Override */
public function __isset($name) {
return isset($this->properties[$name]);
}
/** @Override */
public function __unset($name) {
unset($this->properties[$name]);
}
/** @Override */
public function offsetSet($name, $value) {
$this->__set($name, $value);
}
/** @Override */
public function offsetExists($name) {
return $this->__isset($name);
}
/** @Override */
public function offsetUnset($name) {
$this->__unset($name);
}
/** @Override */
public function offsetGet($name) {
return $this->__get($name);
}
}
?>