LayoutFactory.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Result;
  7. use Magento\Framework\ObjectManagerInterface;
  8. /**
  9. * @api
  10. * @since 100.0.2
  11. */
  12. class LayoutFactory
  13. {
  14. /**
  15. * @var ObjectManagerInterface
  16. */
  17. private $objectManager;
  18. /**
  19. * @var string
  20. */
  21. protected $instanceName;
  22. /**
  23. * @param ObjectManagerInterface $objectManager
  24. * @param string $instanceName
  25. */
  26. public function __construct(
  27. ObjectManagerInterface $objectManager,
  28. $instanceName = \Magento\Framework\View\Result\Layout::class
  29. ) {
  30. $this->objectManager = $objectManager;
  31. $this->instanceName = $instanceName;
  32. }
  33. /**
  34. * @return \Magento\Framework\View\Result\Layout
  35. */
  36. public function create()
  37. {
  38. /** @var \Magento\Framework\View\Result\Layout $resultLayout */
  39. $resultLayout = $this->objectManager->create($this->instanceName);
  40. $resultLayout->addDefaultHandle();
  41. return $resultLayout;
  42. }
  43. }