TemplateEnginePool.php 1016 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View;
  7. /**
  8. * @api
  9. * @since 100.0.2
  10. */
  11. class TemplateEnginePool
  12. {
  13. /**
  14. * Factory
  15. *
  16. * @var TemplateEngineFactory
  17. */
  18. protected $factory;
  19. /**
  20. * Template engines
  21. *
  22. * @var \Magento\Framework\View\TemplateEngineInterface[]
  23. */
  24. protected $engines = [];
  25. /**
  26. * Constructor
  27. *
  28. * @param TemplateEngineFactory $factory
  29. */
  30. public function __construct(TemplateEngineFactory $factory)
  31. {
  32. $this->factory = $factory;
  33. }
  34. /**
  35. * Retrieve a template engine instance by its unique name
  36. *
  37. * @param string $name
  38. * @return \Magento\Framework\View\TemplateEngineInterface
  39. */
  40. public function get($name)
  41. {
  42. if (!isset($this->engines[$name])) {
  43. $this->engines[$name] = $this->factory->create($name);
  44. }
  45. return $this->engines[$name];
  46. }
  47. }