HttpKernelRuntime.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\HttpKernel\Fragment\FragmentHandler;
  12. use Symfony\Component\HttpKernel\Controller\ControllerReference;
  13. /**
  14. * Provides integration with the HttpKernel component.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. class HttpKernelRuntime
  19. {
  20. private $handler;
  21. public function __construct(FragmentHandler $handler)
  22. {
  23. $this->handler = $handler;
  24. }
  25. /**
  26. * Renders a fragment.
  27. *
  28. * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
  29. * @param array $options An array of options
  30. *
  31. * @return string The fragment content
  32. *
  33. * @see FragmentHandler::render()
  34. */
  35. public function renderFragment($uri, $options = array())
  36. {
  37. $strategy = isset($options['strategy']) ? $options['strategy'] : 'inline';
  38. unset($options['strategy']);
  39. return $this->handler->render($uri, $strategy, $options);
  40. }
  41. /**
  42. * Renders a fragment.
  43. *
  44. * @param string $strategy A strategy name
  45. * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
  46. * @param array $options An array of options
  47. *
  48. * @return string The fragment content
  49. *
  50. * @see FragmentHandler::render()
  51. */
  52. public function renderFragmentStrategy($strategy, $uri, $options = array())
  53. {
  54. return $this->handler->render($uri, $strategy, $options);
  55. }
  56. }