src/Helpers/Token.php
protected function implodeValues($glue, $values)
    {
        $result = '';
        $hasProperty = false;
        $previous = '';
        foreach ($values as $value) {
            if ($value['type'] === self::TypeLiteral) {
                // Literal value: set aside and only add if next property value
                // is not empty.
                if (!empty($previous)) {
                    // Multiple literals after each other: treat as 1 literal
                    // but do glue them together.
                    $previous .= $glue;
                }
                $previous .= $value['value'];
            } else { // $value['type'] === self::TypeProperty
                // Property value: if it is not empty, add any previous literal
                // and the property value itself. If it is empty, discard any
                // previous literal value.
                if (!empty($value['value'])) {
                    if (!empty($previous)) {
                        if (!empty($result)) {
                            $result .= $glue;
                        }
                        $result .= $previous;
                    }
                    if (!empty($result)) {
                        $result .= $glue;
                    }
                    $result .= $value['value'];
                }
                // Discard any previous literal value, used or not.
                $previous = '';
                // Remember that this expression has at least 1 property
                $hasProperty = true;
            }
        }

        // Add a (set of) literal value(s) that came without property or if they
        // came as last value(s) and the result so far is not empty.
        if (!empty($previous) && (!$hasProperty || !empty($result))) {
            if (!empty($result)) {
                $result .= $glue;
            }
            $result .= $previous;
        }

        return array('type' => $hasProperty ? self::TypeProperty : self::TypeLiteral ,'value' => $result);
    }
protected function implodeValues($glue, $values)
    {
        $result = '';
        $hasProperty = false;
        $previous = '';
        foreach ($values as $value) {
            if ($value['type'] === self::TypeLiteral) {
                // Literal value: set aside and only add if next property value
                // is not empty.
                if (!empty($previous)) {
                    // Multiple literals after each other: treat as 1 literal
                    // but do glue them together.
                    $previous .= $glue;
                }
                $previous .= $value['value'];
            } else { // $value['type'] === self::TypeProperty
                // Property value: if it is not empty, add any previous literal
                // and the property value itself. If it is empty, discard any
                // previous literal value.
                if (!empty($value['value'])) {
                    if (!empty($previous)) {
                        if (!empty($result)) {
                            $result .= $glue;
                        }
                        $result .= $previous;
                    }
                    if (!empty($result)) {
                        $result .= $glue;
                    }
                    $result .= $value['value'];
                }
                // Discard any previous literal value, used or not.
                $previous = '';
                // Remember that this expression has at least 1 property
                $hasProperty = true;
            }
        }

        // Add a (set of) literal value(s) that came without property or if they
        // came as last value(s) and the result so far is not empty.
        if (!empty($previous) && (!$hasProperty || !empty($result))) {
            if (!empty($result)) {
                $result .= $glue;
            }
            $result .= $previous;
        }

        return array('type' => $hasProperty ? self::TypeProperty : self::TypeLiteral ,'value' => $result);
    }
protected function implodeValues ( $ glue , $ values ) { $ result = '' ; $ hasProperty = false ; $ previous = '' ; foreach ( $ values as $ value ) { if ( $ value [ 'type' ] === self :: TypeLiteral ) { // Literal value: set aside and only add if next property value // is not empty. if ( ! empty ( $ previous ) ) { // Multiple literals after each other: treat as 1 literal // but do glue them together. $ previous .= $ glue ; } $ previous .= $ value [ 'value' ] ; } else { // $value['type'] === self::TypeProperty // Property value: if it is not empty, add any previous literal // and the property value itself. If it is empty, discard any // previous literal value. if ( ! empty ( $ value [ 'value' ] ) ) { if ( ! empty ( $ previous ) ) { if ( ! empty ( $ result ) ) { $ result .= $ glue ; } $ result .= $ previous ; } if ( ! empty ( $ result ) ) { $ result .= $ glue ; } $ result .= $ value [ 'value' ] ; } // Discard any previous literal value, used or not. $ previous = '' ; // Remember that this expression has at least 1 property $ hasProperty = true ; } } // Add a (set of) literal value(s) that came without property or if they // came as last value(s) and the result so far is not empty. if ( ! empty ( $ previous ) && ( ! $ hasProperty || ! empty ( $ result ) ) ) { if ( ! empty ( $ result ) ) { $ result .= $ glue ; } $ result .= $ previous ; } return array ( 'type' => $ hasProperty ? self :: TypeProperty : self :: TypeLiteral , 'value' => $ result ) ; }
Concatenates a list of values using a glue between them.

Literal strings are only used if they are followed by a non-empty
property value. A literal string at the end is only used if the result so
far is not empty.

@param string $glue
@param array[] $values
A list of type-value pairs.

@return array
Returns a type-value pair containing as value a string representation
of all the values with the glue string between each value.
Concatenates a list of values using a glue between them .