Skip to content

Commit

Permalink
Updated twig extension for twig 2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxwilko committed Aug 13, 2019
1 parent 4ed29eb commit 4e42ff8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 258 deletions.
5 changes: 3 additions & 2 deletions src/Assetic/Extension/Twig/AsseticExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

use Assetic\Factory\AssetFactory;
use Assetic\Contracts\ValueSupplierInterface;
use Twig\Extension\GlobalsInterface;

class AsseticExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
class AsseticExtension extends \Twig_Extension implements GlobalsInterface
{
protected $factory;
protected $functions;
Expand Down Expand Up @@ -37,7 +38,7 @@ public function getFunctions()
{
$functions = array();
foreach ($this->functions as $function => $filter) {
$functions[] = new AsseticFilterFunction($function);
$functions[] = AsseticFilterFunction::make($this, $function);
}

return $functions;
Expand Down
14 changes: 7 additions & 7 deletions src/Assetic/Extension/Twig/AsseticFilterFunction.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php namespace Assetic\Extension\Twig;

class AsseticFilterFunction extends \Twig_SimpleFunction
use Twig\TwigFunction;

class AsseticFilterFunction
{
public function __construct($name, $options = array())
public static function make(AsseticExtension $extension, $name, $options = [])
{
parent::__construct($name, null, array_merge($options, array(
'needs_environment' => false,
'needs_context' => false,
'node_class' => '\Assetic\Extension\Twig\AsseticFilterNode',
)));
return new TwigFunction($name, function ($input, array $options) use ($extension, $name) {
return $extension->getFilterInvoker($name)->invoke($input, $options);
}, $options);
}
}
11 changes: 0 additions & 11 deletions src/Assetic/Extension/Twig/AsseticFilterNode.php

This file was deleted.

97 changes: 0 additions & 97 deletions src/Assetic/Extension/Twig/TwigFormulaLoader.php

This file was deleted.

11 changes: 7 additions & 4 deletions tests/Assetic/Test/Extension/Twig/AsseticExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Assetic\Asset\FileAsset;
use Assetic\FilterManager;
use Assetic\AssetManager;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;


class AsseticExtensionTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -28,7 +31,7 @@ class AsseticExtensionTest extends \PHPUnit_Framework_TestCase
private $factory;

/**
* @var \Twig_Environment
* @var Environment
*/
private $twig;

Expand All @@ -39,7 +42,7 @@ class AsseticExtensionTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
if (!class_exists('Twig_Environment')) {
if (!class_exists('\Twig\Environment')) {
$this->markTestSkipped('Twig is not installed.');
}

Expand All @@ -52,7 +55,7 @@ protected function setUp()
$this->factory->setAssetManager($this->am);
$this->factory->setFilterManager($this->fm);

$this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem(__DIR__.'/templates'));
$this->twig = new Environment(new FilesystemLoader(__DIR__.'/templates'));
$this->twig->addExtension(new AsseticExtension($this->factory, array(), $this->valueSupplier));
}

Expand Down Expand Up @@ -197,7 +200,7 @@ public function testFilterFunction()
->with('some_filter')
->will($this->returnValue($filter));

$this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem(__DIR__.'/templates'));
$this->twig = new Environment(new FilesystemLoader(__DIR__.'/templates'));
$this->twig->addExtension(new AsseticExtension($this->factory, array(
'some_func' => array(
'filter' => 'some_filter',
Expand Down
135 changes: 0 additions & 135 deletions tests/Assetic/Test/Extension/Twig/TwigFormulaLoaderTest.php

This file was deleted.

4 changes: 2 additions & 2 deletions tests/Assetic/Test/Extension/Twig/TwigResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testInvalidTemplateNameGetContent()
$loader->willImplement('Twig_SourceContextLoaderInterface');
}

$loader->getSourceContext('asdf')->willThrow(new \Twig_Error_Loader(''));
$loader->getSourceContext('asdf')->willThrow(new \Twig\Error\LoaderError(''));

$resource = new TwigResource($loader->reveal(), 'asdf');
$this->assertEquals('', $resource->getContent());
Expand All @@ -30,7 +30,7 @@ public function testInvalidTemplateNameIsFresh()
$loader->expects($this->once())
->method('isFresh')
->with('asdf', 1234)
->will($this->throwException(new \Twig_Error_Loader('')));
->will($this->throwException(new \Twig\Error\LoaderError('')));

$resource = new TwigResource($loader, 'asdf');
$this->assertFalse($resource->isFresh(1234));
Expand Down

0 comments on commit 4e42ff8

Please sign in to comment.