You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

3 years ago
  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 $fragmentPath = '/_fragment';
  25. /**
  26. * Sets the fragment path that triggers the fragment listener.
  27. *
  28. * @see FragmentListener
  29. */
  30. public function setFragmentPath(string $path)
  31. {
  32. $this->fragmentPath = $path;
  33. }
  34. /**
  35. * Generates a fragment URI for a given controller.
  36. *
  37. * @param bool $absolute Whether to generate an absolute URL or not
  38. * @param bool $strict Whether to allow non-scalar attributes or not
  39. *
  40. * @return string A fragment URI
  41. */
  42. protected function generateFragmentUri(ControllerReference $reference, Request $request, bool $absolute = false, bool $strict = true)
  43. {
  44. return (new FragmentUriGenerator($this->fragmentPath))->generate($reference, $request, $absolute, $strict, false);
  45. }
  46. }