public function render(array $ini)
    {
        $output = [];

        foreach ($ini as $sectionName => $section) {
            $sectionOutput = [];

            if (!is_array($section)) {
                throw new RendererException('The section must contain an array of key-value pairs');
            }

            // Values without keys are stored in this temporary array
            $sectionIni = [];

            foreach ($section as $key => $value) {
                if (is_numeric($key)) {
                    if (!is_array($value)) {
                        $value = [$value];
                    }

                    $sectionIni = array_merge($sectionIni, $value);
                    continue;
                }

                $sectionOutput = array_merge($sectionOutput, $this->renderKeyValuePair($key, $value));
            }

            if (count($sectionIni) > 0) {
                $sectionOutput = array_merge($this->renderKeyValuePair($sectionName, $sectionIni), $sectionOutput);
            }

            array_unshift($sectionOutput, sprintf('[%s]', $sectionName));

            // Write a linefeed after sections
            $sectionOutput[] = '';

            $output = array_merge($output, $sectionOutput);
        }

        return implode("\n", $output);
    }
public function render(array $ini)
    {
        $output = [];

        foreach ($ini as $sectionName => $section) {
            $sectionOutput = [];

            if (!is_array($section)) {
                throw new RendererException('The section must contain an array of key-value pairs');
            }

            // Values without keys are stored in this temporary array
            $sectionIni = [];

            foreach ($section as $key => $value) {
                if (is_numeric($key)) {
                    if (!is_array($value)) {
                        $value = [$value];
                    }

                    $sectionIni = array_merge($sectionIni, $value);
                    continue;
                }

                $sectionOutput = array_merge($sectionOutput, $this->renderKeyValuePair($key, $value));
            }

            if (count($sectionIni) > 0) {
                $sectionOutput = array_merge($this->renderKeyValuePair($sectionName, $sectionIni), $sectionOutput);
            }

            array_unshift($sectionOutput, sprintf('[%s]', $sectionName));

            // Write a linefeed after sections
            $sectionOutput[] = '';

            $output = array_merge($output, $sectionOutput);
        }

        return implode("\n", $output);
    }
public function render ( array $ ini ) { $ output = [ ] ; foreach ( $ ini as $ sectionName => $ section ) { $ sectionOutput = [ ] ; if ( ! is_array ( $ section ) ) { throw new RendererException ( 'The section must contain an array of key-value pairs' ) ; } // Values without keys are stored in this temporary array $ sectionIni = [ ] ; foreach ( $ section as $ key => $ value ) { if ( is_numeric ( $ key ) ) { if ( ! is_array ( $ value ) ) { $ value = [ $ value ] ; } $ sectionIni = array_merge ( $ sectionIni , $ value ) ; continue ; } $ sectionOutput = array_merge ( $ sectionOutput , $ this -> renderKeyValuePair ( $ key , $ value ) ) ; } if ( count ( $ sectionIni ) > 0 ) { $ sectionOutput = array_merge ( $ this -> renderKeyValuePair ( $ sectionName , $ sectionIni ) , $ sectionOutput ) ; } array_unshift ( $ sectionOutput , sprintf ( '[%s]' , $ sectionName ) ) ; // Write a linefeed after sections $ sectionOutput [ ] = '' ; $ output = array_merge ( $ output , $ sectionOutput ) ; } return implode ( "\n" , $ output ) ; }
Renders an INI configuration.

@param array $ini

@return string
Renders an INI configuration .