Source of file RouterExtension.php

Size: 0,965 Bytes - Last Modified: 2023-11-16T22:56:02+01:00

/home/websites/teicee/packagist/site/phpdoc/conf/../vendor/teicee/twig-bundle/src/Extension/RouterExtension.php

12345678910111213141516171819202122232425262728293031323334353637383940
<?php
namespace TIC\TwigBundle\Extension;

use TIC\TwigBundle\Base\TICTwigExtension as BaseExtension;

use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Twig\Environment;

/**
 * Filtres et fonctions twig de formattage et conversions.
 * https://symfony.com/doc/current/templating/twig_extension.html
 */
class RouterExtension extends BaseExtension
{
	protected $router;                  // Symfony\Component\Routing\Generator\UrlGeneratorInterface

	public function getFilters(): array
	{
		return [
			new TwigFilter('isCurrentUrl', [$this, 'isCurrentUrlFilter'] ),
		];
	}

	public function __construct(UrlGeneratorInterface $router)
	{
		$this->router = $router;
	}

	public function isCurrentUrlFilter(string $value = null): bool
	{
		if (empty($value)) return false;
		if (! isset($_SERVER['REQUEST_URI'])) return false;
		if ($value === $_SERVER['REQUEST_URI']) return true;
		return false;
	}

}