Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Lexer\FunctionTokenizer::buildTree PHP Method

buildTree() private method

Regroup tokens together by detecting when the function starts, closes or when it is nested.
private buildTree ( string $originalValue, array $tokens ) : array
$originalValue string
$tokens array
return array
    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;
    }