Skip to content

Commit

Permalink
make Twig Bridge compatible with Twig 3.0
Browse files Browse the repository at this point in the history
Twig provides namespaced class aliases since 1.38.1 and 2.12.1, so this should work on all recently released Twig versions.
  • Loading branch information
mhujer committed Nov 24, 2019
1 parent 435501d commit 782bc49
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@
"symfony/config": "~2.4|~3.0|~4.0",
"symfony/dependency-injection": "~2.4|~3.0|~4.0",
"symfony/http-kernel": "~2.4|~3.0|~4.0",
"twig/twig": "~1.26|~2.0",
"twig/twig": "~1.26|~2.0|~3.0",
"zendframework/zend-modulemanager": "~2.2",
"zendframework/zend-servicemanager": "~2.2",
"zendframework/zend-view": "~2.2"
},
"conflict": {
"twig/twig": "<1.38.1||<2.12.1"
},
"autoload": {
"psr-4": {"Cocur\\Slugify\\": "src"}
},
Expand Down
9 changes: 5 additions & 4 deletions src/Bridge/Twig/SlugifyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
namespace Cocur\Slugify\Bridge\Twig;

use Cocur\Slugify\SlugifyInterface;
use Twig_SimpleFilter;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

/**
* SlugifyExtension
Expand All @@ -23,7 +24,7 @@
* @copyright 2012-2015 Florian Eckerstorfer
* @license http://www.opensource.org/licenses/MIT The MIT License
*/
class SlugifyExtension extends \Twig_Extension
class SlugifyExtension extends AbstractExtension
{
/**
* @var SlugifyInterface
Expand All @@ -45,12 +46,12 @@ public function __construct(SlugifyInterface $slugify)
/**
* Returns the Twig functions of this extension.
*
* @return Twig_SimpleFilter[]
* @return TwigFilter[]
*/
public function getFilters()
{
return [
new Twig_SimpleFilter('slugify', [$this, 'slugifyFilter']),
new TwigFilter('slugify', [$this, 'slugifyFilter']),
];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Bridge/Twig/SlugifyExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getFilters()
$filters = $this->extension->getFilters();

$this->assertCount(1, $filters);
$this->assertInstanceOf('\Twig_SimpleFilter', $filters[0]);
$this->assertInstanceOf('\Twig\TwigFilter', $filters[0]);
}

/**
Expand Down

0 comments on commit 782bc49

Please sign in to comment.