Skip to content

Commit

Permalink
Merge pull request ezsystems#76 from ezsystems/twig2_compat
Browse files Browse the repository at this point in the history
Add LoaderString::getSourceContext method for compatibility with Twig 2
  • Loading branch information
emodric committed Dec 22, 2016
2 parents 0aff856 + 5101ffc commit 887085f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"ezsystems/ezpublish-legacy": ">=2014.11",
"ezsystems/ezpublish-kernel": "~6.0@dev",
"sensio/distribution-bundle": "^3.0|^4.0",
"twig/twig": "^1.23 | ^2.0"
"twig/twig": "^1.27 | ^2.0"
},
"require-dev": {
"matthiasnoback/symfony-dependency-injection-test": "^1.0",
Expand Down
7 changes: 7 additions & 0 deletions mvc/Templating/Tests/Twig/LoaderStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use eZ\Publish\Core\MVC\Legacy\Templating\Twig\LoaderString;
use PHPUnit_Framework_TestCase;
use Twig_Source;

class LoaderStringTest extends PHPUnit_Framework_TestCase
{
Expand All @@ -19,6 +20,12 @@ public function testGetSource()
$this->assertSame('foo', $loaderString->getSource('foo'));
}

public function testGetSourceContext()
{
$loaderString = new LoaderString();
$this->assertEquals(new Twig_Source('foo', 'foo'), $loaderString->getSourceContext('foo'));
}

public function testGetCacheKey()
{
$loaderString = new LoaderString();
Expand Down
9 changes: 9 additions & 0 deletions mvc/Templating/Twig/LoaderString.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Twig_LoaderInterface;
use Twig_ExistsLoaderInterface;
use Twig_Source;

/**
* This loader is supposed to directly load templates as a string, not from FS.
Expand All @@ -26,6 +27,14 @@ public function getSource($name)
return $name;
}

/**
* {@inheritdoc}
*/
public function getSourceContext($name)
{
return new Twig_Source($name, $name);
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 887085f

Please sign in to comment.