src/IniParser.php
private function parseSections(array $simple_parsed) {
        // do an initial pass to gather section names
        $sections = array();
        $globals = array();
        foreach ($simple_parsed as $k => $v) {
            if (is_array($v)) {
                // $k is a section name
                $sections[$k] = $v;
            } else {
                $globals[$k] = $v;
            }
        }

        // now for each section, see if it uses inheritance
        $output_sections = array();
        foreach ($sections as $k => $v) {
            $sects = array_map('trim', array_reverse(explode(':', $k)));
            $root = array_pop($sects);
            $arr = $v;
            foreach ($sects as $s) {
                if ($s === '^') {
                    $arr = array_merge($globals, $arr);
                } elseif (array_key_exists($s, $output_sections)) {
                    $arr = array_merge($output_sections[$s], $arr);
                } elseif (array_key_exists($s, $sections)) {
                    $arr = array_merge($sections[$s], $arr);
                } else {
                    throw new UnexpectedValueException("IniParser: In file '{$this->file}', section '{$root}': Cannot inherit from unknown section '{$s}'");
                }
            }

            if ($this->include_original_sections) {
                $output_sections[$k] = $v;
            }
            $output_sections[$root] = $arr;
        }


        return $globals + $output_sections;
    }
private function parseSections(array $simple_parsed) {
        // do an initial pass to gather section names
        $sections = array();
        $globals = array();
        foreach ($simple_parsed as $k => $v) {
            if (is_array($v)) {
                // $k is a section name
                $sections[$k] = $v;
            } else {
                $globals[$k] = $v;
            }
        }

        // now for each section, see if it uses inheritance
        $output_sections = array();
        foreach ($sections as $k => $v) {
            $sects = array_map('trim', array_reverse(explode(':', $k)));
            $root = array_pop($sects);
            $arr = $v;
            foreach ($sects as $s) {
                if ($s === '^') {
                    $arr = array_merge($globals, $arr);
                } elseif (array_key_exists($s, $output_sections)) {
                    $arr = array_merge($output_sections[$s], $arr);
                } elseif (array_key_exists($s, $sections)) {
                    $arr = array_merge($sections[$s], $arr);
                } else {
                    throw new UnexpectedValueException("IniParser: In file '{$this->file}', section '{$root}': Cannot inherit from unknown section '{$s}'");
                }
            }

            if ($this->include_original_sections) {
                $output_sections[$k] = $v;
            }
            $output_sections[$root] = $arr;
        }


        return $globals + $output_sections;
    }
private function parseSections ( array $ simple_parsed ) { // do an initial pass to gather section names $ sections = array ( ) ; $ globals = array ( ) ; foreach ( $ simple_parsed as $ k => $ v ) { if ( is_array ( $ v ) ) { // $k is a section name $ sections [ $ k ] = $ v ; } else { $ globals [ $ k ] = $ v ; } } // now for each section, see if it uses inheritance $ output_sections = array ( ) ; foreach ( $ sections as $ k => $ v ) { $ sects = array_map ( 'trim' , array_reverse ( explode ( ':' , $ k ) ) ) ; $ root = array_pop ( $ sects ) ; $ arr = $ v ; foreach ( $ sects as $ s ) { if ( $ s === '^' ) { $ arr = array_merge ( $ globals , $ arr ) ; } elseif ( array_key_exists ( $ s , $ output_sections ) ) { $ arr = array_merge ( $ output_sections [ $ s ] , $ arr ) ; } elseif ( array_key_exists ( $ s , $ sections ) ) { $ arr = array_merge ( $ sections [ $ s ] , $ arr ) ; } else { throw new UnexpectedValueException ( "IniParser: In file '{$this->file}', section '{$root}': Cannot inherit from unknown section '{$s}'" ) ; } } if ( $ this -> include_original_sections ) { $ output_sections [ $ k ] = $ v ; } $ output_sections [ $ root ] = $ arr ; } return $ globals + $ output_sections ; }
Parse sections and inheritance.
@param  array  $simple_parsed
@return array  Parsed sections
Parse sections and inheritance .