diff --git a/app/code/Magento/Config/App/Config/Type/System.php b/app/code/Magento/Config/App/Config/Type/System.php index a8b98d3824b5e749cf2911b3f3f6f0283e5eb187..4a3c6da8379153a240e4869592fcef31788df608 100644 --- a/app/code/Magento/Config/App/Config/Type/System.php +++ b/app/code/Magento/Config/App/Config/Type/System.php @@ -10,6 +10,8 @@ use Magento\Framework\App\Config\ConfigSourceInterface; use Magento\Framework\App\Config\Spi\PostProcessorInterface; use Magento\Framework\Cache\FrontendInterface; use Magento\Framework\DataObject; +use Magento\Framework\Serialize\Serializer\Serialize; +use Magento\Framework\Serialize\SerializerInterface; use Magento\Store\Model\Config\Processor\Fallback; /** @@ -53,6 +55,11 @@ class System implements ConfigTypeInterface */ private $fallback; + /** + * @var Serialize + */ + private $serializer; + /** * System constructor. * @param ConfigSourceInterface $source @@ -60,12 +67,14 @@ class System implements ConfigTypeInterface * @param Fallback $fallback * @param FrontendInterface $cache * @param int $cachingNestedLevel + * @param Serialize $serializer */ public function __construct( ConfigSourceInterface $source, PostProcessorInterface $postProcessor, Fallback $fallback, FrontendInterface $cache, + Serialize $serializer, $cachingNestedLevel = 1 ) { $this->source = $source; @@ -73,6 +82,7 @@ class System implements ConfigTypeInterface $this->cache = $cache; $this->cachingNestedLevel = $cachingNestedLevel; $this->fallback = $fallback; + $this->serializer = $serializer; } /** @@ -88,11 +98,16 @@ class System implements ConfigTypeInterface if (!$data) { $data = $this->fallback->process($this->source->get()); $this->data = new DataObject($data); + //Placeholder processing need system config - so we need to save intermediate result $data = $this->postProcessor->process($data); $this->data = new DataObject($data); - $this->cache->save(serialize($this->data), self::CONFIG_TYPE, [self::CACHE_TAG]); + $this->cache->save( + $this->serializer->serialize($this->data->getData()), + self::CONFIG_TYPE, + [self::CACHE_TAG] + ); } else { - $this->data = unserialize($data); + $this->data = new DataObject($this->serializer->unserialize($data)); } } diff --git a/app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php b/app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php index 276082ae8a19c9fa2e19e30a72b3c2a0c26dfaae..be541228bf6d88a5ad7e459ba77a34e896c863a1 100644 --- a/app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php +++ b/app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php @@ -8,8 +8,9 @@ namespace Magento\Config\Test\Unit\App\Config\Type; use Magento\Config\App\Config\Type\System; use Magento\Framework\App\Config\ConfigSourceInterface; use Magento\Framework\App\Config\Spi\PostProcessorInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Cache\FrontendInterface; -use Magento\Framework\DataObject; +use Magento\Framework\Serialize\Serializer\Serialize; use Magento\Store\Model\Config\Processor\Fallback; /** @@ -43,6 +44,11 @@ class SystemTest extends \PHPUnit_Framework_TestCase */ private $configType; + /** + * @var Serialize|\PHPUnit_Framework_MockObject_MockObject + */ + private $serializer; + public function setUp() { $this->source = $this->getMockBuilder(ConfigSourceInterface::class) @@ -54,11 +60,15 @@ class SystemTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->cache = $this->getMockBuilder(FrontendInterface::class) ->getMockForAbstractClass(); + $this->serializer = $this->getMockBuilder(Serialize::class) + ->disableOriginalConstructor() + ->getMock(); $this->configType = new System( $this->source, $this->postProcessor, $this->fallback, - $this->cache + $this->cache, + $this->serializer ); } @@ -79,12 +89,22 @@ class SystemTest extends \PHPUnit_Framework_TestCase ] ] ]; + $this->cache->expects($this->once()) ->method('load') ->with(System::CONFIG_TYPE) - ->willReturn($isCached ? serialize(new DataObject($data)) : null); + ->willReturn($isCached ? $data : null); + + if ($isCached) { + $this->serializer->expects($this->once()) + ->method('unserialize') + ->willReturn($data); + } if (!$isCached) { + $this->serializer->expects($this->once()) + ->method('serialize') + ->willReturn(serialize($data)); $this->source->expects($this->once()) ->method('get') ->willReturn($data); @@ -99,7 +119,7 @@ class SystemTest extends \PHPUnit_Framework_TestCase $this->cache->expects($this->once()) ->method('save') ->with( - serialize(new DataObject($data)), + serialize($data), System::CONFIG_TYPE, [System::CACHE_TAG] ); diff --git a/app/code/Magento/Eav/Model/Entity/AttributeCache.php b/app/code/Magento/Eav/Model/Entity/AttributeCache.php index 60727aa654e1c6daa9f334162ceca09f39792328..2aca4aa58968352e983cbeeb7119b290027e1a4d 100644 --- a/app/code/Magento/Eav/Model/Entity/AttributeCache.php +++ b/app/code/Magento/Eav/Model/Entity/AttributeCache.php @@ -9,6 +9,9 @@ namespace Magento\Eav\Model\Entity; use Magento\Eav\Model\Entity\Attribute\AbstractAttribute; use Magento\Framework\App\CacheInterface; use Magento\Framework\App\Cache\StateInterface; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Serialize\Serializer\Serialize; +use Magento\Framework\Serialize\SerializerInterface; /** * Class AttributeCache @@ -43,6 +46,11 @@ class AttributeCache */ private $unsupportedTypes; + /** + * @var SerializerInterface + */ + private $serializer; + /** * AttributeCache constructor. * @param CacheInterface $cache @@ -89,7 +97,7 @@ class AttributeCache $cacheKey = self::ATTRIBUTES_CACHE_PREFIX . $entityType . $suffix; $attributesData = $this->cache->load($cacheKey); if ($attributesData) { - $attributes = unserialize($attributesData); + $attributes = $this->getSerializer()->unserialize($attributesData); $this->attributeInstances[$entityType . $suffix] = $attributes; return $attributes; } @@ -113,7 +121,7 @@ class AttributeCache $this->attributeInstances[$entityType . $suffix] = $attributes; if ($this->isAttributeCacheEnabled()) { $cacheKey = self::ATTRIBUTES_CACHE_PREFIX . $entityType . $suffix; - $attributesData = serialize($attributes); + $attributesData = $this->getSerializer()->serialize($attributes); $this->cache->save( $attributesData, $cacheKey, @@ -145,4 +153,19 @@ class AttributeCache } return true; } + + /** + * Retrieve handler which allows serialize/deserialize data + * + * @deprecated + * @return SerializerInterface + */ + private function getSerializer() + { + if (!$this->serializer) { + $this->serializer = ObjectManager::getInstance()->get(Serialize::class); + } + + return $this->serializer; + } } diff --git a/app/code/Magento/Store/App/Config/Type/Scopes.php b/app/code/Magento/Store/App/Config/Type/Scopes.php index f66e172bc638eaa1d5fdbbfe4b412497f3882652..dbe939aac1be44a08f6d8b68f2e353fd3e44356f 100644 --- a/app/code/Magento/Store/App/Config/Type/Scopes.php +++ b/app/code/Magento/Store/App/Config/Type/Scopes.php @@ -9,6 +9,8 @@ use Magento\Framework\App\Config\ConfigTypeInterface; use Magento\Framework\App\Config\ConfigSourceInterface; use Magento\Framework\Cache\FrontendInterface; use Magento\Framework\DataObject; +use Magento\Framework\Serialize\Serializer\Serialize; +use Magento\Framework\Serialize\SerializerInterface; use Magento\Store\Model\Group; use Magento\Store\Model\Store; use Magento\Store\Model\Website; @@ -42,20 +44,28 @@ class Scopes implements ConfigTypeInterface */ private $cachingNestedLevel; + /** + * @var Serialize + */ + private $serializer; + /** * System constructor. * @param ConfigSourceInterface $source * @param FrontendInterface $cache * @param int $cachingNestedLevel + * @param SerializerInterface $serializer */ public function __construct( ConfigSourceInterface $source, FrontendInterface $cache, + Serialize $serializer, $cachingNestedLevel = 1 ) { $this->source = $source; $this->cache = $cache; $this->cachingNestedLevel = $cachingNestedLevel; + $this->serializer = $serializer; } /** @@ -69,12 +79,12 @@ class Scopes implements ConfigTypeInterface if (!$data) { $this->data = new DataObject($this->source->get()); $this->cache->save( - serialize($this->data), + $this->serializer->serialize($this->data->getData()), self::CONFIG_TYPE, [Group::CACHE_TAG, Store::CACHE_TAG, Website::CACHE_TAG] ); } else { - $this->data = unserialize($data); + $this->data = new DataObject($this->serializer->unserialize($data)); } } diff --git a/app/code/Magento/Store/Test/Unit/App/Config/Type/ScopesTest.php b/app/code/Magento/Store/Test/Unit/App/Config/Type/ScopesTest.php index 12e85d8631031452cff8dea3fd54c47ef669735d..94efcc7db8cc7b37fe7ed514c7345d5b27335bea 100644 --- a/app/code/Magento/Store/Test/Unit/App/Config/Type/ScopesTest.php +++ b/app/code/Magento/Store/Test/Unit/App/Config/Type/ScopesTest.php @@ -8,6 +8,7 @@ namespace Magento\Store\Test\Unit\App\Config\Type; use Magento\Framework\App\Config\ConfigSourceInterface; use Magento\Framework\Cache\FrontendInterface; use Magento\Framework\DataObject; +use Magento\Framework\Serialize\Serializer\Serialize; use Magento\Store\App\Config\Type\Scopes; use Magento\Store\Model\Group; use Magento\Store\Model\Store; @@ -30,14 +31,22 @@ class ScopesTest extends \PHPUnit_Framework_TestCase */ private $configType; + /** + * @var Serialize | \PHPUnit_Framework_MockObject_MockObject + */ + private $serializer; + public function setUp() { $this->source = $this->getMockBuilder(ConfigSourceInterface::class) ->getMockForAbstractClass(); $this->cache = $this->getMockBuilder(FrontendInterface::class) ->getMockForAbstractClass(); + $this->serializer = $this->getMockBuilder(Serialize::class) + ->disableOriginalConstructor() + ->getMock(); - $this->configType = new Scopes($this->source, $this->cache); + $this->configType = new Scopes($this->source, $this->cache, $this->serializer); } /** @@ -58,9 +67,18 @@ class ScopesTest extends \PHPUnit_Framework_TestCase $this->cache->expects($this->once()) ->method('load') ->with(Scopes::CONFIG_TYPE) - ->willReturn($isCached ? serialize(new DataObject($data)) : false); + ->willReturn($isCached ? serialize($data) : false); + + if ($isCached) { + $this->serializer->expects($this->once()) + ->method('unserialize') + ->willReturn($data); + } if (!$isCached) { + $this->serializer->expects($this->once()) + ->method('serialize') + ->willReturn(serialize($data)); $this->source->expects($this->once()) ->method('get') ->with('') @@ -68,7 +86,7 @@ class ScopesTest extends \PHPUnit_Framework_TestCase $this->cache->expects($this->once()) ->method('save') ->with( - serialize(new DataObject($data)), + serialize($data), Scopes::CONFIG_TYPE, [Group::CACHE_TAG, Store::CACHE_TAG, Website::CACHE_TAG] ); diff --git a/app/code/Magento/Theme/Model/Theme/ThemeProvider.php b/app/code/Magento/Theme/Model/Theme/ThemeProvider.php index 89d7bfc18d30c27026777f7864b562354277dfee..68e675387f90552d3370cccca6ed5e0bca3a7994 100644 --- a/app/code/Magento/Theme/Model/Theme/ThemeProvider.php +++ b/app/code/Magento/Theme/Model/Theme/ThemeProvider.php @@ -6,6 +6,8 @@ namespace Magento\Theme\Model\Theme; use Magento\Framework\App\ObjectManager; +use Magento\Framework\Serialize\Serializer\Serialize; +use Magento\Framework\Serialize\SerializerInterface; use Magento\Framework\View\Design\Theme\ListInterface; use Magento\Framework\App\DeploymentConfig; @@ -44,6 +46,11 @@ class ThemeProvider implements \Magento\Framework\View\Design\Theme\ThemeProvide */ private $deploymentConfig; + /** + * @var SerializerInterface + */ + private $serializer; + /** * ThemeProvider constructor. * @@ -77,13 +84,13 @@ class ThemeProvider implements \Magento\Framework\View\Design\Theme\ThemeProvide /** @var $themeCollection \Magento\Theme\Model\ResourceModel\Theme\Collection */ $theme = $this->cache->load('theme'. $fullPath); if ($theme) { - $this->themes[$fullPath] = unserialize($theme); + $this->themes[$fullPath] = $this->getSerializer()->unserialize($theme); return $this->themes[$fullPath]; } $themeCollection = $this->collectionFactory->create(); $item = $themeCollection->getThemeByFullPath($fullPath); if ($item->getId()) { - $themeData = serialize($item); + $themeData = $this->getSerializer()->serialize($item); $this->cache->save($themeData, 'theme' . $fullPath); $this->cache->save($themeData, 'theme-by-id-' . $item->getId()); $this->themes[$fullPath] = $item; @@ -115,14 +122,14 @@ class ThemeProvider implements \Magento\Framework\View\Design\Theme\ThemeProvide } $theme = $this->cache->load('theme-by-id-' . $themeId); if ($theme) { - $this->themes[$themeId] = unserialize($theme); + $this->themes[$themeId] = $this->getSerializer()->unserialize($theme); return $this->themes[$themeId]; } /** @var $themeModel \Magento\Framework\View\Design\ThemeInterface */ $themeModel = $this->themeFactory->create(); $themeModel->load($themeId); if ($themeModel->getId()) { - $this->cache->save(serialize($themeModel), 'theme-by-id-' . $themeId); + $this->cache->save($this->getSerializer()->serialize($themeModel), 'theme-by-id-' . $themeId); $this->themes[$themeId] = $themeModel; } return $themeModel; @@ -151,4 +158,19 @@ class ThemeProvider implements \Magento\Framework\View\Design\Theme\ThemeProvide } return $this->deploymentConfig; } + + /** + * Retrieve handler which allows serialize/deserialize data + * + * @deprecated + * @return SerializerInterface + */ + private function getSerializer() + { + if (!$this->serializer) { + $this->serializer = ObjectManager::getInstance()->get(Serialize::class); + } + + return $this->serializer; + } } diff --git a/app/code/Magento/User/Model/ResourceModel/User.php b/app/code/Magento/User/Model/ResourceModel/User.php index d3e228d44358136c748258c47da3f7f2b2bba76b..fee2a07b21c8adc74556a9d9e7636b830827eeb9 100644 --- a/app/code/Magento/User/Model/ResourceModel/User.php +++ b/app/code/Magento/User/Model/ResourceModel/User.php @@ -9,6 +9,9 @@ namespace Magento\User\Model\ResourceModel; use Magento\Authorization\Model\Acl\Role\Group as RoleGroup; use Magento\Authorization\Model\Acl\Role\User as RoleUser; use Magento\Authorization\Model\UserContextInterface; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Serialize\Serializer\Serialize; +use Magento\Framework\Serialize\SerializerInterface; use Magento\User\Model\User as ModelUser; /** @@ -34,6 +37,11 @@ class User extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb */ protected $dateTime; + /** + * @var SerializerInterface + */ + private $serializer; + /** * Construct * @@ -617,4 +625,19 @@ class User extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb [':user_id' => $userId] ); } + + /** + * Retrieve handler which allows serialize/deserialize data + * + * @deprecated + * @return SerializerInterface + */ + private function getSerializer() + { + if (!$this->serializer) { + $this->serializer = ObjectManager::getInstance()->get(Serialize::class); + } + + return $this->serializer; + } }