Passed
Branch master (21a93d)
by Alfred
01:51
created
ConfigManager.php 3 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -11,18 +11,18 @@  discard block
 block discarded – undo
11 11
 {
12 12
 const PHP_TAB = "\t";
13 13
     /**
14
-    * Chemin complet du fichier de configuration
15
-    */
14
+     * Chemin complet du fichier de configuration
15
+     */
16 16
     private $targetFile;
17 17
     private $Options = [];
18 18
     /**
19
-    * tableau multidimensionnel contenant les donnée de configuration, initialement
20
-    * chargées depuis le fichier
21
-    */
19
+     * tableau multidimensionnel contenant les donnée de configuration, initialement
20
+     * chargées depuis le fichier
21
+     */
22 22
     private $Config = [];
23 23
     /**
24
-    * processeurs de fichier pris en charge par l'application
25
-    */
24
+     * processeurs de fichier pris en charge par l'application
25
+     */
26 26
     private $availableDrivers = array('JSON', 'PHP','INI','YML');
27 27
 
28 28
     private $defaultSection = 'runtime';
@@ -48,11 +48,11 @@  discard block
 block discarded – undo
48 48
             trigger_error($a->getMessage(),E_USER_ERROR);
49 49
         }
50 50
     }
51
- /**
52
-     * @param $section
53
-     * @param $item
54
-     * @return array|bool|mixed
55
-     */
51
+  /**
52
+   * @param $section
53
+   * @param $item
54
+   * @return array|bool|mixed
55
+   */
56 56
     public function get($section=null, $item=null)
57 57
     {
58 58
         if($item) $item = trim(strtolower($item));
@@ -81,12 +81,12 @@  discard block
 block discarded – undo
81 81
         return $this->Config[$section][$item];
82 82
     }
83 83
 
84
- /**
85
-     * @param $section
86
-     * @param $item
87
-     * @param $value
88
-     * @return bool
89
-     */
84
+  /**
85
+   * @param $section
86
+   * @param $item
87
+   * @param $value
88
+   * @return bool
89
+   */
90 90
     public function set($section,$item=null,$value=null)
91 91
     { 
92 92
         ob_start();
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
             case 1:
98 98
                 if(!is_array($arguments[0])) return false;
99 99
                 $item=array_change_key_case($arguments[0], CASE_LOWER); $section=null; $value=null;	
100
-		break;
100
+    break;
101 101
             case 2:
102 102
                 if(is_array($arguments[0])) return false;
103 103
                 $_arg = strtolower(trim($arguments[0]));
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
             $Options['driver'] = strtoupper(pathinfo($Options['filename'], PATHINFO_EXTENSION));
217 217
         else
218 218
             $Options['filename']= $Options['filename'].'.'.strtolower($default['driver']);
219
-	     if(!in_array($Options['driver'],$this->availableDrivers))
219
+        if(!in_array($Options['driver'],$this->availableDrivers))
220 220
             throw new Exception('ERROR: driver "'.$Options['driver'].'" not supported');
221
-	    $this->Options = array_merge($default,$Options);
221
+      $this->Options = array_merge($default,$Options);
222 222
         return $this->Options;
223 223
     }
224 224
     /**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
         }
251 251
         return $path;
252 252
     }
253
-	  /**
253
+    /**
254 254
      * @param array $options
255 255
      * @return mixed
256 256
      */
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 /**
288 288
      * @return bool
289 289
      */
