1 <?php
2 /**
3 * Conf.php
4 *
5 * @author Elvyrra SAS
6 * @license http://rem.mit-license.org/ MIT
7 */
8
9 namespace Hawk;
10
11 /**
12 * This class is used to get and set the application base configuration
13 *
14 * @package Core
15 */
16 final class Conf extends Singleton{
17 /**
18 * The application configuration cache
19 *
20 * @var array
21 */
22 private $conf;
23
24
25 /**
26 * The configuration instance
27 *
28 * @var Conf
29 */
30 protected static $instance;
31
32
33 /**
34 * Get a configuration value
35 *
36 * @param string $option The name of the configuration parameter to get
37 *
38 * @return mixed The configuration value
39 */
40 public function get($option = ''){
41 if(!isset($this->conf)) {
42 return null;
43 }
44
45 if(empty($option)) {
46 return $this->conf;
47 }
48 else{
49 $fields = explode('.', $option);
50 $tmp = $this->conf;
51 foreach($fields as $field){
52 if(isset($tmp[$field])) {
53 $tmp = $tmp[$field];
54 }
55 else{
56 return null;
57 }
58 }
59 return $tmp;
60 }
61 }
62
63
64 /**
65 * Set a configuration parameter
66 *
67 * @param string $option The name of the parameter to set
68 * @param mixed $value The value to set
69 */
70 public function set($option, $value = null){
71 if($value == null) {
72 $this->conf = $option;
73 }
74 else{
75 $fields = explode('.', $option);
76 $tmp = &$this->conf;
77 foreach($fields as $field){
78 $tmp = &$tmp[$field];
79 }
80 $tmp = $value;
81 }
82 }
83
84
85 /**
86 * Check if a configuration parameter exists
87 *
88 * @param string $option The parameter name to find
89 *
90 * @return boolean True if the parameter exists in the application configuration, false else
91 */
92 public function has($option){
93 $value = $this->get($option);
94 return $value !== null;
95 }
96
97 }