public static function serialize($prefix, array $typoscript, $indent = 0)
    {
        $serialized = [];

        // Sort the TypoScript fragment
        ksort($typoscript, SORT_NATURAL);

        // Run through the TypoScript fragment
        foreach ($typoscript as $key => $value) {
            $line = str_repeat(' ', $indent * 4);
            $line .= trim(strlen($prefix) ? "$prefix.$key" : $key, '.');

            // If the value is a list of values
            if (is_array($value)) {

                // If the list has only one element
                if (count($value) === 1) {
                    $line .= '.'.self::serialize('', $value, 0);
                } else {
                    $line .= ' {'.PHP_EOL.self::serialize('', $value, $indent + 1).PHP_EOL.'}';
                }

                // Else if it's a multiline value
            } elseif (preg_match('/\R/', $value)) {
                $line .= ' ('.PHP_EOL.$value.PHP_EOL.')';

                // Else: Simple assignment
            } else {
                $line .= ' = '.$value;
            }
            $serialized[] = $line;
        }

        return implode(PHP_EOL, $serialized);
    }
public static function serialize($prefix, array $typoscript, $indent = 0)
    {
        $serialized = [];

        // Sort the TypoScript fragment
        ksort($typoscript, SORT_NATURAL);

        // Run through the TypoScript fragment
        foreach ($typoscript as $key => $value) {
            $line = str_repeat(' ', $indent * 4);
            $line .= trim(strlen($prefix) ? "$prefix.$key" : $key, '.');

            // If the value is a list of values
            if (is_array($value)) {

                // If the list has only one element
                if (count($value) === 1) {
                    $line .= '.'.self::serialize('', $value, 0);
                } else {
                    $line .= ' {'.PHP_EOL.self::serialize('', $value, $indent + 1).PHP_EOL.'}';
                }

                // Else if it's a multiline value
            } elseif (preg_match('/\R/', $value)) {
                $line .= ' ('.PHP_EOL.$value.PHP_EOL.')';

                // Else: Simple assignment
            } else {
                $line .= ' = '.$value;
            }
            $serialized[] = $line;
        }

        return implode(PHP_EOL, $serialized);
    }
public static function serialize ( $ prefix , array $ typoscript , $ indent = 0 ) { $ serialized = [ ] ; // Sort the TypoScript fragment ksort ( $ typoscript , SORT_NATURAL ) ; // Run through the TypoScript fragment foreach ( $ typoscript as $ key => $ value ) { $ line = str_repeat ( ' ' , $ indent * 4 ) ; $ line .= trim ( strlen ( $ prefix ) ? "$prefix.$key" : $ key , '.' ) ; // If the value is a list of values if ( is_array ( $ value ) ) { // If the list has only one element if ( count ( $ value ) === 1 ) { $ line .= '.' . self :: serialize ( '' , $ value , 0 ) ; } else { $ line .= ' {' . PHP_EOL . self :: serialize ( '' , $ value , $ indent + 1 ) . PHP_EOL . '}' ; } // Else if it's a multiline value } elseif ( preg_match ( '/\R/' , $ value ) ) { $ line .= ' (' . PHP_EOL . $ value . PHP_EOL . ')' ; // Else: Simple assignment } else { $ line .= ' = ' . $ value ; } $ serialized [ ] = $ line ; } return implode ( PHP_EOL , $ serialized ) ; }
Serialize a TypoScript fragment

@param string $prefix    Key prefix
@param array $typoscript TypoScript fragment
@param int $indent       Indentation level

@return string Serialized TypoScript
Serialize a TypoScript fragment