/** * Load data for current scope * * @return void */ protected function _loadScopedData() { $scope = $this->_configScope->getCurrentScope(); if (false == isset($this->_loadedScopes[$scope])) { if (false == in_array($scope, $this->_scopePriorityScheme)) { $this->_scopePriorityScheme[] = $scope; } foreach ($this->_scopePriorityScheme as $scopeCode) { if (false == isset($this->_loadedScopes[$scopeCode])) { if ($scopeCode !== 'primary' && ($data = $this->_cache->load($scopeCode . '::' . $this->_cacheId))) { $data = unserialize($data); } else { $data = $this->_reader->read($scopeCode); if ($scopeCode !== 'primary') { $this->_cache->save(serialize($data), $scopeCode . '::' . $this->_cacheId); } } $this->merge($data); $this->_loadedScopes[$scopeCode] = true; } if ($scopeCode == $scope) { break; } } } }
/** * @expectedException \Exception * @expectedExceptionMessage Some error */ public function testEmulateAreaCodeException() { $areaCode = 'original code'; $emulatedCode = 'emulated code'; $this->scopeMock->expects($this->once())->method('setCurrentScope')->with($areaCode); $this->model->setAreaCode($areaCode); $this->model->emulateAreaCode($emulatedCode, [$this, 'emulateAreaCodeCallbackException']); $this->assertEquals($this->model->getAreaCode(), $areaCode); }
/** * Modify pathInfo: strip down the front name and query parameters. * * @param \Magento\Framework\App\AreaList $areaList * @param \Magento\Framework\Config\ScopeInterface $configScope * @param null|string|\Zend_Uri $uri */ public function __construct(\Magento\Framework\App\AreaList $areaList, \Magento\Framework\Config\ScopeInterface $configScope, $uri = null) { parent::__construct($uri); $areaFrontName = $areaList->getFrontName($configScope->getCurrentScope()); $this->_pathInfo = $this->_requestUri; /** Remove base url and area from path */ $this->_pathInfo = preg_replace("#.*?/{$areaFrontName}/?#", '/', $this->_pathInfo); /** Remove GET parameters from path */ $this->_pathInfo = preg_replace('#\\?.*#', '', $this->_pathInfo); }
/** * Modify pathInfo: strip down the front name and query parameters. * * @param AreaList $areaList * @param ScopeInterface $configScope * @param CookieReaderInterface $cookieReader * @param null|string|\Zend_Uri $uri */ public function __construct(CookieReaderInterface $cookieReader, AreaList $areaList, ScopeInterface $configScope, $uri = null) { parent::__construct($cookieReader, $uri); $pathInfo = $this->getRequestUri(); /** Remove base url and area from path */ $areaFrontName = $areaList->getFrontName($configScope->getCurrentScope()); $pathInfo = preg_replace("#.*?/{$areaFrontName}/?#", '/', $pathInfo); /** Remove GET parameters from path */ $pathInfo = preg_replace('#\\?.*#', '', $pathInfo); $this->setPathInfo($pathInfo); }
/** * {@inheritDoc} * * @return string */ protected function getXmlPathPrefix() { if ($this->scope->getCurrentScope() == \Magento\Framework\App\Area::AREA_ADMINHTML) { return self::XML_PATH_ADMIN_AREA; } return self::XML_PATH_FRONTED_AREA; }
/** * Set area code * * @param string $code * @return void * @throws \Magento\Framework\Exception */ public function setAreaCode($code) { if (isset($this->_areaCode)) { throw new \Magento\Framework\Exception('Area code is already set'); } $this->_configScope->setCurrentScope($code); $this->_areaCode = $code; }
/** * Fetch routes from configs by area code and router id * * @param string $scope * @return array */ protected function _getRoutes($scope = null) { $scope = $scope ?: $this->_configScope->getCurrentScope(); if (isset($this->_routes[$scope])) { return $this->_routes[$scope]; } $cacheId = $scope . '::' . $this->_cacheId; $cachedRoutes = unserialize($this->_cache->load($cacheId)); if (is_array($cachedRoutes)) { $this->_routes[$scope] = $cachedRoutes; return $cachedRoutes; } $routers = $this->_reader->read($scope); $routes = $routers[$this->_areaList->getDefaultRouter($scope)]['routes']; $this->_cache->save(serialize($routes), $cacheId); $this->_routes[$scope] = $routes; return $routes; }
/** * Generate URI of SOAP endpoint. * * @return string */ public function getEndpointUri() { $storeCode = $this->_storeManager->getStore()->getCode() === \Magento\Store\Model\Store::ADMIN_CODE ? \Magento\Webapi\Controller\PathProcessor::ALL_STORE_CODE : $this->_storeManager->getStore()->getCode(); return $this->_storeManager->getStore()->getBaseUrl() . $this->_areaList->getFrontName($this->_configScope->getCurrentScope()) . '/' . $storeCode; }
/** * Generate URI of SOAP endpoint. * * @return string */ public function getEndpointUri() { return $this->_storeManager->getStore()->getBaseUrl() . $this->_areaList->getFrontName($this->_configScope->getCurrentScope()) . '/' . $this->_storeManager->getStore()->getCode(); }
/** * @param int $limitTime * @param int $scope * @dataProvider dataProviderNumberValueWithScope */ public function testGetMinTimeBetweenPasswordResetRequests($limitTime, $scope) { $this->scopeConfigMock->expects($this->once())->method('getValue')->with($this->getXmlPathPrefix($scope) . \Magento\Security\Model\Config::XML_PATH_MIN_TIME_BETWEEN_PASSWORD_RESET_REQUESTS)->willReturn($limitTime); $this->scopeMock->expects($this->once())->method('getCurrentScope')->willReturn($scope); $this->assertEquals($limitTime * 60, $this->model->getMinTimeBetweenPasswordResetRequests()); }