1 <?php
2 /**
3 * Class file.
4 *
5 * @author Tobias Munk <schmunk@usrbin.de>
6 * @link http://www.phundament.com/
7 * @copyright Copyright © 2005-2011 diemeisterei GmbH
8 * @license http://www.phundament.com/license/
9 */
10
11 /**
12 * Configuration helper, reads files or arrays, skips missing files without
13 * throwing errors if file is not found
14 *
15 * Based upon http://www.yiiframework.com/doc/guide/1.1/en/database.migration#c2550 from Leric
16 *
17 * @author Tobias Munk <schmunk@usrbin.de>
18 * @package p3extensions.components
19 * @since 3.0.1
20 */
21 class P3Configuration {
22
23 public $scanDirectories;
24 private $_config;
25
26 public function __construct($directories) {
27 $this->scanDirectories = $directories;
28 }
29
30 private function scan(){
31 foreach($this->scanDirectories AS $dir){
32 if (is_array($dir)) {
33 $config = $dir;
34 } elseif (is_file($dir)) {
35 $config = require($dir);
36 } else {
37 Yii::log('Configuration file '.$dir.' not found');
38 continue;
39 }
40 $this->_config = CMap::mergeArray($this->_config, $config);
41 }
42 }
43
44 function toArray() {
45 $this->scan();
46 return $this->_config;
47 }
48
49 }
50
51 ?>
52