From 327d4c3462fa1708b4cf967770f0be8ee4ef3669 Mon Sep 17 00:00:00 2001 From: Alexey Chelnakov Date: Tue, 22 Feb 2022 13:03:56 +0300 Subject: [PATCH] fix deprecations bump symfony and php versions fix typo --- DependencyInjection/Configuration.php | 7 ++++-- Event/TwigInjectEvent.php | 4 ++-- Event/TwigInjectRender.php | 6 ++--- README.md | 6 ++--- Twig/InjectionExtension.php | 33 +++++++++++++-------------- composer.json | 19 ++++++++------- 6 files changed, 38 insertions(+), 37 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index f20310f..be9bf5b 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -12,8 +12,11 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('intaro_twig_injection'); + $treeBuilder = new TreeBuilder('intaro_twig_injection'); + if (!\method_exists($treeBuilder, 'getRootNode')) { + // BC layer for symfony/config 4.1 and older + $rootNode = $treeBuilder->root('intaro_twig_injection'); + } return $treeBuilder; } diff --git a/Event/TwigInjectEvent.php b/Event/TwigInjectEvent.php index e460454..4c6aadb 100644 --- a/Event/TwigInjectEvent.php +++ b/Event/TwigInjectEvent.php @@ -2,7 +2,7 @@ namespace Intaro\TwigInjectionBundle\Event; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; class TwigInjectEvent extends Event { @@ -41,4 +41,4 @@ public function setInjections(array $injections) { $this->injections = $injections; } -} \ No newline at end of file +} diff --git a/Event/TwigInjectRender.php b/Event/TwigInjectRender.php index 1b5562e..b24ed0b 100644 --- a/Event/TwigInjectRender.php +++ b/Event/TwigInjectRender.php @@ -10,13 +10,13 @@ class TwigInjectRender extends TwigInjectItem private $controller; private $attributes; private $query; - private $stategy; + private $strategy; public function __construct( $controller, - array $attributes = array(), + array $attributes = [], $priority = 0, - array $query = array(), + array $query = [], $strategy = 'inline' ) { $this->controller = $controller; diff --git a/README.md b/README.md index 02e5f27..7fe6e44 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Require the bundle in your `composer.json` file: ```json { "require": { - "intaro/twig-injection-bundle": "~1.0.0", + "intaro/twig-injection-bundle": "~1.0.0" } } ``` @@ -23,11 +23,11 @@ Register the bundle in `AppKernel`: public function registerBundles() { - $bundles = array( + $bundles = [ //... new Intaro\TwigInjectionBundle\IntaroTwigInjectionBundle(), - ); + ]; //... } diff --git a/Twig/InjectionExtension.php b/Twig/InjectionExtension.php index 82b203e..4edd632 100644 --- a/Twig/InjectionExtension.php +++ b/Twig/InjectionExtension.php @@ -1,17 +1,16 @@ dispatcher = $dispatcher; } - public function getFunctions() + public function getFunctions(): array { - return array( - 'inject' => new Twig_SimpleFunction('inject', [$this, 'inject'], [ + return [ + 'inject' => new TwigFunction('inject', [$this, 'inject'], [ 'needs_environment' => true, 'needs_context' => true, - 'is_safe' => array('all'), + 'is_safe' => ['all'], ]), - ); + ]; } - public function inject(\Twig_Environment $env, $context, $eventName, array $parameters = []) + public function inject(\Twig\Environment $env, $context, $eventName, array $parameters = []) { $event = new TwigInjectEvent($parameters); - $event = $this->dispatcher->dispatch($eventName, $event); + $event = $this->dispatcher->dispatch($event, $eventName); return $this->render($env, $context, $event); } - private function render(\Twig_Environment $env, $context, TwigInjectEvent $event) + private function render(\Twig\Environment $env, $context, TwigInjectEvent $event) { $content = ''; - if (sizeof($injections = $event->getInjections())) { + if (\count($injections = $event->getInjections()) > 0) { foreach ($injections as $item) { if ($item instanceof TwigInjectInclude) { $content .= $env->resolveTemplate($item->getTemplate())->render(array_merge($context, $item->getParameters())); @@ -66,7 +65,7 @@ private function render(\Twig_Environment $env, $context, TwigInjectEvent $event return $content; } - public function getName() + public function getName(): string { return 'twig_injection_extension'; } diff --git a/composer.json b/composer.json index 97b5646..0b42648 100644 --- a/composer.json +++ b/composer.json @@ -11,18 +11,17 @@ } ], "require": { - "php": ">=5.4.4", - "symfony/framework-bundle" : ">=2.8|<=3.4", - "symfony/twig-bridge": ">=2.8|<=3.4", - "symfony/twig-bundle": ">=2.8|<=3.4", - "symfony/http-kernel" : ">=2.8|<=3.4", - "symfony/event-dispatcher" : ">=2.8|<=3.4", - "symfony/yaml": ">=2.8|<=3.4" + "php": ">=7.1.3", + "symfony/framework-bundle" : "^3.4|^4.4", + "symfony/twig-bridge": "^3.4|^4.4", + "symfony/twig-bundle": "^3.4|^4.4", + "symfony/http-kernel" : "^3.4|^4.4", + "symfony/event-dispatcher" : "^3.4|^4.4", + "symfony/yaml": "^3.4|^4.4" }, "autoload": { - "psr-0": { + "psr-4": { "Intaro\\TwigInjectionBundle\\": "" } - }, - "target-dir" : "Intaro/TwigInjectionBundle" + } }