RoutableFragmentRenderer.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\Component\HttpKernel\Fragment;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpKernel\Controller\ControllerReference;
  13. use Symfony\Component\HttpKernel\EventListener\FragmentListener;
  14. /**
  15. * Adds the possibility to generate a fragment URI for a given Controller.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. abstract class RoutableFragmentRenderer implements FragmentRendererInterface
  20. {
  21. /**
  22. * @internal
  23. */
  24. protected string $fragmentPath = '/_fragment';
  25. /**
  26. * Sets the fragment path that triggers the fragment listener.
  27. *
  28. * @see FragmentListener
  29. *
  30. * @return void
  31. */
  32. public function setFragmentPath(string $path)
  33. {
  34. $this->fragmentPath = $path;
  35. }
  36. /**
  37. * Generates a fragment URI for a given controller.
  38. *
  39. * @param bool $absolute Whether to generate an absolute URL or not
  40. * @param bool $strict Whether to allow non-scalar attributes or not
  41. */
  42. protected function generateFragmentUri(ControllerReference $reference, Request $request, bool $absolute = false, bool $strict = true): string
  43. {
  44. return (new FragmentUriGenerator($this->fragmentPath))->generate($reference, $request, $absolute, $strict, false);
  45. }
  46. }