/** * Build the token container, parsed from the provided document * * @param string $document Document to parse * @return array Container of nested tokens */ public function buildContainer($document) { // Find the start and end tokens $startRegex = '/(' . $this->delimiters['variable'][0] . '|' . $this->delimiters['block'][0] . ')+/'; $endRegex = '/(' . $this->delimiters['variable'][1] . '|' . $this->delimiters['block'][1] . ')+/'; preg_match_all($startRegex, $document, $start, PREG_OFFSET_CAPTURE + PREG_SET_ORDER); preg_match_all($endRegex, $document, $end, PREG_OFFSET_CAPTURE + PREG_SET_ORDER); // Walk through our matches $match = new Matches($start, $end, $this->delimiters); $result = $match->walk($document); $container = $this->nest($result); return $container; }