Skip to content

Commit 5834ba9

Browse files
Merge pull request #5 from tobias-93/master
Update to allow Twig 3, switch to PSR-4
2 parents 840c73e + 7054c6b commit 5834ba9

7 files changed

+37
-31
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
],
2020
"require": {
2121
"php": ">=5.3.0",
22-
"twig/twig": "~1.12||^2.0"
22+
"twig/twig": "~1.40||~2.9||~3.0"
2323
},
2424
"require-dev": {
2525
"phpunit/phpunit": "~4.3"
2626
},
2727
"autoload": {
28-
"psr-0": { "TwigGenerator": "src/" }
28+
"psr-4": { "TwigGenerator\\": "src/" }
2929
}
3030
}

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<filter>
2121
<whitelist>
22-
<directory>./src/TwigGenerator/</directory>
22+
<directory>./src/</directory>
2323
</whitelist>
2424
</filter>
2525
</phpunit>
File renamed without changes.

src/TwigGenerator/Extension/PHPPrintExtension.php renamed to src/Extension/PHPPrintExtension.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22

33
namespace TwigGenerator\Extension;
44

5+
use Twig\Extension\AbstractExtension;
6+
use Twig\TwigFilter;
7+
58
/**
69
* @author Cedric LOMBARDOT
710
* @author Piotr Gołębiewski <[email protected]>
811
* @author Stéphane Escandell
912
*/
10-
class PHPPrintExtension extends \Twig_Extension
13+
class PHPPrintExtension extends AbstractExtension
1114
{
1215
/**
1316
* {@inheritdoc}
1417
*/
1518
public function getFilters()
1619
{
1720
return array(
18-
'as_php' => new \Twig_SimpleFilter('as_php' , array($this, 'asPhp')),
19-
'php_name' => new \Twig_SimpleFilter('php_name', array($this, 'phpName')),
21+
'as_php' => new TwigFilter('as_php' , array($this, 'asPhp')),
22+
'php_name' => new TwigFilter('php_name', array($this, 'phpName')),
2023
);
2124
}
2225

src/TwigGenerator/Extension/TwigPrintExtension.php renamed to src/Extension/TwigPrintExtension.php

+28-25
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
namespace TwigGenerator\Extension;
44

5+
use Twig\Extension\AbstractExtension;
6+
use Twig\TwigFunction;
7+
58
/**
69
* @author Cedric LOMBARDOT
710
* @author Piotr Gołębiewski <[email protected]>
811
* @author Stéphane Escandell
912
*/
10-
class TwigPrintExtension extends \Twig_Extension
13+
class TwigPrintExtension extends AbstractExtension
1114
{
1215
/**
1316
* @var array
@@ -20,28 +23,28 @@ class TwigPrintExtension extends \Twig_Extension
2023
public function getFunctions()
2124
{
2225
return array(
23-
'echo_twig' => new \Twig_SimpleFunction('echo_twig' , array($this, 'getEchoTwig')),
24-
'echo_block' => new \Twig_SimpleFunction('echo_block' , array($this, 'getEchoBlock')),
25-
'echo_endblock' => new \Twig_SimpleFunction('echo_endblock' , array($this, 'getEchoEndBlock')),
26-
'echo_for' => new \Twig_SimpleFunction('echo_for' , array($this, 'getEchoFor')),
27-
'echo_endfor' => new \Twig_SimpleFunction('echo_endfor' , array($this, 'getEchoEndFor')),
28-
'echo_raw' => new \Twig_SimpleFunction('echo_raw' , array($this, 'getEchoRaw')),
29-
'echo_endraw' => new \Twig_SimpleFunction('echo_endraw' , array($this, 'getEchoEndRaw')),
30-
'echo_spaceless' => new \Twig_SimpleFunction('echo_spaceless' , array($this, 'getEchoSpaceless')),
31-
'echo_endspaceless' => new \Twig_SimpleFunction('echo_endspaceless', array($this, 'getEchoEndSpaceless')),
32-
'echo_extends' => new \Twig_SimpleFunction('echo_extends' , array($this, 'getEchoExtends')),
33-
'echo_if' => new \Twig_SimpleFunction('echo_if' , array($this, 'getEchoIf')),
34-
'echo_else' => new \Twig_SimpleFunction('echo_else' , array($this, 'getEchoElse')),
35-
'echo_elseif' => new \Twig_SimpleFunction('echo_elseif' , array($this, 'getEchoElseIf')),
36-
'echo_endif' => new \Twig_SimpleFunction('echo_endif' , array($this, 'getEchoEndIf')),
37-
'echo_set' => new \Twig_SimpleFunction('echo_set' , array($this, 'getEchoSet')),
38-
'echo_twig_arr' => new \Twig_SimpleFunction('echo_twig_arr' , array($this, 'getEchoTwigArr')),
39-
'echo_twig_assoc' => new \Twig_SimpleFunction('echo_twig_assoc' , array($this, 'getEchoTwigAssoc')),
40-
'echo_twig_filter' => new \Twig_SimpleFunction('echo_twig_filter' , array($this, 'getEchoTwigFilter')),
41-
'echo_include' => new \Twig_SimpleFunction('echo_include' , array($this, 'getEchoInclude')),
42-
'echo_use' => new \Twig_SimpleFunction('echo_use' , array($this, 'getEchoUse')),
43-
'echo_print_block' => new \Twig_SimpleFunction('echo_print_block' , array($this, 'getEchoPrintBlock')),
44-
'char' => new \Twig_SimpleFunction('char' , array($this, 'char')),
26+
'echo_twig' => new TwigFunction('echo_twig' , array($this, 'getEchoTwig')),
27+
'echo_block' => new TwigFunction('echo_block' , array($this, 'getEchoBlock')),
28+
'echo_endblock' => new TwigFunction('echo_endblock' , array($this, 'getEchoEndBlock')),
29+
'echo_for' => new TwigFunction('echo_for' , array($this, 'getEchoFor')),
30+
'echo_endfor' => new TwigFunction('echo_endfor' , array($this, 'getEchoEndFor')),
31+
'echo_raw' => new TwigFunction('echo_raw' , array($this, 'getEchoRaw')),
32+
'echo_endraw' => new TwigFunction('echo_endraw' , array($this, 'getEchoEndRaw')),
33+
'echo_spaceless' => new TwigFunction('echo_spaceless' , array($this, 'getEchoSpaceless')),
34+
'echo_endspaceless' => new TwigFunction('echo_endspaceless', array($this, 'getEchoEndSpaceless')),
35+
'echo_extends' => new TwigFunction('echo_extends' , array($this, 'getEchoExtends')),
36+
'echo_if' => new TwigFunction('echo_if' , array($this, 'getEchoIf')),
37+
'echo_else' => new TwigFunction('echo_else' , array($this, 'getEchoElse')),
38+
'echo_elseif' => new TwigFunction('echo_elseif' , array($this, 'getEchoElseIf')),
39+
'echo_endif' => new TwigFunction('echo_endif' , array($this, 'getEchoEndIf')),
40+
'echo_set' => new TwigFunction('echo_set' , array($this, 'getEchoSet')),
41+
'echo_twig_arr' => new TwigFunction('echo_twig_arr' , array($this, 'getEchoTwigArr')),
42+
'echo_twig_assoc' => new TwigFunction('echo_twig_assoc' , array($this, 'getEchoTwigAssoc')),
43+
'echo_twig_filter' => new TwigFunction('echo_twig_filter' , array($this, 'getEchoTwigFilter')),
44+
'echo_include' => new TwigFunction('echo_include' , array($this, 'getEchoInclude')),
45+
'echo_use' => new TwigFunction('echo_use' , array($this, 'getEchoUse')),
46+
'echo_print_block' => new TwigFunction('echo_print_block' , array($this, 'getEchoPrintBlock')),
47+
'char' => new TwigFunction('char' , array($this, 'char')),
4548
);
4649
}
4750

@@ -289,7 +292,7 @@ public function getEchoEndRaw()
289292
*/
290293
public function getEchoSpaceless()
291294
{
292-
return '{% spaceless %}';
295+
return '{% apply spaceless %}';
293296
}
294297

295298
/**
@@ -299,7 +302,7 @@ public function getEchoSpaceless()
299302
*/
300303
public function getEchoEndSpaceless()
301304
{
302-
return '{% endspaceless %}';
305+
return '{% endapply %}';
303306
}
304307

305308
/**

0 commit comments

Comments
 (0)