1: <?php
2: namespace TIC\TwigBundle\Extension;
3:
4: use TIC\TwigBundle\Base\TICTwigExtension as BaseExtension;
5:
6: use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
7: use Twig\TwigFilter;
8: use Twig\TwigFunction;
9: use Twig\Environment;
10:
11: /**
12: * Filtres et fonctions twig de formattage et conversions.
13: * https://symfony.com/doc/current/templating/twig_extension.html
14: */
15: class RouterExtension extends BaseExtension
16: {
17: protected $router; // Symfony\Component\Routing\Generator\UrlGeneratorInterface
18:
19: public function getFilters(): array
20: {
21: return [
22: new TwigFilter('isCurrentUrl', [$this, 'isCurrentUrlFilter'] ),
23: ];
24: }
25:
26: public function __construct(UrlGeneratorInterface $router)
27: {
28: $this->router = $router;
29: }
30:
31: public function isCurrentUrlFilter(string $value = null): bool
32: {
33: if (empty($value)) return false;
34: if (! isset($_SERVER['REQUEST_URI'])) return false;
35: if ($value === $_SERVER['REQUEST_URI']) return true;
36: return false;
37: }
38:
39: }
40: