Xhtml.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\TemplateEngine;
  7. use Magento\Framework\View\Element\BlockInterface;
  8. use Magento\Framework\View\TemplateEngineInterface;
  9. use Magento\Framework\View\TemplateEngine\Xhtml\Template;
  10. use Magento\Framework\View\TemplateEngine\Xhtml\ResultFactory;
  11. use Magento\Framework\View\TemplateEngine\Xhtml\ResultInterface;
  12. use Magento\Framework\View\TemplateEngine\Xhtml\CompilerFactory;
  13. use Magento\Framework\View\TemplateEngine\Xhtml\TemplateFactory;
  14. use Magento\Framework\View\Element\UiComponent\Config\Provider\Template as TemplateProvider;
  15. /**
  16. * Class Xhtml
  17. */
  18. class Xhtml implements TemplateEngineInterface
  19. {
  20. /**
  21. * @var TemplateProvider
  22. */
  23. protected $templateProvider;
  24. /**
  25. * @var ResultFactory
  26. */
  27. protected $resultFactory;
  28. /**
  29. * @var TemplateFactory
  30. */
  31. protected $templateFactory;
  32. /**
  33. * @var CompilerFactory
  34. */
  35. protected $compilerFactory;
  36. /**
  37. * Constructor
  38. *
  39. * @param TemplateProvider $templateProvider
  40. * @param ResultFactory $resultFactory
  41. * @param TemplateFactory $templateFactory
  42. * @param CompilerFactory $compilerFactory
  43. */
  44. public function __construct(
  45. TemplateProvider $templateProvider,
  46. ResultFactory $resultFactory,
  47. TemplateFactory $templateFactory,
  48. CompilerFactory $compilerFactory
  49. ) {
  50. $this->templateProvider = $templateProvider;
  51. $this->resultFactory = $resultFactory;
  52. $this->templateFactory = $templateFactory;
  53. $this->compilerFactory = $compilerFactory;
  54. }
  55. /**
  56. * Render template
  57. *
  58. * Render the named template in the context of a particular block and with
  59. * the data provided in $vars.
  60. *
  61. * @param BlockInterface $block
  62. * @param string $templateFile
  63. * @param array $dictionary
  64. * @return ResultInterface
  65. *
  66. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  67. */
  68. public function render(BlockInterface $block, $templateFile, array $dictionary = [])
  69. {
  70. /** @var Template $template */
  71. $template = $this->templateFactory->create(['content' => $this->templateProvider->getTemplate($templateFile)]);
  72. $result = $this->resultFactory->create(
  73. [
  74. 'template' => $template,
  75. 'compiler' => $this->compilerFactory->create(),
  76. 'component' => $block
  77. ]
  78. );
  79. return $result;
  80. }
  81. }