From e6784f80d9c1bb9eec1eae607514d0115dd9e1f2 Mon Sep 17 00:00:00 2001 From: Ralf Baussenwein Date: Sun, 20 Feb 2022 17:29:07 +0100 Subject: [PATCH] Fix compatibility with twig version 3 --- Tests/Twig/AbstractExtensionTest.php | 11 +++++++---- Twig/ApiExtension.php | 6 ++++-- Twig/MapExtension.php | 6 ++++-- Twig/PlaceAutocompleteExtension.php | 6 ++++-- Twig/StaticMapExtension.php | 6 ++++-- composer.json | 2 +- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Tests/Twig/AbstractExtensionTest.php b/Tests/Twig/AbstractExtensionTest.php index 12d5f197..19826d28 100644 --- a/Tests/Twig/AbstractExtensionTest.php +++ b/Tests/Twig/AbstractExtensionTest.php @@ -12,6 +12,9 @@ namespace Ivory\GoogleMapBundle\Tests\Twig; use PHPUnit\Framework\TestCase; +use Twig\Environment; +use Twig\Extension\AbstractExtension; +use Twig\Loader\FilesystemLoader; /** * @author GeLo @@ -19,7 +22,7 @@ abstract class AbstractExtensionTest extends TestCase { /** - * @var \Twig_Environment + * @var Environment */ private $twig; @@ -28,17 +31,17 @@ abstract class AbstractExtensionTest extends TestCase */ protected function setUp() { - $this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem([])); + $this->twig = new Environment(new FilesystemLoader([])); $this->twig->addExtension($this->createExtension()); } /** - * @return \Twig_Extension + * @return AbstractExtension */ abstract protected function createExtension(); /** - * @return \Twig_Environment + * @return Environment */ protected function getTwig() { diff --git a/Twig/ApiExtension.php b/Twig/ApiExtension.php index ddebdb86..68b1d3c4 100644 --- a/Twig/ApiExtension.php +++ b/Twig/ApiExtension.php @@ -12,11 +12,13 @@ namespace Ivory\GoogleMapBundle\Twig; use Ivory\GoogleMap\Helper\ApiHelper; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * @author GeLo */ -class ApiExtension extends \Twig_Extension +class ApiExtension extends AbstractExtension { /** * @var ApiHelper @@ -39,7 +41,7 @@ public function getFunctions() $functions = []; foreach ($this->getMapping() as $name => $method) { - $functions[] = new \Twig_SimpleFunction($name, [$this, $method], ['is_safe' => ['html']]); + $functions[] = new TwigFunction($name, [$this, $method], ['is_safe' => ['html']]); } return $functions; diff --git a/Twig/MapExtension.php b/Twig/MapExtension.php index 0adcacd7..4a63039a 100644 --- a/Twig/MapExtension.php +++ b/Twig/MapExtension.php @@ -13,11 +13,13 @@ use Ivory\GoogleMap\Helper\MapHelper; use Ivory\GoogleMap\Map; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * @author GeLo */ -class MapExtension extends \Twig_Extension +class MapExtension extends AbstractExtension { /** * @var MapHelper @@ -40,7 +42,7 @@ public function getFunctions() $functions = []; foreach ($this->getMapping() as $name => $method) { - $functions[] = new \Twig_SimpleFunction($name, [$this, $method], ['is_safe' => ['html']]); + $functions[] = new TwigFunction($name, [$this, $method], ['is_safe' => ['html']]); } return $functions; diff --git a/Twig/PlaceAutocompleteExtension.php b/Twig/PlaceAutocompleteExtension.php index 6b00b67f..f22a2ce5 100644 --- a/Twig/PlaceAutocompleteExtension.php +++ b/Twig/PlaceAutocompleteExtension.php @@ -13,11 +13,13 @@ use Ivory\GoogleMap\Helper\PlaceAutocompleteHelper; use Ivory\GoogleMap\Place\Autocomplete; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * @author GeLo */ -class PlaceAutocompleteExtension extends \Twig_Extension +class PlaceAutocompleteExtension extends AbstractExtension { /** * @var PlaceAutocompleteHelper @@ -40,7 +42,7 @@ public function getFunctions() $functions = []; foreach ($this->getMapping() as $name => $method) { - $functions[] = new \Twig_SimpleFunction($name, [$this, $method], ['is_safe' => ['html']]); + $functions[] = new TwigFunction($name, [$this, $method], ['is_safe' => ['html']]); } return $functions; diff --git a/Twig/StaticMapExtension.php b/Twig/StaticMapExtension.php index da6060ef..3487c355 100644 --- a/Twig/StaticMapExtension.php +++ b/Twig/StaticMapExtension.php @@ -13,11 +13,13 @@ use Ivory\GoogleMap\Helper\StaticMapHelper; use Ivory\GoogleMap\Map; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * @author GeLo */ -class StaticMapExtension extends \Twig_Extension +class StaticMapExtension extends AbstractExtension { /** * @var StaticMapHelper @@ -40,7 +42,7 @@ public function getFunctions() $functions = []; foreach ($this->getMapping() as $name => $method) { - $functions[] = new \Twig_SimpleFunction($name, [$this, $method], ['is_safe' => ['html']]); + $functions[] = new TwigFunction($name, [$this, $method], ['is_safe' => ['html']]); } return $functions; diff --git a/composer.json b/composer.json index 79118cd9..ee774e77 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "symfony/phpunit-bridge": "^2.7 || ^3.0 || ^4.0", "symfony/templating": "^2.7 || ^3.0 || ^4.0", "symfony/yaml": "^2.7 || ^3.0 || ^4.0", - "twig/twig": "^1.18" + "twig/twig": "^2.7 || ^3.0" }, "autoload": { "psr-4": { "Ivory\\GoogleMapBundle\\": "" }