Config.php (1273B)
1 <?php 2 3 namespace Finwo\Framework\Config; 4 5 use Finwo\DataFile\DataFile; 6 use Finwo\PropertyAccessor\PropertyAccessor; 7 8 class Config 9 { 10 /** 11 * @return PropertyAccessor 12 */ 13 protected static function getAccessor() 14 { 15 static $cache = null; 16 if(is_null($cache)) { 17 $cache = new PropertyAccessor(); 18 } 19 return $cache; 20 } 21 22 /** 23 * @return array 24 */ 25 protected static function &getFull() 26 { 27 static $cache = null; 28 if(is_null($cache)) { 29 // Detect files 30 $files = array(); 31 foreach(Datafile::$supported as $fileType) { 32 $files = array_merge($files, glob( APPROOT . DS . 'config' . DS . '*.' . $fileType)); 33 } 34 // Load them 35 $cache = array(); 36 foreach($files as $file) { 37 $cache = array_merge($cache, DataFile::read($file)); 38 } 39 } 40 return $cache; 41 } 42 43 /** 44 * @param string $key 45 * 46 * @return mixed 47 */ 48 public static function get( $key = null ) 49 { 50 if(is_null($key)) { 51 return self::getFull(); 52 } 53 return self::getAccessor()->getSafe(self::getFull(), $key, '.'); 54 } 55 56 /** 57 * @param string $key 58 * @param string $value 59 */ 60 public static function set( $key, $value ) 61 { 62 self::getAccessor()->set( self::getFull(), $key, $value, '.' ); 63 } 64 }