Skip to content

Commit

Permalink
feature #2203 deprecated Twig_Compiler::addIndentation() (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.x branch.

Discussion
----------

deprecated Twig_Compiler::addIndentation()

Commits
-------

bc499a4 deprecated Twig_Compiler::addIndentation()
  • Loading branch information
fabpot committed Oct 24, 2016
2 parents 7e5c06a + bc499a4 commit cefaecf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions 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
Expand Down
3 changes: 3 additions & 0 deletions doc/deprecated.rst
Expand Up @@ -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
-------

Expand Down
9 changes: 6 additions & 3 deletions lib/Twig/Compiler.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/Twig/Node/Macro.php
Expand Up @@ -70,15 +70,15 @@ public function compile(Twig_Compiler $compiler)

foreach ($this->getNode('arguments') as $name => $default) {
$compiler
->addIndentation()
->write('')
->string($name)
->raw(' => $__'.$name.'__')
->raw(",\n")
;
}

$compiler
->addIndentation()
->write('')
->string(self::VARARGS_NAME)
->raw(' => ')
;
Expand Down

0 comments on commit cefaecf

Please sign in to comment.