Пример #1
0
 public static function arrayExtend(&$first_array)
 {
     $arrays = func_get_args();
     if (!count($arrays)) {
         \Exception('You must pass in at least one array');
     }
     $array = count($arrays) ? array_shift($arrays) : array();
     $is_assoc = function ($a) {
         if (is_array($a) && count($keys = array_keys($a))) {
             return (bool) (implode(',', $keys) !== implode(',', array_keys($keys)));
         }
         return false;
     };
     $extender = function ($a1, $a2) use($is_assoc) {
         if ($is_assoc($a2)) {
             foreach ($a2 as $key => $value) {
                 if (isset($a1[$key]) && $is_assoc($a1[$key]) && $is_assoc($value)) {
                     $a1[$key] = Utils::arrayExtend($a1[$key], $value);
                 } else {
                     $a1[$key] = $value;
                 }
             }
         } else {
             $a1 = $a2;
         }
         return $a1;
     };
     foreach ($arrays as $extendee) {
         $array = $extender($array, $extendee);
     }
     return $array;
 }
Пример #2
0
 public static function realLoad($_file_path, $values = array(), $imported_config = array(), &$shared_config = array(), $base_config = array(), $basePath = '')
 {
     self::registerDefaultLoaders();
     $file_path = realpath($_file_path);
     if (!$file_path) {
         throw new ConfigFileDoesNotExistException(sprintf('The following configuration file could not be found: %s', $_file_path));
     }
     if (in_array($file_path, $imported_config)) {
         throw new InfiniteConfigIncludeDetectedException(sprintf('The following configuration file has already been included: %s', $file_path));
     }
     $imported_config[] = $file_path;
     // detect loader type required
     $ext = preg_replace('/^.*\\.([a-z]+)$/', '$1', $file_path);
     if (!isset(self::$registered_loaders[$ext])) {
         throw new \Exception(sprintf('Unable to find appropriate loader for config file of type %s: %s', $ext, $file_path));
     }
     // load it
     $data = self::$registered_loaders[$ext]->load($file_path, $values);
     $extended_data = Utils::arrayExtend($base_config, $data);
     // loop through each attribute and resolve any special attrs e.g @extend, @import, %...%
     $data = self::traverseConfig($file_path, $data, $values, $imported_config, $shared_config, $basePath);
     return $data;
 }