123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\App;
- class View implements ViewInterface
- {
- /**
- * @var \Magento\Framework\View\LayoutInterface
- */
- protected $_layout;
- /**
- * @var \Magento\Framework\Config\ScopeInterface
- */
- protected $_configScope;
- /**
- * @var \Magento\Framework\Event\ManagerInterface
- */
- protected $_eventManager;
- /**
- * @var \Magento\Framework\View\Result\Page
- */
- protected $page;
- /**
- * @var ActionFlag
- */
- protected $_actionFlag;
- /**
- * @var ResponseInterface
- */
- protected $_response;
- /**
- * @var RequestInterface
- */
- protected $_request;
- /**
- * @var bool
- */
- protected $_isLayoutLoaded = false;
- /**
- * @param \Magento\Framework\View\LayoutInterface $layout
- * @param RequestInterface $request
- * @param ResponseInterface $response
- * @param \Magento\Framework\Config\ScopeInterface $configScope
- * @param \Magento\Framework\Event\ManagerInterface $eventManager
- * @param \Magento\Framework\View\Result\PageFactory $pageFactory
- * @param ActionFlag $actionFlag
- */
- public function __construct(
- \Magento\Framework\View\LayoutInterface $layout,
- RequestInterface $request,
- ResponseInterface $response,
- \Magento\Framework\Config\ScopeInterface $configScope,
- \Magento\Framework\Event\ManagerInterface $eventManager,
- \Magento\Framework\View\Result\PageFactory $pageFactory,
- ActionFlag $actionFlag
- ) {
- $this->_layout = $layout;
- $this->_request = $request;
- $this->_response = $response;
- $this->_configScope = $configScope;
- $this->_eventManager = $eventManager;
- $this->_actionFlag = $actionFlag;
- $this->page = $pageFactory->create(true);
- }
- /**
- * Retrieve current page object
- *
- * @return \Magento\Framework\View\Result\Page
- */
- public function getPage()
- {
- return $this->page;
- }
- /**
- * Retrieve current layout object
- *
- * @return \Magento\Framework\View\LayoutInterface
- */
- public function getLayout()
- {
- return $this->page->getLayout();
- }
- /**
- * {@inheritdoc}
- */
- public function loadLayout($handles = null, $generateBlocks = true, $generateXml = true, $addActionHandles = true)
- {
- if ($this->_isLayoutLoaded) {
- throw new \RuntimeException('Layout must be loaded only once.');
- }
- // if handles were specified in arguments load them first
- if (!empty($handles)) {
- $this->getLayout()->getUpdate()->addHandle($handles);
- }
- if ($addActionHandles) {
- // add default layout handles for this action
- $this->page->initLayout();
- }
- $this->loadLayoutUpdates();
- if (!$generateXml) {
- return $this;
- }
- $this->generateLayoutXml();
- if (!$generateBlocks) {
- return $this;
- }
- $this->generateLayoutBlocks();
- $this->_isLayoutLoaded = true;
- return $this;
- }
- /**
- * Retrieve the default layout handle name for the current action
- *
- * @return string
- */
- public function getDefaultLayoutHandle()
- {
- return $this->page->getDefaultLayoutHandle();
- }
- /**
- * Add layout handle by full controller action name
- *
- * @return $this
- */
- public function addActionLayoutHandles()
- {
- $this->getLayout()->getUpdate()->addHandle($this->getDefaultLayoutHandle());
- return $this;
- }
- /**
- * Add layout updates handles associated with the action page
- *
- * @param array|null $parameters page parameters
- * @param string|null $defaultHandle
- * @return bool
- */
- public function addPageLayoutHandles(array $parameters = [], $defaultHandle = null)
- {
- return $this->page->addPageLayoutHandles($parameters, $defaultHandle);
- }
- /**
- * Load layout updates
- *
- * @return $this
- */
- public function loadLayoutUpdates()
- {
- $this->page->getConfig()->publicBuild();
- return $this;
- }
- /**
- * Generate layout xml
- *
- * @return $this
- */
- public function generateLayoutXml()
- {
- $this->page->getConfig()->publicBuild();
- return $this;
- }
- /**
- * Generate layout blocks
- *
- * @return $this
- */
- public function generateLayoutBlocks()
- {
- $this->page->getConfig()->publicBuild();
- return $this;
- }
- /**
- * Rendering layout
- *
- * @param string $output
- * @return $this
- */
- public function renderLayout($output = '')
- {
- if ($this->_actionFlag->get('', 'no-renderLayout')) {
- return $this;
- }
- \Magento\Framework\Profiler::start('LAYOUT');
- \Magento\Framework\Profiler::start('layout_render');
- if ('' !== $output) {
- $this->getLayout()->addOutputElement($output);
- }
- $this->_eventManager->dispatch('controller_action_layout_render_before');
- $this->_eventManager->dispatch(
- 'controller_action_layout_render_before_' . $this->_request->getFullActionName()
- );
- $this->page->renderResult($this->_response);
- \Magento\Framework\Profiler::stop('layout_render');
- \Magento\Framework\Profiler::stop('LAYOUT');
- return $this;
- }
- /**
- * Set isLayoutLoaded flag
- *
- * @param bool $value
- * @return void
- */
- public function setIsLayoutLoaded($value)
- {
- $this->_isLayoutLoaded = $value;
- }
- /**
- * Returns is layout loaded
- *
- * @return bool
- */
- public function isLayoutLoaded()
- {
- return $this->_isLayoutLoaded;
- }
- }
|