290
-     private function Save()
290
+      private function Save()
291 291
     {
292 292
         if( !is_writeable( $this->targetFile ) ) @chmod($this->targetFile,0775);
293 293
         $content = null;
Please login to merge, or discard this patch.
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
     /**
24 24
     * processeurs de fichier pris en charge par l'application
25 25
     */
26
-    private $availableDrivers = array('JSON', 'PHP','INI','YML');
26
+    private $availableDrivers = array('JSON', 'PHP', 'INI', 'YML');
27 27
 
28 28
     private $defaultSection = 'runtime';
29 29
 
@@ -32,20 +32,20 @@  discard block
 block discarded – undo
32 32
      * @param $location
33 33
      * @throws \Exception
34 34
      */
35
-    public function __construct( $filename, $location=null )
35
+    public function __construct($filename, $location = null)
36 36
     {
37 37
         $numargs = func_num_args();
38 38
         try
39 39
         {
40
-            if($numargs > 2)
40
+            if ($numargs > 2)
41 41
                 throw new Exception('SETUP ERROR: configuration manager can accept only up to 2 parameters,'.$numargs.' given!');
42
-            $this->configureOptions($filename,$location);
42
+            $this->configureOptions($filename, $location);
43 43
             $this->parseConfiguration($this->Options);
44 44
             return $this;
45 45
         }
46
-        catch(Exception $a)
46
+        catch (Exception $a)
47 47
         {
48
-            trigger_error($a->getMessage(),E_USER_ERROR);
48
+            trigger_error($a->getMessage(), E_USER_ERROR);
49 49
         }
50 50
     }
51 51
  /**
@@ -53,31 +53,31 @@  discard block
 block discarded – undo
53 53
      * @param $item
54 54
      * @return array|bool|mixed
55 55
      */
56
-    public function get($section=null, $item=null)
56
+    public function get($section = null, $item = null)
57 57
     {
58
-        if($item) $item = trim(strtolower($item));
59
-        if($section) $section = trim(strtolower($section));
60
-        if(!count($this->Config)) return false;
61
-        if(!$section or !strlen($section)) return $this->Config;
62
-        if($section AND $item)
58
+        if ($item) $item = trim(strtolower($item));
59
+        if ($section) $section = trim(strtolower($section));
60
+        if (!count($this->Config)) return false;
61
+        if (!$section or !strlen($section)) return $this->Config;
62
+        if ($section AND $item)
63 63
         {
64
-            if(!isset($this->Config[$section]))
64
+            if (!isset($this->Config[$section]))
65 65
             {
66 66
                 $key = $item;
67 67
                 $item = $section;
68 68
                 $section = $this->defaultSection;
69
-                if(!isset($this->Config[$section][$item][$key]))
69
+                if (!isset($this->Config[$section][$item][$key]))
70 70
                     return false;
71 71
                 return $this->Config[$section][$item][$key];
72 72
             }
73 73
         }
74
-        elseif(!$item or !strlen($item))
74
+        elseif (!$item or !strlen($item))
75 75
         {
76 76
             $item = $section;
77
-            if(isset($this->Config[$item])) return $this->Config[$item];
77
+            if (isset($this->Config[$item])) return $this->Config[$item];
78 78
             $section = $this->defaultSection;
79 79
         }
80
-        if(!isset($this->Config[$section][$item])) return false;
80
+        if (!isset($this->Config[$section][$item])) return false;
81 81
         return $this->Config[$section][$item];
82 82
     }
83 83
 
@@ -87,53 +87,53 @@  discard block
 block discarded – undo
87 87
      * @param $value
88 88
      * @return bool
89 89
      */
90
-    public function set($section,$item=null,$value=null)
90
+    public function set($section, $item = null, $value = null)
91 91
     { 
92 92
         ob_start();
93 93
         $numarg = func_num_args();
94
-        $arguments=func_get_args();
95
-        switch($numarg)
94
+        $arguments = func_get_args();
95
+        switch ($numarg)
96 96
         {
97 97
             case 1:
98
-                if(!is_array($arguments[0])) return false;
99
-                $item=array_change_key_case($arguments[0], CASE_LOWER); $section=null; $value=null;	
98
+                if (!is_array($arguments[0])) return false;
99
+                $item = array_change_key_case($arguments[0], CASE_LOWER); $section = null; $value = null;	
100 100
 		break;
101 101
             case 2:
102
-                if(is_array($arguments[0])) return false;
102
+                if (is_array($arguments[0])) return false;
103 103
                 $_arg = strtolower(trim($arguments[0]));
104
-                if(is_array($arguments[1])){ $section=$_arg; $item =array_change_key_case($arguments[1], CASE_LOWER);$value=null;}
105
-                else {$item = $_arg;$value=$arguments[1];$section=null;}
104
+                if (is_array($arguments[1])) { $section = $_arg; $item = array_change_key_case($arguments[1], CASE_LOWER); $value = null; }
105
+                else {$item = $_arg; $value = $arguments[1]; $section = null; }
106 106
                 break;
107 107
             default:
108 108
                 break;
109 109
         }
110
-        $section = $section? trim(strtolower($section)) : $this->defaultSection;
111
-        if(!is_array($item))
110
+        $section = $section ? trim(strtolower($section)) : $this->defaultSection;
111
+        if (!is_array($item))
112 112
         {
113
-            if(!$value) return false;
114
-            $item=trim(strtolower($item));
115
-            if(!isset($this->Config[$section][$item]) or !is_array($this->Config[$section][$item])):
116
-                $this->Config[$section][$item]=$value;
113
+            if (!$value) return false;
114
+            $item = trim(strtolower($item));
115
+            if (!isset($this->Config[$section][$item]) or !is_array($this->Config[$section][$item])):
116
+                $this->Config[$section][$item] = $value;
117 117
             else:
118
-                if(!is_array($value)) $value = array($value);
119
-                $this->Config[$section][$item] = array_merge($this->Config[$section][$item],$value);
118
+                if (!is_array($value)) $value = array($value);
119
+                $this->Config[$section][$item] = array_merge($this->Config[$section][$item], $value);
120 120
             endif;
121 121
         }
122 122
         else
123 123
         {
124
-            if($value) return false;
124
+            if ($value) return false;
125 125
             $item = array_change_key_case($item, CASE_LOWER);
126 126
             $sectionsize = count($this->Config[$section]);
127 127
             $itemsize = count($item);
128
-            if($sectionsize)
128
+            if ($sectionsize)
129 129
             {
130
-                if($itemsize=='1')
130
+                if ($itemsize == '1')
131 131
                 {
132
-                    if(isset($this->Config[$section][key($item)]))
133
-                        $this->Config[$section][key($item)] = array_merge($this->Config[$section][key($item)],$item[key($item)]);
134
-                    else if(!is_numeric(key($item))) $this->Config[$section][key($item)]=$item[key($item)];
132
+                    if (isset($this->Config[$section][key($item)]))
133
+                        $this->Config[$section][key($item)] = array_merge($this->Config[$section][key($item)], $item[key($item)]);
134
+                    else if (!is_numeric(key($item))) $this->Config[$section][key($item)] = $item[key($item)];
135 135
                 }
136
-                else $this->Config[$section] = array_merge($this->Config[$section],$item);
136
+                else $this->Config[$section] = array_merge($this->Config[$section], $item);
137 137
             }
138 138
             else $this->Config[$section] = $item;
139 139
         }
@@ -146,30 +146,30 @@  discard block
 block discarded – undo
146 146
      * @param $item
147 147
      * @return bool
148 148
      */
149
-    public function del($section, $item=null)
149
+    public function del($section, $item = null)
150 150
     {
151 151
         $section = trim(strtolower($section));
152
-        if($item and strlen($item))
152
+        if ($item and strlen($item))
153 153
         {
154 154
             $item = trim(strtolower($item));
155
-            if(!isset($this->Config[$section]))
155
+            if (!isset($this->Config[$section]))
156 156
             {
157 157
                 $key = $item;
158 158
                 $item = $section;
159 159
                 $section = $this->defaultSection;
160
-                if(isset($this->Config[$section][$item][$key]))
160
+                if (isset($this->Config[$section][$item][$key]))
161 161
                 {
162
-                    $itemSize=count($this->Config[$section][$item]);
163
-                    if($itemSize>1) unset($this->Config[$section][$item][$key]);
162
+                    $itemSize = count($this->Config[$section][$item]);
163
+                    if ($itemSize > 1) unset($this->Config[$section][$item][$key]);
164 164
                     else unset($this->Config[$section]);
165 165
                 }
166 166
             }
167 167
             else
168 168
             {
169
-                $sectionSize=count($this->Config[$section]);
170
-                if(isset($this->Config[$section][$item]))
169
+                $sectionSize = count($this->Config[$section]);
170
+                if (isset($this->Config[$section][$item]))
171 171
                 {
172
-                    if($sectionSize>1) unset($this->Config[$section][$item]);
172
+                    if ($sectionSize > 1) unset($this->Config[$section][$item]);
173 173
                     else unset($this->Config[$section]);
174 174
                 }
175 175
             } 
@@ -177,13 +177,13 @@  discard block
 block discarded – undo
177 177
         else
178 178
         {
179 179
             $item = $section;
180
-            if(!isset($this->Config[$item]))
180
+            if (!isset($this->Config[$item]))
181 181
             {
182 182
                 $section = $this->defaultSection;
183 183
                 $defaultSectionSize = count($this->Config[$section]);
184
-                if(isset($this->Config[$section][$item]))
184
+                if (isset($this->Config[$section][$item]))
185 185
                 {
186
-                    if($defaultSectionSize>1) unset($this->Config[$section][$item]);
186
+                    if ($defaultSectionSize > 1) unset($this->Config[$section][$item]);
187 187
                     else unset($this->Config[$section]);
188 188
                 }
189 189
             }
@@ -196,29 +196,29 @@  discard block
 block discarded – undo
196 196
      * @param $location
197 197
      * @return array|bool
198 198
      */
199
-    private function configureOptions($file,$location=null){
200
-        if(!is_string($file) or ($location and !is_string($location)))
199
+    private function configureOptions($file, $location = null) {
200
+        if (!is_string($file) or ($location and !is_string($location)))
201 201
             throw new Exception('SETUP ERROR: configuration manager can accept string only parameters');
202
-        $default=[
202
+        $default = [
203 203
             'driver' => 'PHP',
204 204
             'filename' => null,
205 205
             'directory' => __DIR__,
206 206
         ];
207 207
         $Options = [];
208
-        if($location)
209
-            $Options['directory']=rtrim($this->normalize($location),DIRECTORY_SEPARATOR);
210
-        else{
211
-            if(basename($file)!==$file)
212
-                $Options['directory']= rtrim($this->normalize(pathinfo($file,PATHINFO_DIRNAME)),DIRECTORY_SEPARATOR);
208
+        if ($location)
209
+            $Options['directory'] = rtrim($this->normalize($location), DIRECTORY_SEPARATOR);
210
+        else {
211
+            if (basename($file) !== $file)
212
+                $Options['directory'] = rtrim($this->normalize(pathinfo($file, PATHINFO_DIRNAME)), DIRECTORY_SEPARATOR);
213 213
         }
214 214
         $Options['filename'] = basename($file);
215
-        if(strpos($Options['filename'],'.')!==false)
215
+        if (strpos($Options['filename'], '.') !== false)
216 216
             $Options['driver'] = strtoupper(pathinfo($Options['filename'], PATHINFO_EXTENSION));
217 217
         else
218
-            $Options['filename']= $Options['filename'].'.'.strtolower($default['driver']);
219
-	     if(!in_array($Options['driver'],$this->availableDrivers))
218
+            $Options['filename'] = $Options['filename'].'.'.strtolower($default['driver']);
219
+	     if (!in_array($Options['driver'], $this->availableDrivers))
220 220
             throw new Exception('ERROR: driver "'.$Options['driver'].'" not supported');
221
-	    $this->Options = array_merge($default,$Options);
221
+	    $this->Options = array_merge($default, $Options);
222 222
         return $this->Options;
223 223
     }
224 224
     /**
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
      */
229 229
     private function normalize($path, $relativeTo = null) {
230 230
         $path = rtrim(preg_replace('#[/\\\\]+#', DIRECTORY_SEPARATOR, $path), DIRECTORY_SEPARATOR);
231
-        $isAbsolute = stripos(PHP_OS, 'win')===0 ? preg_match('/^[A-Za-z]+:/', $path): !strncmp($path, DIRECTORY_SEPARATOR, 1);
231
+        $isAbsolute = stripos(PHP_OS, 'win') === 0 ? preg_match('/^[A-Za-z]+:/', $path) : !strncmp($path, DIRECTORY_SEPARATOR, 1);
232 232
         if (!$isAbsolute)
233 233
         {
234 234
             if (!$relativeTo) $relativeTo = getcwd();
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         while (end($parts) !== false)
242 242
         {
243 243
             array_pop($parts);
244
-            $attempt = stripos(PHP_OS, 'win')===0 ? implode(DIRECTORY_SEPARATOR, $parts): DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts);
244
+            $attempt = stripos(PHP_OS, 'win') === 0 ? implode(DIRECTORY_SEPARATOR, $parts) : DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts);
245 245
             if ($realpaths = realpath($attempt))
246 246
             {
247 247
                 $path = $realpaths.substr($path, strlen($attempt));
@@ -254,14 +254,14 @@  discard block
 block discarded – undo
254 254
      * @param array $options
255 255
      * @return mixed
256 256
      */
257
-    private function parseConfiguration($options=[])
257
+    private function parseConfiguration($options = [])
258 258
     {
259 259
 
260 260
         try
261 261
         {  $this->targetFile = $this->normalize($options['directory'].DIRECTORY_SEPARATOR.$options['filename']);
262
-            if(!file_exists($this->targetFile))
263
-                file_put_contents($this->targetFile,'',LOCK_EX);
264
-            switch($this->Options['driver'])
262
+            if (!file_exists($this->targetFile))
263
+                file_put_contents($this->targetFile, '', LOCK_EX);
264
+            switch ($this->Options['driver'])
265 265
             {
266 266
                 case 'JSON':
267 267
                     $this->Config = unserialize(json_decode(file_get_contents($this->targetFile), true));
@@ -270,17 +270,17 @@  discard block
 block discarded – undo
270 270
                     $this->Config = parse_ini_file($this->targetFile, true);
271 271
                     break;
272 272
                 case 'YML':
273
-                    $ndocs=0;
274
-                    $this->Config = yaml_parse_file($this->targetFile,0,$ndocs);
273
+                    $ndocs = 0;
274
+                    $this->Config = yaml_parse_file($this->targetFile, 0, $ndocs);
275 275
                     break;
276 276
                 default:
277
-                    if(!$this->Config = include $this->targetFile) $this->Config = [];
277
+                    if (!$this->Config = include $this->targetFile) $this->Config = [];
278 278
                     break;
279 279
             }
280 280
         }
281
-        catch(Exception $b)
281
+        catch (Exception $b)
282 282
         {
283
-            trigger_error($b->getMessage(),E_USER_ERROR);
283
+            trigger_error($b->getMessage(), E_USER_ERROR);
284 284
         }
285 285
         return $this->Config;
286 286
     }
@@ -289,9 +289,9 @@  discard block
 block discarded – undo
289 289
      */
290 290
      private function Save()
291 291
     {
292
-        if( !is_writeable( $this->targetFile ) ) @chmod($this->targetFile,0775);
292
+        if (!is_writeable($this->targetFile)) @chmod($this->targetFile, 0775);
293 293
         $content = null;
294
-        switch($this->Options['driver'])
294
+        switch ($this->Options['driver'])
295 295
         {
296 296
             case 'JSON':
297 297
                 $content .= json_encode(serialize($this->Config));
@@ -300,28 +300,28 @@  discard block
 block discarded – undo
300 300
                 $content .= '; @file generator: Iriven France Php "'.get_class($this).'" Class'.PHP_EOL;
301 301
                 $content .= '; @Last Update: '.date('Y-m-d H:i:s').PHP_EOL;
302 302
                 $content .= PHP_EOL;
303
-                foreach($this->Config as $section => $array)
303
+                foreach ($this->Config as $section => $array)
304 304
                 {
305 305
                     is_array($array) or $array = array($array);
306
-                    $content .= '[' . $section . ']'.PHP_EOL;
307
-                    foreach( $array as $key => $value )
306
+                    $content .= '['.$section.']'.PHP_EOL;
307
+                    foreach ($array as $key => $value)
308 308
                         $content .= PHP_TAB.$key.' = '.$value.PHP_EOL;
309 309
                     $content .= PHP_EOL;
310 310
                 }
311 311
                 break;
312 312
             case 'YML':
313
-                $content .= yaml_emit ($this->Config, YAML_UTF8_ENCODING , YAML_LN_BREAK );
313
+                $content .= yaml_emit($this->Config, YAML_UTF8_ENCODING, YAML_LN_BREAK);
314 314
                 break;
315 315
             default:
316 316
                 $content .= '<?php'.PHP_EOL;
317 317
                 $content .= 'return ';
318
-                $content .= var_export($this->Config, true) . ';';
318
+                $content .= var_export($this->Config, true).';';
319 319
                 $content = preg_replace('/array\s+\(/', '[', $content);
320 320
                 $content = preg_replace('/,(\s+)\)/', '$1]', $content);
321 321
                 break;
322 322
         }
323 323
         file_put_contents($this->targetFile, $content, LOCK_EX);
324
-        @chmod($this->targetFile,0644);
324
+        @chmod($this->targetFile, 0644);
325 325
         return true;
326 326
     }
327 327
     /**
Please login to merge, or discard this patch.
Braces   +110 added lines, -64 removed lines patch added patch discarded remove patch
@@ -37,13 +37,13 @@  discard block
 block discarded – undo
37 37
         $numargs = func_num_args();
38 38
         try
39 39
         {
40
-            if($numargs > 2)
41
-                throw new Exception('SETUP ERROR: configuration manager can accept only up to 2 parameters,'.$numargs.' given!');
40
+            if($numargs > 2) {
41
+                            throw new Exception('SETUP ERROR: configuration manager can accept only up to 2 parameters,'.$numargs.' given!');
42
+            }
42 43
             $this->configureOptions($filename,$location);
43 44
             $this->parseConfiguration($this->Options);
44 45
             return $this;
45
-        }
46
-        catch(Exception $a)
46
+        } catch(Exception $a)
47 47
         {
48 48
             trigger_error($a->getMessage(),E_USER_ERROR);
49 49
         }
@@ -55,10 +55,18 @@  discard block
 block discarded – undo
55 55
      */
56 56
     public function get($section=null, $item=null)
57 57
     {
58
-        if($item) $item = trim(strtolower($item));
59
-        if($section) $section = trim(strtolower($section));
60
-        if(!count($this->Config)) return false;
61
-        if(!$section or !strlen($section)) return $this->Config;
58
+        if($item) {
59
+          $item = trim(strtolower($item));
60
+        }
61
+        if($section) {
62
+          $section = trim(strtolower($section));
63
+        }
64
+        if(!count($this->Config)) {
65
+          return false;
66
+        }
67
+        if(!$section or !strlen($section)) {
68
+          return $this->Config;
69
+        }
62 70
         if($section AND $item)
63 71
         {
64 72
             if(!isset($this->Config[$section]))
@@ -66,18 +74,22 @@  discard block
 block discarded – undo
66 74
                 $key = $item;
67 75
                 $item = $section;
68 76
                 $section = $this->defaultSection;
69
-                if(!isset($this->Config[$section][$item][$key]))
70
-                    return false;
77
+                if(!isset($this->Config[$section][$item][$key])) {
78
+                                    return false;
79
+                }
71 80
                 return $this->Config[$section][$item][$key];
72 81
             }
73
-        }
74
-        elseif(!$item or !strlen($item))
82
+        } elseif(!$item or !strlen($item))
75 83
         {
76 84
             $item = $section;
77
-            if(isset($this->Config[$item])) return $this->Config[$item];
85
+            if(isset($this->Config[$item])) {
86
+              return $this->Config[$item];
87
+            }
78 88
             $section = $this->defaultSection;
79 89
         }
80
-        if(!isset($this->Config[$section][$item])) return false;
90
+        if(!isset($this->Config[$section][$item])) {
91
+          return false;
92
+        }
81 93
         return $this->Config[$section][$item];
82 94
     }
83 95
 
@@ -95,14 +107,17 @@  discard block
 block discarded – undo
95 107
         switch($numarg)
96 108
         {
97 109
             case 1:
98
-                if(!is_array($arguments[0])) return false;
110
+                if(!is_array($arguments[0])) {
111
+                  return false;
112
+                }
99 113
                 $item=array_change_key_case($arguments[0], CASE_LOWER); $section=null; $value=null;	
100 114
 		break;
101 115
             case 2:
102
-                if(is_array($arguments[0])) return false;
116
+                if(is_array($arguments[0])) {
117
+                  return false;
118
+                }
103 119
                 $_arg = strtolower(trim($arguments[0]));
104
-                if(is_array($arguments[1])){ $section=$_arg; $item =array_change_key_case($arguments[1], CASE_LOWER);$value=null;}
105
-                else {$item = $_arg;$value=$arguments[1];$section=null;}
120
+                if(is_array($arguments[1])){ $section=$_arg; $item =array_change_key_case($arguments[1], CASE_LOWER);$value=null;} else {$item = $_arg;$value=$arguments[1];$section=null;}
106 121
                 break;
107 122
             default:
108 123
                 break;
@@ -110,18 +125,23 @@  discard block
 block discarded – undo
110 125
         $section = $section? trim(strtolower($section)) : $this->defaultSection;
111 126
         if(!is_array($item))
112 127
         {
113
-            if(!$value) return false;
128
+            if(!$value) {
129
+              return false;
130
+            }
114 131
             $item=trim(strtolower($item));
115 132
             if(!isset($this->Config[$section][$item]) or !is_array($this->Config[$section][$item])):
116 133
                 $this->Config[$section][$item]=$value;
117
-            else:
134
+            else {
135
+              :
118 136
                 if(!is_array($value)) $value = array($value);
137
+            }
119 138
                 $this->Config[$section][$item] = array_merge($this->Config[$section][$item],$value);
120 139
             endif;
121
-        }
122
-        else
140
+        } else
123 141
         {
124
-            if($value) return false;
142
+            if($value) {
143
+              return false;
144
+            }
125 145
             $item = array_change_key_case($item, CASE_LOWER);
126 146
             $sectionsize = count($this->Config[$section]);
127 147
             $itemsize = count($item);
@@ -129,13 +149,17 @@  discard block
 block discarded – undo
129 149
             {
130 150
                 if($itemsize=='1')
131 151
                 {
132
-                    if(isset($this->Config[$section][key($item)]))
133
-                        $this->Config[$section][key($item)] = array_merge($this->Config[$section][key($item)],$item[key($item)]);
134
-                    else if(!is_numeric(key($item))) $this->Config[$section][key($item)]=$item[key($item)];
152
+                    if(isset($this->Config[$section][key($item)])) {
153
+                                            $this->Config[$section][key($item)] = array_merge($this->Config[$section][key($item)],$item[key($item)]);
154
+                    } else if(!is_numeric(key($item))) {
155
+                      $this->Config[$section][key($item)]=$item[key($item)];
156
+                    }
157
+                } else {
158
+                  $this->Config[$section] = array_merge($this->Config[$section],$item);
135 159
                 }
136
-                else $this->Config[$section] = array_merge($this->Config[$section],$item);
160
+            } else {
161
+              $this->Config[$section] = $item;
137 162
             }
138
-            else $this->Config[$section] = $item;
139 163
         }
140 164
         $re = $this->Save();
141 165
         ob_end_clean();
@@ -160,21 +184,25 @@  discard block
 block discarded – undo
160 184
                 if(isset($this->Config[$section][$item][$key]))
161 185
                 {
162 186
                     $itemSize=count($this->Config[$section][$item]);
163
-                    if($itemSize>1) unset($this->Config[$section][$item][$key]);
164
-                    else unset($this->Config[$section]);
187
+                    if($itemSize>1) {
188
+                      unset($this->Config[$section][$item][$key]);
189
+                    } else {
190
+                      unset($this->Config[$section]);
191
+                    }
165 192
                 }
166
-            }
167
-            else
193
+            } else
168 194
             {
169 195
                 $sectionSize=count($this->Config[$section]);
170 196
                 if(isset($this->Config[$section][$item]))
171 197
                 {
172
-                    if($sectionSize>1) unset($this->Config[$section][$item]);
173
-                    else unset($this->Config[$section]);
198
+                    if($sectionSize>1) {
199
+                      unset($this->Config[$section][$item]);
200
+                    } else {
201
+                      unset($this->Config[$section]);
202
+                    }
174 203
                 }
175 204
             } 
176
-        }
177
-        else
205
+        } else
178 206
         {
179 207
             $item = $section;
180 208
             if(!isset($this->Config[$item]))
@@ -183,11 +211,15 @@  discard block
 block discarded – undo
183 211
                 $defaultSectionSize = count($this->Config[$section]);
184 212
                 if(isset($this->Config[$section][$item]))
185 213
                 {
186
-                    if($defaultSectionSize>1) unset($this->Config[$section][$item]);
187
-                    else unset($this->Config[$section]);
214
+                    if($defaultSectionSize>1) {
215
+                      unset($this->Config[$section][$item]);
216
+                    } else {
217
+                      unset($this->Config[$section]);
218
+                    }
188 219
                 }
220
+            } else {
221
+              unset($this->Config[$item]);
189 222
             }
190
-            else unset($this->Config[$item]);
191 223
         }
192 224
         return $this->Save();
193 225
     }
@@ -197,27 +229,31 @@  discard block
 block discarded – undo
197 229
      * @return array|bool
198 230
      */
199 231
     private function configureOptions($file,$location=null){
200
-        if(!is_string($file) or ($location and !is_string($location)))
201
-            throw new Exception('SETUP ERROR: configuration manager can accept string only parameters');
232
+        if(!is_string($file) or ($location and !is_string($location))) {
233
+                    throw new Exception('SETUP ERROR: configuration manager can accept string only parameters');
234
+        }
202 235
         $default=[
203 236
             'driver' => 'PHP',
204 237
             'filename' => null,
205 238
             'directory' => __DIR__,
206 239
         ];
207 240
         $Options = [];
208
-        if($location)
209
-            $Options['directory']=rtrim($this->normalize($location),DIRECTORY_SEPARATOR);
210
-        else{
211
-            if(basename($file)!==$file)
212
-                $Options['directory']= rtrim($this->normalize(pathinfo($file,PATHINFO_DIRNAME)),DIRECTORY_SEPARATOR);
241
+        if($location) {
242
+                    $Options['directory']=rtrim($this->normalize($location),DIRECTORY_SEPARATOR);
243
+        } else{
244
+            if(basename($file)!==$file) {
245
+                            $Options['directory']= rtrim($this->normalize(pathinfo($file,PATHINFO_DIRNAME)),DIRECTORY_SEPARATOR);
246
+            }
213 247
         }
214 248
         $Options['filename'] = basename($file);
215
-        if(strpos($Options['filename'],'.')!==false)
216
-            $Options['driver'] = strtoupper(pathinfo($Options['filename'], PATHINFO_EXTENSION));
217
-        else
218
-            $Options['filename']= $Options['filename'].'.'.strtolower($default['driver']);
219
-	     if(!in_array($Options['driver'],$this->availableDrivers))
220
-            throw new Exception('ERROR: driver "'.$Options['driver'].'" not supported');
249
+        if(strpos($Options['filename'],'.')!==false) {
250
+                    $Options['driver'] = strtoupper(pathinfo($Options['filename'], PATHINFO_EXTENSION));
251
+        } else {
252
+                    $Options['filename']= $Options['filename'].'.'.strtolower($default['driver']);
253
+        }
254
+	     if(!in_array($Options['driver'],$this->availableDrivers)) {
255
+	                 throw new Exception('ERROR: driver "'.$Options['driver'].'" not supported');
256
+	     }
221 257
 	    $this->Options = array_merge($default,$Options);
222 258
         return $this->Options;
223 259
     }
@@ -231,12 +267,17 @@  discard block
 block discarded – undo
231 267
         $isAbsolute = stripos(PHP_OS, 'win')===0 ? preg_match('/^[A-Za-z]+:/', $path): !strncmp($path, DIRECTORY_SEPARATOR, 1);
232 268
         if (!$isAbsolute)
233 269
         {
234
-            if (!$relativeTo) $relativeTo = getcwd();
270
+            if (!$relativeTo) {
271
+              $relativeTo = getcwd();
272
+            }
235 273
             $path = $relativeTo.DIRECTORY_SEPARATOR.$path;
236 274
         }
237
-        if (is_link($path) and ($parentPath = realpath(dirname($path))))
238
-            return $parentPath.DIRECTORY_SEPARATOR.$path;
239
-        if ($realpath = realpath($path))  return $realpath;
275
+        if (is_link($path) and ($parentPath = realpath(dirname($path)))) {
276
+                    return $parentPath.DIRECTORY_SEPARATOR.$path;
277
+        }
278
+        if ($realpath = realpath($path)) {
279
+          return $realpath;
280
+        }
240 281
         $parts = explode(DIRECTORY_SEPARATOR, trim($path, DIRECTORY_SEPARATOR));
241 282
         while (end($parts) !== false)
242 283
         {
@@ -259,8 +300,9 @@  discard block
 block discarded – undo
259 300
 
260 301
         try
261 302
         {  $this->targetFile = $this->normalize($options['directory'].DIRECTORY_SEPARATOR.$options['filename']);
262
-            if(!file_exists($this->targetFile))
263
-                file_put_contents($this->targetFile,'',LOCK_EX);
303
+            if(!file_exists($this->targetFile)) {
304
+                            file_put_contents($this->targetFile,'',LOCK_EX);
305
+            }
264 306
             switch($this->Options['driver'])
265 307
             {
266 308
                 case 'JSON':
@@ -274,11 +316,12 @@  discard block
 block discarded – undo
274 316
                     $this->Config = yaml_parse_file($this->targetFile,0,$ndocs);
275 317
                     break;
276 318
                 default:
277
-                    if(!$this->Config = include $this->targetFile) $this->Config = [];
319
+                    if(!$this->Config = include $this->targetFile) {
320
+                      $this->Config = [];
321
+                    }
278 322
                     break;
279 323
             }
280
-        }
281
-        catch(Exception $b)
324
+        } catch(Exception $b)
282 325
         {
283 326
             trigger_error($b->getMessage(),E_USER_ERROR);
284 327
         }
@@ -289,7 +332,9 @@  discard block
 block discarded – undo
289 332
      */
290 333
      private function Save()
291 334
     {
292
-        if( !is_writeable( $this->targetFile ) ) @chmod($this->targetFile,0775);
335
+        if( !is_writeable( $this->targetFile ) ) {
336
+          @chmod($this->targetFile,0775);
337
+        }
293 338
         $content = null;
294 339
         switch($this->Options['driver'])
295 340
         {
@@ -304,8 +349,9 @@  discard block
 block discarded – undo
304 349
                 {
305 350
                     is_array($array) or $array = array($array);
306 351
                     $content .= '[' . $section . ']'.PHP_EOL;
307
-                    foreach( $array as $key => $value )
308
-                        $content .= PHP_TAB.$key.' = '.$value.PHP_EOL;
352
+                    foreach( $array as $key => $value ) {
353
+                                            $content .= PHP_TAB.$key.' = '.$value.PHP_EOL;
354
+                    }
309 355
                     $content .= PHP_EOL;
310 356
                 }
311 357
                 break;
Please login to merge, or discard this patch.