private function buildTree(string $originalValue, array $tokens): array
    {
        $tree = [];
        $functions = [];

        foreach ($tokens as $key => $value) {
            if ($this->tokenizer->isOpeningToken($value)) {
                $functions[$key] = null;    // The value here is ignored

                continue;
            }

            if ($this->tokenizer->isClosingToken($value)) {
                if (false === $this->tokenizer->isTheLastFunction($functions)) {
                    end($functions);
                    $lastFunctionKey = key($functions);
                    if (null === $lastFunctionKey) {
                        throw ExpressionLanguageExceptionFactory::createForMalformedFunction($originalValue);
                    }

                    unset($functions[$lastFunctionKey]);

                    continue;
                }

                end($functions);
                $lastFunctionKey = key($functions);
                $this->append($tree, $tokens, $lastFunctionKey, $key);
                unset($functions[$lastFunctionKey]);

                continue;
            }

            if ($this->tokenizer->functionIsNotClosed($functions)) {
                continue;
            }

            $tree[] = $value;
        }

        if ([] !== $functions) {
            throw ExpressionLanguageExceptionFactory::createForMalformedFunction($originalValue);
        }

        return $tree;
    }
private function buildTree(string $originalValue, array $tokens): array
    {
        $tree = [];
        $functions = [];

        foreach ($tokens as $key => $value) {
            if ($this->tokenizer->isOpeningToken($value)) {
                $functions[$key] = null;    // The value here is ignored

                continue;
            }

            if ($this->tokenizer->isClosingToken($value)) {
                if (false === $this->tokenizer->isTheLastFunction($functions)) {
                    end($functions);
                    $lastFunctionKey = key($functions);
                    if (null === $lastFunctionKey) {
                        throw ExpressionLanguageExceptionFactory::createForMalformedFunction($originalValue);
                    }

                    unset($functions[$lastFunctionKey]);

                    continue;
                }

                end($functions);
                $lastFunctionKey = key($functions);
                $this->append($tree, $tokens, $lastFunctionKey, $key);
                unset($functions[$lastFunctionKey]);

                continue;
            }

            if ($this->tokenizer->functionIsNotClosed($functions)) {
                continue;
            }

            $tree[] = $value;
        }

        if ([] !== $functions) {
            throw ExpressionLanguageExceptionFactory::createForMalformedFunction($originalValue);
        }

        return $tree;
    }
private function buildTree ( string $ originalValue , array $ tokens ) : array { $ tree = [ ] ; $ functions = [ ] ; foreach ( $ tokens as $ key => $ value ) { if ( $ this -> tokenizer -> isOpeningToken ( $ value ) ) { $ functions [ $ key ] = null ; // The value here is ignored continue ; } if ( $ this -> tokenizer -> isClosingToken ( $ value ) ) { if ( false === $ this -> tokenizer -> isTheLastFunction ( $ functions ) ) { end ( $ functions ) ; $ lastFunctionKey = key ( $ functions ) ; if ( null === $ lastFunctionKey ) { throw ExpressionLanguageExceptionFactory :: createForMalformedFunction ( $ originalValue ) ; } unset ( $ functions [ $ lastFunctionKey ] ) ; continue ; } end ( $ functions ) ; $ lastFunctionKey = key ( $ functions ) ; $ this -> append ( $ tree , $ tokens , $ lastFunctionKey , $ key ) ; unset ( $ functions [ $ lastFunctionKey ] ) ; continue ; } if ( $ this -> tokenizer -> functionIsNotClosed ( $ functions ) ) { continue ; } $ tree [ ] = $ value ; } if ( [ ] !== $ functions ) { throw ExpressionLanguageExceptionFactory :: createForMalformedFunction ( $ originalValue ) ; } return $ tree ; }
Regroup tokens together by detecting when the function starts, closes or when it is nested.
Regroup tokens together by detecting when the function starts closes or when it is nested .