LogoutUrlExtension.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\Bundle\SecurityBundle\Twig\Extension;
  11. @trigger_error('The '.__NAMESPACE__.'\LogoutUrlExtension class is deprecated since Symfony 2.7 and will be removed in 3.0. Use Symfony\Bridge\Twig\Extension\LogoutUrlExtension instead.', E_USER_DEPRECATED);
  12. use Symfony\Bundle\SecurityBundle\Templating\Helper\LogoutUrlHelper;
  13. use Twig\Extension\AbstractExtension;
  14. use Twig\TwigFunction;
  15. /**
  16. * LogoutUrlHelper provides generator functions for the logout URL to Twig.
  17. *
  18. * @author Jeremy Mikola <jmikola@gmail.com>
  19. *
  20. * @deprecated since version 2.7, to be removed in 3.0. Use Symfony\Bridge\Twig\Extension\LogoutUrlExtension instead.
  21. */
  22. class LogoutUrlExtension extends AbstractExtension
  23. {
  24. private $helper;
  25. public function __construct(LogoutUrlHelper $helper)
  26. {
  27. $this->helper = $helper;
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function getFunctions()
  33. {
  34. return array(
  35. new TwigFunction('logout_url', array($this, 'getLogoutUrl')),
  36. new TwigFunction('logout_path', array($this, 'getLogoutPath')),
  37. );
  38. }
  39. /**
  40. * Generates the relative logout URL for the firewall.
  41. *
  42. * @param string|null $key The firewall key or null to use the current firewall key
  43. *
  44. * @return string The relative logout URL
  45. */
  46. public function getLogoutPath($key = null)
  47. {
  48. return $this->helper->getLogoutPath($key);
  49. }
  50. /**
  51. * Generates the absolute logout URL for the firewall.
  52. *
  53. * @param string|null $key The firewall key or null to use the current firewall key
  54. *
  55. * @return string The absolute logout URL
  56. */
  57. public function getLogoutUrl($key = null)
  58. {
  59. return $this->helper->getLogoutUrl($key);
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function getName()
  65. {
  66. return 'logout_url';
  67. }
  68. }