From 6268ee6789b08256da01fd5f6d701dc446d58745 Mon Sep 17 00:00:00 2001 From: tomazpu <32056440+tomazpu@users.noreply.github.com> Date: Tue, 31 Oct 2017 14:56:24 +0100 Subject: [PATCH 1/2] #32 added ScopePool and ReaderPool for 2.2 support --- Model/App/Config/ReaderPool.php | 36 +++++++ Model/App/Config/ScopePool.php | 168 ++++++++++++++++++++++++++++++++ Model/Support.php | 6 +- 3 files changed, 207 insertions(+), 3 deletions(-) create mode 100644 Model/App/Config/ReaderPool.php create mode 100644 Model/App/Config/ScopePool.php diff --git a/Model/App/Config/ReaderPool.php b/Model/App/Config/ReaderPool.php new file mode 100644 index 0000000..2815e2f --- /dev/null +++ b/Model/App/Config/ReaderPool.php @@ -0,0 +1,36 @@ +_readers = $readers; + } + + /** + * Retrieve reader by scope type + * + * @param string $scopeType + * @return mixed + */ + public function getReader($scopeType) + { + return $this->_readers[$scopeType]; + } +} \ No newline at end of file diff --git a/Model/App/Config/ScopePool.php b/Model/App/Config/ScopePool.php new file mode 100644 index 0000000..8110acb --- /dev/null +++ b/Model/App/Config/ScopePool.php @@ -0,0 +1,168 @@ +_readerPool = $readerPool; + $this->_dataFactory = $dataFactory; + $this->_cache = $cache; + $this->_cacheId = $cacheId; + $this->_scopeResolverPool = $scopeResolverPool; + } + + /** + * Retrieve config section + * + * @param string $scopeType + * @param string|\Magento\Framework\DataObject|null $scopeCode + * @return \Magento\Framework\App\Config\DataInterface + */ + public function getScope($scopeType, $scopeCode = null) + { + $scopeCode = $this->_getScopeCode($scopeType, $scopeCode); + + $code = $scopeType . '|' . $scopeCode; + + if (!isset($this->_scopes[$code])) { + // Key by url to support dynamic {{base_url}} and port assignments + $host = $this->getRequest()->getHttpHost(); + $port = $this->getRequest()->getServer('SERVER_PORT'); + $path = $this->getRequest()->getBasePath(); + + $urlInfo = $host . $port . trim($path, '/'); + $cacheKey = $this->_cacheId . '|' . $code . '|' . $urlInfo; + $data = $this->_cache->load($cacheKey); + + if ($data) { + $data = unserialize($data); + } else { + $reader = $this->_readerPool->getReader($scopeType); + if ($scopeType === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) { + $data = $reader->read(); + } else { + $data = $reader->read($scopeCode); + } + + $this->_cache->save(serialize($data), $cacheKey, [self::CACHE_TAG]); + } + $this->_scopes[$code] = $this->_dataFactory->create(['data' => $data]); + } + return $this->_scopes[$code]; + } + + /** + * Retrieve scope code value + * + * @param string $scopeType + * @param string|\Magento\Framework\DataObject|null $scopeCode + * @return string + */ + protected function _getScopeCode($scopeType, $scopeCode) + { + return $this->getScopeCodeResolver()->resolve($scopeType, $scopeCode); + } + + /** + * @deprecated + * @return ScopeCodeResolver + */ + public function getScopeCodeResolver() + { + if ($this->scopeCodeResolver === null) { + $this->scopeCodeResolver = ObjectManager::getInstance()->get(ScopeCodeResolver::class); + } + return $this->scopeCodeResolver; + } + + /** + * @deprecated + * @return RequestInterface + */ + private function getRequest() + { + if ($this->request === null) { + $this->request = ObjectManager::getInstance()->get(RequestInterface::class); + } + return $this->request; + } + + /** + * Clear cache of all scopes + * + * @return void + */ + public function clean() + { + $this->_scopes = []; + $this->_cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [self::CACHE_TAG]); + } +} diff --git a/Model/Support.php b/Model/Support.php index 521babf..8cfb33d 100644 --- a/Model/Support.php +++ b/Model/Support.php @@ -61,7 +61,7 @@ class Support protected $_paymentConfig; /** - * @var \Magento\Framework\App\Config\ScopePool + * @var \Wirecard\CheckoutSeamless\Model\App\Config\ScopePool */ protected $_scopePool; @@ -184,7 +184,7 @@ class Support /** * @param \Wirecard\CheckoutSeamless\Helper\Data $dataHelper - * @param \Magento\Framework\App\Config\ScopePool $scopePool + * @param \Wirecard\CheckoutSeamless\Model\App\Config\ScopePool $scopePool * @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder * @param \Magento\Framework\Module\ModuleList\Loader $moduleLoader * @param \Magento\Payment\Model\Config $paymentConfig @@ -192,7 +192,7 @@ class Support */ public function __construct( \Wirecard\CheckoutSeamless\Helper\Data $dataHelper, - \Magento\Framework\App\Config\ScopePool $scopePool, + \Wirecard\CheckoutSeamless\Model\App\Config\ScopePool $scopePool, \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, \Magento\Framework\Module\ModuleList\Loader $moduleLoader, \Magento\Payment\Model\Config $paymentConfig From 11226f8af649ccd5ab4cea937e961d315a5189f0 Mon Sep 17 00:00:00 2001 From: tomazpu <32056440+tomazpu@users.noreply.github.com> Date: Tue, 31 Oct 2017 16:08:32 +0100 Subject: [PATCH 2/2] #32 Version increase --- Helper/Data.php | 2 +- README.md | 2 +- composer.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index 4a5aaad..acc7ae5 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -38,7 +38,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper { - protected $_pluginVersion = '1.0.8'; + protected $_pluginVersion = '1.0.9'; protected $_pluginName = 'Wirecard/CheckoutSeamless'; /** diff --git a/README.md b/README.md index 37767e5..7886518 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![License](https://img.shields.io/badge/license-GPLv2-blue.svg)](https://raw.githubusercontent.com/wirecard/Magento2-WCP/master/LICENSE) [![PHP v5.6](https://img.shields.io/badge/php-v5.5-yellow.svg)](http://www.php.net) [![PHP v7.0](https://img.shields.io/badge/php-v7.0-yellow.svg)](http://www.php.net) -[![Magento v2.1.4](https://img.shields.io/badge/magento-v2.1.8-green.svg)](https://magento.com/) +[![Magento v2.2.0](https://img.shields.io/badge/magento-v2.2.0-green.svg)](https://magento.com/) Wirecard Checkout Seamless extension for Magento 2. diff --git a/composer.json b/composer.json index 4cf523b..905a312 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "wirecard/magento2-wcs", "description": "Wirecard Checkout Seamless", "type": "magento2-module", - "version": "1.0.8", + "version": "1.0.9", "license": [ "MIT" ],