PageFactory.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. * A factory that knows how to create a "page" result
  10. * Requires an instance of controller action in order to impose page type,
  11. * which is by convention is determined from the controller action class
  12. *
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class PageFactory
  17. {
  18. /**
  19. * @var ObjectManagerInterface
  20. */
  21. private $objectManager;
  22. /**
  23. * @var string
  24. */
  25. protected $instanceName;
  26. /**
  27. * @param ObjectManagerInterface $objectManager
  28. * @param string $instanceName
  29. */
  30. public function __construct(
  31. ObjectManagerInterface $objectManager,
  32. $instanceName = \Magento\Framework\View\Result\Page::class
  33. ) {
  34. $this->objectManager = $objectManager;
  35. $this->instanceName = $instanceName;
  36. }
  37. /**
  38. * Create new page regarding its type
  39. *
  40. * TODO: As argument has to be controller action interface, temporary solution until controller output models
  41. * TODO: are not implemented
  42. *
  43. * @param bool $isView
  44. * @param array $arguments
  45. * @return \Magento\Framework\View\Result\Page
  46. */
  47. public function create($isView = false, array $arguments = [])
  48. {
  49. /** @var \Magento\Framework\View\Result\Page $page */
  50. $page = $this->objectManager->create($this->instanceName, $arguments);
  51. // TODO Temporary solution for compatibility with View object. Will be deleted in MAGETWO-28359
  52. if (!$isView) {
  53. $page->addDefaultHandle();
  54. }
  55. return $page;
  56. }
  57. }