/** * Searches for curly brackets, HTML tags and attributes. * @param string * @return string */ private function parse($s) { $this->input = & $s; $this->offset = 0; $this->output = ''; $this->tags = array(); $len = strlen($s); while ($this->offset < $len) { $matches = $this->{"context$this->context"}(); if (!$matches) { // EOF break; } elseif (!empty($matches['comment'])) { // {* *} } elseif (!empty($matches['macro'])) { // {macro} $code = $this->handler->macro($matches['macro']); if ($code === FALSE) { throw new LatteException("Unknown macro {{$matches['macro']}}", 0, $this->line); } $nl = isset($matches['newline']) ? "\n" : ''; if ($nl && $matches['indent'] && strncmp($code, '<?php echo ', 11)) { // the only macro on line "without" output $this->output .= "\n" . $code; // preserve new line from 'indent', remove indentation } else { $this->output .= $matches['indent'] . $code . (substr($code, -2) === '?>' ? $nl : ''); // double newline to avoid newline eating by PHP } } else { // common behaviour $this->output .= $matches[0]; } } foreach ($this->tags as $tag) { if (!$tag->isMacro && !empty($tag->attrs)) { throw new LatteException("Missing end tag </$tag->name> for macro-attribute " . self::HTML_PREFIX . implode(' and ' . self::HTML_PREFIX, array_keys($tag->attrs)) . ".", 0, $this->line); } } return $this->output . substr($this->input, $this->offset); }
/** * Searches for curly brackets, HTML tags and attributes. * @param string * @return string */ private function parse($s) { $this->input =& $s; $this->offset = 0; $this->output = ''; $this->tags = array(); $len = strlen($s); while ($this->offset < $len) { $matches = $this->{"context{$this->context}"}(); if (!$matches) { // EOF break; } elseif (!empty($matches['macro'])) { // {macro|modifiers} preg_match('#^(/?[a-z]+)?(.*?)(\\|[a-z](?:' . self::RE_STRING . '|[^\'"]+)*)?$()#is', $matches['macro'], $m2); list(, $macro, $value, $modifiers) = $m2; $code = $this->handler->macro($macro, trim($value), isset($modifiers) ? $modifiers : ''); if ($code === NULL) { throw new InvalidStateException("Unknown macro {{$matches['macro']}} on line {$this->line}."); } $nl = isset($matches['newline']) ? "\n" : ''; // double newline if ($nl && $matches['indent'] && strncmp($code, '<?php echo ', 11)) { $this->output .= "\n" . $code; // remove indent, single newline } else { $this->output .= $matches['indent'] . $code . (substr($code, -2) === '?>' ? $nl : ''); } } else { // common behaviour $this->output .= $matches[0]; } } foreach ($this->tags as $tag) { if (!$tag->isMacro && !empty($tag->attrs)) { throw new InvalidStateException("Missing end tag </{$tag->name}> for macro-attribute " . self::HTML_PREFIX . implode(' and ' . self::HTML_PREFIX, array_keys($tag->attrs)) . "."); } } return $this->output . substr($this->input, $this->offset); }