|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * |
4 | 3 | * Copyright © Magento, Inc. All rights reserved. |
5 | 4 | * See COPYING.txt for license details. |
6 | 5 | */ |
7 | 6 | namespace Magento\Cms\Controller\Index; |
8 | 7 |
|
| 8 | +use Magento\Framework\App\Action\Context; |
| 9 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 10 | +use Magento\Framework\App\ObjectManager; |
| 11 | +use Magento\Framework\App\ResponseInterface; |
| 12 | +use Magento\Framework\Controller\ResultInterface; |
| 13 | +use Magento\Framework\Controller\Result\Forward; |
| 14 | +use Magento\Framework\Controller\Result\ForwardFactory; |
| 15 | +use Magento\Framework\View\Result\Page as ResultPage; |
| 16 | +use Magento\Cms\Helper\Page; |
| 17 | +use Magento\Store\Model\ScopeInterface; |
| 18 | + |
9 | 19 | class Index extends \Magento\Framework\App\Action\Action |
10 | 20 | { |
11 | 21 | /** |
12 | | - * @var \Magento\Framework\Controller\Result\ForwardFactory |
| 22 | + * @var ForwardFactory |
13 | 23 | */ |
14 | 24 | protected $resultForwardFactory; |
15 | 25 |
|
16 | 26 | /** |
17 | | - * @param \Magento\Framework\App\Action\Context $context |
18 | | - * @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory |
| 27 | + * @var ScopeConfigInterface |
| 28 | + */ |
| 29 | + private $scopeConfig; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var Page |
| 33 | + */ |
| 34 | + private $page; |
| 35 | + |
| 36 | + /** |
| 37 | + * Index constructor. |
| 38 | + * |
| 39 | + * @param Context $context |
| 40 | + * @param ForwardFactory $resultForwardFactory |
| 41 | + * @param ScopeConfigInterface|null $scopeConfig |
| 42 | + * @param Page|null $page |
19 | 43 | */ |
20 | 44 | public function __construct( |
21 | | - \Magento\Framework\App\Action\Context $context, |
22 | | - \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory |
| 45 | + Context $context, |
| 46 | + ForwardFactory $resultForwardFactory, |
| 47 | + ScopeConfigInterface $scopeConfig = null, |
| 48 | + Page $page = null |
23 | 49 | ) { |
24 | 50 | $this->resultForwardFactory = $resultForwardFactory; |
| 51 | + $this->scopeConfig = $scopeConfig ? : ObjectManager::getInstance()->get(ScopeConfigInterface::class); |
| 52 | + $this->page = $page ? : ObjectManager::getInstance()->get(Page::class); |
25 | 53 | parent::__construct($context); |
26 | 54 | } |
27 | 55 |
|
28 | 56 | /** |
29 | 57 | * Renders CMS Home page |
30 | 58 | * |
31 | 59 | * @param string|null $coreRoute |
32 | | - * @return \Magento\Framework\Controller\Result\Forward |
| 60 | + * |
| 61 | + * @return bool|ResponseInterface|Forward|ResultInterface|ResultPage |
| 62 | + * |
33 | 63 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
34 | 64 | */ |
35 | 65 | public function execute($coreRoute = null) |
36 | 66 | { |
37 | | - $pageId = $this->_objectManager->get( |
38 | | - \Magento\Framework\App\Config\ScopeConfigInterface::class |
39 | | - )->getValue( |
40 | | - \Magento\Cms\Helper\Page::XML_PATH_HOME_PAGE, |
41 | | - \Magento\Store\Model\ScopeInterface::SCOPE_STORE |
42 | | - ); |
43 | | - $resultPage = $this->_objectManager->get(\Magento\Cms\Helper\Page::class)->prepareResultPage($this, $pageId); |
| 67 | + $pageId = $this->scopeConfig->getValue(Page::XML_PATH_HOME_PAGE, ScopeInterface::SCOPE_STORE); |
| 68 | + $resultPage = $this->page->prepareResultPage($this, $pageId); |
44 | 69 | if (!$resultPage) { |
45 | | - /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ |
| 70 | + /** @var Forward $resultForward */ |
46 | 71 | $resultForward = $this->resultForwardFactory->create(); |
47 | 72 | $resultForward->forward('defaultIndex'); |
48 | 73 | return $resultForward; |
|
0 commit comments