42 @trigger_error(sprintf(
'Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', is_object($node) ? get_class($node) : null === $node ?
'null' : gettype($node),
$name, get_class($this)), E_USER_DEPRECATED);
54 foreach ($this->attributes as
$name => $value) {
55 $attributes[] = sprintf(
'%s: %s',
$name, str_replace(
"\n",
'', var_export($value,
true)));
60 if (
count($this->nodes)) {
61 foreach ($this->nodes as
$name => $node) {
62 $len = strlen(
$name) + 4;
64 foreach (explode(
"\n", (
string) $node) as $line) {
65 $noderepr[] = str_repeat(
' ', $len).$line;
68 $repr[] = sprintf(
' %s: %s',
$name, ltrim(implode(
"\n", $noderepr)));
76 return implode(
"\n", $repr);
82 public function toXml($asDom =
false)
84 @trigger_error(sprintf(
'%s is deprecated since version 1.16.1 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);
87 $dom->formatOutput =
true;
88 $dom->appendChild(
$xml = $dom->createElement(
'twig'));
90 $xml->appendChild($node = $dom->createElement(
'node'));
91 $node->setAttribute(
'class', get_class($this));
93 foreach ($this->attributes as
$name => $value) {
94 $node->appendChild($attribute = $dom->createElement(
'attribute'));
95 $attribute->setAttribute(
'name',
$name);
96 $attribute->appendChild($dom->createTextNode($value));
99 foreach ($this->nodes as
$name =>
$n) {
104 $child =
$n->toXml(
true)->getElementsByTagName(
'node')->item(0);
105 $child = $dom->importNode($child,
true);
106 $child->setAttribute(
'name',
$name);
108 $node->appendChild($child);
111 return $asDom ? $dom : $dom->saveXML();
116 foreach ($this->nodes as $node) {
117 $node->compile($compiler);
131 @trigger_error(
'The '.__METHOD__.
' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateLine() instead.', E_USER_DEPRECATED);
146 return array_key_exists(
$name, $this->attributes);
154 if (!array_key_exists(
$name, $this->attributes)) {
155 throw new LogicException(sprintf(
'Attribute "%s" does not exist for Node "%s".',
$name, get_class($this)));
158 return $this->attributes[
$name];
167 $this->attributes[
$name] = $value;
172 unset($this->attributes[
$name]);
180 return array_key_exists(
$name, $this->nodes);
188 if (!array_key_exists(
$name, $this->nodes)) {
189 throw new LogicException(sprintf(
'Node "%s" does not exist for Node "%s".',
$name, get_class($this)));
192 return $this->nodes[
$name];
198 @trigger_error(sprintf(
'Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', is_object($node) ? get_class($node) : null === $node ?
'null' : gettype($node),
$name, get_class($this)), E_USER_DEPRECATED);
201 $this->nodes[
$name] = $node;
206 unset($this->nodes[
$name]);
211 return count($this->nodes);
222 foreach ($this->nodes as $node) {
223 if (null !== $node) {
224 $node->setTemplateName(
$name);
239 @trigger_error(
'The '.__METHOD__.
' method is deprecated since version 1.27 and will be removed in 2.0. Use setTemplateName() instead.', E_USER_DEPRECATED);
249 @trigger_error(
'The '.__METHOD__.
' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateName() instead.', E_USER_DEPRECATED);
255 class_alias(
'Twig_Node',
'Twig\Node\Node',
false);
256 class_exists(
'Twig_Compiler');
Represents a node in the AST.
Represents a node in the AST.
setNode($name, $node=null)
compile(Twig_Compiler $compiler)
Compiles the node to PHP.
Create styles array
The data for the language used.
__construct(array $nodes=array(), array $attributes=array(), $lineno=0, $tag=null)
Constructor.
setAttribute($name, $value)