Config_Lite::buildOutputString PHP Method

buildOutputString() protected method

Generated the output of the ini file, suitable for echo'ing or writing back to the ini file.
protected buildOutputString ( array $sectionsarray ) : string
$sectionsarray array array of ini data
return string
    protected function buildOutputString($sectionsarray)
    {
        $content = '';
        $sections = '';
        $globals = '';
        if (!empty($sectionsarray)) {
            // 2 loops to write `globals' on top, alternative: buffer
            foreach ($sectionsarray as $section => $item) {
                if (!is_array($item)) {
                    $value = $this->normalizeValue($item);
                    $globals .= $section . ' = ' . $value . $this->linebreak;
                }
            }
            $content .= $globals;
            foreach ($sectionsarray as $section => $item) {
                if (is_array($item)) {
                    $sections .= $this->linebreak . "[" . $section . "]" . $this->linebreak;
                    foreach ($item as $key => $value) {
                        if (is_array($value)) {
                            foreach ($value as $arrkey => $arrvalue) {
                                $arrvalue = $this->normalizeValue($arrvalue);
                                $arrkey = $key . '[' . $arrkey . ']';
                                $sections .= $arrkey . ' = ' . $arrvalue . $this->linebreak;
                            }
                        } else {
                            $value = $this->normalizeValue($value);
                            $sections .= $key . ' = ' . $value . $this->linebreak;
                        }
                    }
                }
            }
            $content .= $sections;
        }
        return $content;
    }