Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Twig Bridge compatible with Twig 3.0 #236

Merged
merged 2 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.38.1|^2.12.1|~3.0",
"zendframework/zend-modulemanager": "~2.2",
"zendframework/zend-servicemanager": "~2.2",
"zendframework/zend-view": "~2.2"
},
"conflict": {
"twig/twig": ">=1,<1.38.1|>=2,<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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-namespaced classes were removed in 3.0

{
/**
* @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
4 changes: 4 additions & 0 deletions tests/Bridge/Silex/SlugifySilexProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function register()
*/
public function registerWithTwig()
{
if (!class_exists('\Twig_Environment')) {
$this->markTestSkipped('Silex is not compatible with Twig 3');
}

$app = new Application();
$app->register(new TwigServiceProvider());
$app->register(new SlugifyServiceProvider());
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