Skip to content

Commit

Permalink
fix deprecations
Browse files Browse the repository at this point in the history
bump symfony and php versions
fix typo
  • Loading branch information
addfs committed Mar 17, 2022
1 parent bfa4cff commit 327d4c3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 37 deletions.
7 changes: 5 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions Event/TwigInjectEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Intaro\TwigInjectionBundle\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class TwigInjectEvent extends Event
{
Expand Down Expand Up @@ -41,4 +41,4 @@ public function setInjections(array $injections)
{
$this->injections = $injections;
}
}
}
6 changes: 3 additions & 3 deletions Event/TwigInjectRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
```
Expand All @@ -23,11 +23,11 @@ Register the bundle in `AppKernel`:

public function registerBundles()
{
$bundles = array(
$bundles = [
//...

new Intaro\TwigInjectionBundle\IntaroTwigInjectionBundle(),
);
];

//...
}
Expand Down
33 changes: 16 additions & 17 deletions Twig/InjectionExtension.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<?php
namespace Intaro\TwigInjectionBundle\Twig;

use Twig_Extension;
use Twig_SimpleFunction;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Intaro\TwigInjectionBundle\Event\TwigInjectEvent;
use Intaro\TwigInjectionBundle\Event\TwigInjectInclude;
use Intaro\TwigInjectionBundle\Event\TwigInjectRender;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class InjectionExtension extends Twig_Extension
class InjectionExtension extends AbstractExtension
{
private $fragment;
private $dispatcher;
Expand All @@ -22,31 +21,31 @@ public function __construct(FragmentHandler $fragment, EventDispatcherInterface
$this->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()));
Expand All @@ -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';
}
Expand Down
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 327d4c3

Please sign in to comment.