protected $lineno;
protected $tag;
+ /**
+ * Constructor.
+ *
+ * The nodes are automatically made available as properties ($this->node).
+ * The attributes are automatically made available as array items ($this['name']).
+ *
+ * @param array $nodes An array of named nodes
+ * @param array $attributes An array of attributes (should not be nodes)
+ * @param integer $lineno The line number
+ * @param string $tag The tag name associated with the Node
+ */
public function __construct(array $nodes = array(), array $attributes = array(), $lineno = 0, $tag = null)
{
$this->nodes = array();
*/
public function parse(Twig_TokenStream $stream)
{
- $this->handlers = array();
- $this->visitors = array();
-
// tag handlers
+ $this->handlers = array();
foreach ($this->env->getTokenParsers() as $handler) {
$handler->setParser($this);
}
if (null !== $this->parent) {
- // check that the body only contains block references and empty text nodes
- foreach ($body as $node)
- {
- if (
- ($node instanceof Twig_Node_Text && !preg_match('/^\s*$/s', $node['data']))
- ||
- (!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference)
- ) {
- throw new Twig_SyntaxError('A template that extends another one cannot have a body', $node->getLine(), $this->stream->getFilename());
- }
- }
+ $this->checkBodyNodes($body);
}
$node = new Twig_Node_Module($body, $this->parent, new Twig_Node($this->blocks), new Twig_Node($this->macros), $this->stream->getFilename());
return $traverser->traverse($node);
}
- public function subparse($test, $drop_needle = false)
+ public function subparse($test, $dropNeedle = false)
{
$lineno = $this->getCurrentToken()->getLine();
$rv = array();
}
if (!is_null($test) && call_user_func($test, $token)) {
- if ($drop_needle) {
+ if ($dropNeedle) {
$this->stream->next();
}
{
return $this->stream->getCurrent();
}
+
+ protected function checkBodyNodes($body)
+ {
+ // check that the body only contains block references and empty text nodes
+ foreach ($body as $node)
+ {
+ if (
+ ($node instanceof Twig_Node_Text && !preg_match('/^\s*$/s', $node['data']))
+ ||
+ (!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference)
+ ) {
+ throw new Twig_SyntaxError('A template that extends another one cannot have a body', $node->getLine(), $this->stream->getFilename());
+ }
+ }
+ }
}