From f79395851b044689567e0e6c9504acbcaa742782 Mon Sep 17 00:00:00 2001 From: Benjamin Southall Date: Tue, 26 Feb 2019 10:11:12 +1000 Subject: Twig update to latest Twig 1.x legacy as per vichan --- inc/lib/Twig/Node.php | 124 +++++++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 47 deletions(-) (limited to 'inc/lib/Twig/Node.php') diff --git a/inc/lib/Twig/Node.php b/inc/lib/Twig/Node.php index 931b4635..89ada144 100644 --- a/inc/lib/Twig/Node.php +++ b/inc/lib/Twig/Node.php @@ -3,8 +3,8 @@ /* * This file is part of Twig. * - * (c) 2009 Fabien Potencier - * (c) 2009 Armin Ronacher + * (c) Fabien Potencier + * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -22,19 +22,26 @@ class Twig_Node implements Twig_NodeInterface protected $lineno; protected $tag; + private $name; + /** * 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 + * @param array $nodes An array of named nodes + * @param array $attributes An array of attributes (should not be nodes) + * @param int $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) { + foreach ($nodes as $name => $node) { + if (!$node instanceof Twig_NodeInterface) { + @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); + } + } $this->nodes = $nodes; $this->attributes = $attributes; $this->lineno = $lineno; @@ -69,8 +76,13 @@ class Twig_Node implements Twig_NodeInterface return implode("\n", $repr); } + /** + * @deprecated since 1.16.1 (to be removed in 2.0) + */ public function toXml($asDom = false) { + @trigger_error(sprintf('%s is deprecated since version 1.16.1 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED); + $dom = new DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; $dom->appendChild($xml = $dom->createElement('twig')); @@ -96,7 +108,7 @@ class Twig_Node implements Twig_NodeInterface $node->appendChild($child); } - return $asDom ? $dom : $dom->saveXml(); + return $asDom ? $dom : $dom->saveXML(); } public function compile(Twig_Compiler $compiler) @@ -106,8 +118,18 @@ class Twig_Node implements Twig_NodeInterface } } + public function getTemplateLine() + { + return $this->lineno; + } + + /** + * @deprecated since 1.27 (to be removed in 2.0) + */ public function getLine() { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateLine() instead.', E_USER_DEPRECATED); + return $this->lineno; } @@ -117,11 +139,7 @@ class Twig_Node implements Twig_NodeInterface } /** - * Returns true if the attribute is defined. - * - * @param string The attribute name - * - * @return Boolean true if the attribute is defined, false otherwise + * @return bool */ public function hasAttribute($name) { @@ -129,11 +147,7 @@ class Twig_Node implements Twig_NodeInterface } /** - * Gets an attribute. - * - * @param string The attribute name - * - * @return mixed The attribute value + * @return mixed */ public function getAttribute($name) { @@ -145,32 +159,21 @@ class Twig_Node implements Twig_NodeInterface } /** - * Sets an attribute. - * - * @param string The attribute name - * @param mixed The attribute value + * @param string $name + * @param mixed $value */ public function setAttribute($name, $value) { $this->attributes[$name] = $value; } - /** - * Removes an attribute. - * - * @param string The attribute name - */ public function removeAttribute($name) { unset($this->attributes[$name]); } /** - * Returns true if the node with the given identifier exists. - * - * @param string The node name - * - * @return Boolean true if the node with the given name exists, false otherwise + * @return bool */ public function hasNode($name) { @@ -178,11 +181,7 @@ class Twig_Node implements Twig_NodeInterface } /** - * Gets a node by name. - * - * @param string The node name - * - * @return Twig_Node A Twig_Node instance + * @return Twig_Node */ public function getNode($name) { @@ -193,22 +192,15 @@ class Twig_Node implements Twig_NodeInterface return $this->nodes[$name]; } - /** - * Sets a node. - * - * @param string The node name - * @param Twig_Node A Twig_Node instance - */ public function setNode($name, $node = null) { + if (!$node instanceof Twig_NodeInterface) { + @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); + } + $this->nodes[$name] = $node; } - /** - * Removes a node by name. - * - * @param string The node name - */ public function removeNode($name) { unset($this->nodes[$name]); @@ -223,4 +215,42 @@ class Twig_Node implements Twig_NodeInterface { return new ArrayIterator($this->nodes); } + + public function setTemplateName($name) + { + $this->name = $name; + foreach ($this->nodes as $node) { + if (null !== $node) { + $node->setTemplateName($name); + } + } + } + + public function getTemplateName() + { + return $this->name; + } + + /** + * @deprecated since 1.27 (to be removed in 2.0) + */ + public function setFilename($name) + { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use setTemplateName() instead.', E_USER_DEPRECATED); + + $this->setTemplateName($name); + } + + /** + * @deprecated since 1.27 (to be removed in 2.0) + */ + public function getFilename() + { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateName() instead.', E_USER_DEPRECATED); + + return $this->name; + } } + +class_alias('Twig_Node', 'Twig\Node\Node', false); +class_exists('Twig_Compiler'); -- cgit v1.3