vendor/pimcore/pimcore/lib/Controller/Controller.php line 74

Open in your IDE?
  1. <?php
  2. /**
  3. * Pimcore
  4. *
  5. * This source file is available under two different licenses:
  6. * - GNU General Public License version 3 (GPLv3)
  7. * - Pimcore Commercial License (PCL)
  8. * Full copyright and license information is available in
  9. * LICENSE.md which is distributed with this source code.
  10. *
  11. * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12. * @license http://www.pimcore.org/license GPLv3 and PCL
  13. */
  14. namespace Pimcore\Controller;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\HttpFoundation\StreamedResponse;
  18. use Symfony\Component\Templating\EngineInterface;
  19. abstract class Controller extends AbstractController
  20. {
  21. /**
  22. * {@inheritdoc}
  23. *
  24. */
  25. protected function render(string $view, array $parameters = [], Response $response = null): Response
  26. {
  27. $templatingEngine = $this->container->get('pimcore.templating');
  28. if ($templatingEngine->isDelegate()) {
  29. $content = $templatingEngine->render($view, $parameters);
  30. if (null === $response) {
  31. $response = new Response();
  32. }
  33. $response->setContent($content);
  34. return $response;
  35. }
  36. return parent::render($view, $parameters, $response);
  37. }
  38. /**
  39. * {@inheritdoc}
  40. *
  41. */
  42. protected function stream(string $view, array $parameters = [], StreamedResponse $response = null): StreamedResponse
  43. {
  44. $templatingEngine = $this->container->get('pimcore.templating');
  45. if ($templatingEngine->isDelegate()) {
  46. $callback = function () use ($templatingEngine, $view, $parameters) {
  47. $templatingEngine->stream($view, $parameters);
  48. };
  49. if (null === $response) {
  50. return new StreamedResponse($callback);
  51. }
  52. $response->setCallback($callback);
  53. return $response;
  54. }
  55. return parent::stream($view, $parameters, $response);
  56. }
  57. /**
  58. * {@inheritdoc}
  59. *
  60. */
  61. protected function renderView(string $view, array $parameters = []): string
  62. {
  63. $templatingEngine = $this->container->get('pimcore.templating');
  64. if ($templatingEngine->isDelegate()) {
  65. return $templatingEngine->render($view, $parameters);
  66. }
  67. return parent::renderView($view, $parameters);
  68. }
  69. /**
  70. * @return string[]
  71. */
  72. public static function getSubscribedServices()// : array
  73. {
  74. $services = parent::getSubscribedServices();
  75. $services['pimcore.templating'] = '?'.EngineInterface::class;
  76. return $services;
  77. }
  78. }