vendor/symfony/twig-bridge/Extension/LogoutUrlExtension.php line 45

  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bridge\Twig\Extension;
  11. use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
  12. use Twig\Extension\AbstractExtension;
  13. use Twig\TwigFunction;
  14. /**
  15.  * LogoutUrlHelper provides generator functions for the logout URL to Twig.
  16.  *
  17.  * @author Jeremy Mikola <jmikola@gmail.com>
  18.  */
  19. final class LogoutUrlExtension extends AbstractExtension
  20. {
  21.     private LogoutUrlGenerator $generator;
  22.     public function __construct(LogoutUrlGenerator $generator)
  23.     {
  24.         $this->generator $generator;
  25.     }
  26.     public function getFunctions(): array
  27.     {
  28.         return [
  29.             new TwigFunction('logout_url'$this->getLogoutUrl(...)),
  30.             new TwigFunction('logout_path'$this->getLogoutPath(...)),
  31.         ];
  32.     }
  33.     /**
  34.      * Generates the relative logout URL for the firewall.
  35.      *
  36.      * @param string|null $key The firewall key or null to use the current firewall key
  37.      */
  38.     public function getLogoutPath(string $key null): string
  39.     {
  40.         return $this->generator->getLogoutPath($key);
  41.     }
  42.     /**
  43.      * Generates the absolute logout URL for the firewall.
  44.      *
  45.      * @param string|null $key The firewall key or null to use the current firewall key
  46.      */
  47.     public function getLogoutUrl(string $key null): string
  48.     {
  49.         return $this->generator->getLogoutUrl($key);
  50.     }
  51. }