diff --git a/vendor/magento/module-website-restriction/Controller/Index/Stub.php b/vendor/magento/module-website-restriction/Controller/Index/Stub.php index cbae6f84d08f..6a40c730f00a 100644 --- a/vendor/magento/module-website-restriction/Controller/Index/Stub.php +++ b/vendor/magento/module-website-restriction/Controller/Index/Stub.php @@ -5,18 +5,37 @@ */ namespace Magento\WebsiteRestriction\Controller\Index; +use Magento\Cms\Model\PageFactory; +use Magento\Framework\App\Action\Action; +use Magento\Framework\App\Action\Context; +use Magento\Framework\App\Cache\Type\Config; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Registry; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; +use Magento\Framework\View\DesignInterface; +use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; +use Magento\Framework\View\Page\Config as ViewPageConfig; +use Magento\WebsiteRestriction\Model\Config as WebsiteRestrictionConfig; +use Magento\Store\Model\Website; + /** * Website stub controller + * + * @SuppressWarnings(PHPMD.AllPurposeAction) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Stub extends \Magento\Framework\App\Action\Action +class Stub extends Action { /** * @var string */ - protected $_stubPageIdentifier = \Magento\WebsiteRestriction\Model\Config::XML_PATH_RESTRICTION_LANDING_PAGE; + protected $_stubPageIdentifier = WebsiteRestrictionConfig::XML_PATH_RESTRICTION_LANDING_PAGE; /** - * @var \Magento\Framework\App\Cache\Type\Config + * @var Config */ protected $_configCacheType; @@ -33,49 +52,55 @@ class Stub extends \Magento\Framework\App\Action\Action protected $_cacheKeyPrefix = 'RESTRICTION_LANGING_PAGE_'; /** - * Core registry - * - * @var \Magento\Framework\Registry + * @var Registry */ protected $_coreRegistry; /** - * @var \Magento\Store\Model\Website + * @var Website */ protected $_website; /** - * @var \Magento\Cms\Model\PageFactory + * @var PageFactory */ protected $_pageFactory; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @var ScopeConfigInterface */ protected $_scopeConfig; /** - * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface + * @var TimezoneInterface */ protected $_localeDate; /** - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Framework\App\Cache\Type\Config $configCacheType - * @param \Magento\Store\Model\Website $website - * @param \Magento\Cms\Model\PageFactory $pageFactory - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate + * @var StoreManagerInterface + */ + private $storeManager; + + /** + * @param Context $context + * @param Registry $coreRegistry + * @param Config $configCacheType + * @param Website $website + * @param PageFactory $pageFactory + * @param ScopeConfigInterface $scopeConfig + * @param TimezoneInterface $localeDate + * @param StoreManagerInterface|null $storeManager + * @throws NoSuchEntityException */ public function __construct( - \Magento\Framework\App\Action\Context $context, - \Magento\Framework\Registry $coreRegistry, - \Magento\Framework\App\Cache\Type\Config $configCacheType, - \Magento\Store\Model\Website $website, - \Magento\Cms\Model\PageFactory $pageFactory, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate + Context $context, + Registry $coreRegistry, + Config $configCacheType, + Website $website, + PageFactory $pageFactory, + ScopeConfigInterface $scopeConfig, + TimezoneInterface $localeDate, + ?StoreManagerInterface $storeManager = null ) { $this->_coreRegistry = $coreRegistry; $this->_configCacheType = $configCacheType; @@ -83,8 +108,12 @@ public function __construct( $this->_pageFactory = $pageFactory; $this->_scopeConfig = $scopeConfig; $this->_localeDate = $localeDate; + $this->storeManager = $storeManager ?? ObjectManager::getInstance() + ->get(StoreManagerInterface::class); + $websiteId = $this->storeManager->getStore()->getWebsiteId(); parent::__construct($context); - $this->_cacheKey = $this->_cacheKeyPrefix . $this->_website->getId(); + + $this->_cacheKey = $this->_cacheKeyPrefix . $websiteId; } /** @@ -101,11 +130,10 @@ public function execute() /** * Generating page and save it to cache */ - /** @var \Magento\Cms\Model\Page $page */ $page = $this->_pageFactory->create()->load( $this->_scopeConfig->getValue( $this->_stubPageIdentifier, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ), 'identifier' ); @@ -120,7 +148,7 @@ public function execute() ) ) { $this->_objectManager->get( - \Magento\Framework\View\DesignInterface::class + DesignInterface::class )->setDesignTheme( $page->getCustomTheme() ); @@ -129,8 +157,8 @@ public function execute() $this->_view->addActionLayoutHandles(); if ($page->getPageLayout()) { - /** @var \Magento\Framework\View\Page\Config $pageConfig */ - $pageConfig = $this->_objectManager->get(\Magento\Framework\View\Page\Config::class); + /** @var ViewPageConfig $pageConfig */ + $pageConfig = $this->_objectManager->get(ViewPageConfig::class); $pageConfig->setPageLayout($page->getPageLayout()); } @@ -141,7 +169,7 @@ public function execute() $this->_configCacheType->save( $this->getResponse()->getBody(), $this->_cacheKey, - [\Magento\Store\Model\Website::CACHE_TAG] + [Website::CACHE_TAG] ); } }