mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 18:36:53 +00:00
deprecated Node::setTemplateName()
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
* 2.8.1 (2019-XX-XX)
|
* 2.8.1 (2019-XX-XX)
|
||||||
|
|
||||||
* n/a
|
* deprecated Node::setTemplateName() in favor of Node::setSourceContext()
|
||||||
|
|
||||||
* 2.8.0 (2019-04-16)
|
* 2.8.0 (2019-04-16)
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ class ModuleNode extends Node
|
|||||||
], 1);
|
], 1);
|
||||||
|
|
||||||
// populate the template name of all node children
|
// populate the template name of all node children
|
||||||
$this->setTemplateName($source->getName());
|
|
||||||
$this->setSourceContext($source);
|
$this->setSourceContext($source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-3
@@ -168,17 +168,25 @@ class Node implements \Countable, \IteratorAggregate
|
|||||||
return new \ArrayIterator($this->nodes);
|
return new \ArrayIterator($this->nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTemplateName($name)
|
/**
|
||||||
|
* @deprecated since 2.8 (to be removed in 3.0)
|
||||||
|
*/
|
||||||
|
public function setTemplateName($name/*, $triggerDeprecation = true */)
|
||||||
{
|
{
|
||||||
|
$triggerDeprecation = 2 > \func_num_args() || \func_get_arg(1);
|
||||||
|
if ($triggerDeprecation) {
|
||||||
|
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use setSourceContext() instead.', E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
foreach ($this->nodes as $node) {
|
foreach ($this->nodes as $node) {
|
||||||
$node->setTemplateName($name);
|
$node->setTemplateName($name, $triggerDeprecation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTemplateName()
|
public function getTemplateName()
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->sourceContext ? $this->sourceContext->getName() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSourceContext(Source $source)
|
public function setSourceContext(Source $source)
|
||||||
@@ -187,6 +195,8 @@ class Node implements \Countable, \IteratorAggregate
|
|||||||
foreach ($this->nodes as $node) {
|
foreach ($this->nodes as $node) {
|
||||||
$node->setSourceContext($source);
|
$node->setSourceContext($source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->setTemplateName($source->getName(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSourceContext()
|
public function getSourceContext()
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use Twig\Node\Expression\FunctionExpression;
|
|||||||
use Twig\Node\IfNode;
|
use Twig\Node\IfNode;
|
||||||
use Twig\Node\Node;
|
use Twig\Node\Node;
|
||||||
use Twig\Test\NodeTestCase;
|
use Twig\Test\NodeTestCase;
|
||||||
|
use Twig\Source;
|
||||||
use Twig\TwigFunction;
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
class Twig_Tests_Node_DeprecatedTest extends NodeTestCase
|
class Twig_Tests_Node_DeprecatedTest extends NodeTestCase
|
||||||
@@ -35,7 +36,7 @@ class Twig_Tests_Node_DeprecatedTest extends NodeTestCase
|
|||||||
|
|
||||||
$expr = new ConstantExpression('This section is deprecated', 1);
|
$expr = new ConstantExpression('This section is deprecated', 1);
|
||||||
$node = new DeprecatedNode($expr, 1, 'deprecated');
|
$node = new DeprecatedNode($expr, 1, 'deprecated');
|
||||||
$node->setTemplateName('foo.twig');
|
$node->setSourceContext(new Source('', 'foo.twig'));
|
||||||
|
|
||||||
$tests[] = [$node, <<<EOF
|
$tests[] = [$node, <<<EOF
|
||||||
// line 1
|
// line 1
|
||||||
@@ -48,7 +49,7 @@ EOF
|
|||||||
new DeprecatedNode($expr, 2, 'deprecated'),
|
new DeprecatedNode($expr, 2, 'deprecated'),
|
||||||
], [], 1);
|
], [], 1);
|
||||||
$node = new IfNode($t, null, 1);
|
$node = new IfNode($t, null, 1);
|
||||||
$node->setTemplateName('foo.twig');
|
$node->setSourceContext(new Source('', 'foo.twig'));
|
||||||
|
|
||||||
$tests[] = [$node, <<<EOF
|
$tests[] = [$node, <<<EOF
|
||||||
// line 1
|
// line 1
|
||||||
@@ -64,7 +65,7 @@ EOF
|
|||||||
|
|
||||||
$expr = new FunctionExpression('foo', new Node(), 1);
|
$expr = new FunctionExpression('foo', new Node(), 1);
|
||||||
$node = new DeprecatedNode($expr, 1, 'deprecated');
|
$node = new DeprecatedNode($expr, 1, 'deprecated');
|
||||||
$node->setTemplateName('foo.twig');
|
$node->setSourceContext(new Source('', 'foo.twig'));
|
||||||
|
|
||||||
$compiler = $this->getCompiler($environment);
|
$compiler = $this->getCompiler($environment);
|
||||||
$varName = $compiler->getVarName();
|
$varName = $compiler->getVarName();
|
||||||
|
|||||||
Reference in New Issue
Block a user