diff --git a/CHANGELOG b/CHANGELOG index 87d05f1797..0e2c51036e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.27.0 (2016-XX-XX) + * deprecated Twig_Compiler::addIndentation() * fixed regression when registering two extensions having the same class name * deprecated Twig_LoaderInterface::getSource() (implement Twig_SourceContextLoaderInterface instead) * fixed the filesystem loader with relative paths diff --git a/doc/deprecated.rst b/doc/deprecated.rst index 6e6229984e..2879fea483 100644 --- a/doc/deprecated.rst +++ b/doc/deprecated.rst @@ -148,6 +148,9 @@ Compiler * As of Twig 1.26, the ``Twig_Compiler::getFilename()`` has been deprecated. You should not use it anyway as its values is not reliable. +* As of Twig 1.27, the ``Twig_Compiler::addIndentation()`` has been deprecated. + Use ``Twig_Compiler::write('')`` instead. + Loaders ------- diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index a33e137464..c39fae6517 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -97,7 +97,7 @@ public function compile(Twig_NodeInterface $node, $indentation = 0) public function subcompile(Twig_NodeInterface $node, $raw = true) { if (false === $raw) { - $this->addIndentation(); + $this->source .= str_repeat(' ', $this->indentation * 4); } $node->compile($this); @@ -128,8 +128,7 @@ public function write() { $strings = func_get_args(); foreach ($strings as $string) { - $this->addIndentation(); - $this->source .= $string; + $this->source .= str_repeat(' ', $this->indentation * 4).$string; } return $this; @@ -139,9 +138,13 @@ public function write() * Appends an indentation to the current PHP code after compilation. * * @return Twig_Compiler The current compiler instance + * + * @deprecated since 1.27 (to be removed in 2.0). */ public function addIndentation() { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use write(\'\') instead.', E_USER_DEPRECATED); + $this->source .= str_repeat(' ', $this->indentation * 4); return $this; diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index 9280e294c7..2d5226a892 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -70,7 +70,7 @@ public function compile(Twig_Compiler $compiler) foreach ($this->getNode('arguments') as $name => $default) { $compiler - ->addIndentation() + ->write('') ->string($name) ->raw(' => $__'.$name.'__') ->raw(",\n") @@ -78,7 +78,7 @@ public function compile(Twig_Compiler $compiler) } $compiler - ->addIndentation() + ->write('') ->string(self::VARARGS_NAME) ->raw(' => ') ;