diff --git a/app/code/Magento/Ui/Model/Manager.php b/app/code/Magento/Ui/Model/Manager.php index 348b7d398800d71bc763eecb719313b89f44252e..8029bbf959f0288284659910877cdf4f8f89166f 100644 --- a/app/code/Magento/Ui/Model/Manager.php +++ b/app/code/Magento/Ui/Model/Manager.php @@ -17,6 +17,8 @@ use Magento\Framework\View\Element\UiComponent\Config\ManagerInterface; use Magento\Framework\View\Element\UiComponent\Config\Provider\Component\Definition as ComponentDefinition; use Magento\Framework\View\Element\UiComponent\Config\ReaderFactory; use Magento\Framework\View\Element\UiComponent\Config\UiReaderInterface; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\App\ObjectManager; /** * Class Manager @@ -94,6 +96,11 @@ class Manager implements ManagerInterface */ protected $uiReader; + /** + * @var SerializerInterface + */ + private $serializer; + /** * @param ComponentDefinition $componentConfigProvider * @param DomMergerInterface $domMerger @@ -102,6 +109,7 @@ class Manager implements ManagerInterface * @param AggregatedFileCollectorFactory $aggregatedFileCollectorFactory * @param CacheInterface $cache * @param InterpreterInterface $argumentInterpreter + * @param SerializerInterface|null $serializer */ public function __construct( ComponentDefinition $componentConfigProvider, @@ -110,7 +118,8 @@ class Manager implements ManagerInterface ArrayObjectFactory $arrayObjectFactory, AggregatedFileCollectorFactory $aggregatedFileCollectorFactory, CacheInterface $cache, - InterpreterInterface $argumentInterpreter + InterpreterInterface $argumentInterpreter, + SerializerInterface $serializer = null ) { $this->componentConfigProvider = $componentConfigProvider; $this->domMerger = $domMerger; @@ -120,6 +129,7 @@ class Manager implements ManagerInterface $this->aggregatedFileCollectorFactory = $aggregatedFileCollectorFactory; $this->cache = $cache; $this->argumentInterpreter = $argumentInterpreter; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); } /** @@ -164,9 +174,14 @@ class Manager implements ManagerInterface $cachedPool = $this->cache->load($cacheID); if ($cachedPool === false) { $this->prepare($name); - $this->cache->save($this->componentsPool->serialize(), $cacheID); + $this->cache->save( + $this->serializer->serialize($this->componentsPool->getArrayCopy()), + $cacheID + ); } else { - $this->componentsPool->unserialize($cachedPool); + $this->componentsPool->exchangeArray( + $this->serializer->unserialize($cachedPool) + ); } $this->componentsData->offsetSet($name, $this->componentsPool); $this->componentsData->offsetSet($name, $this->evaluateComponentArguments($this->getData($name))); diff --git a/app/code/Magento/Ui/Test/Unit/Model/ManagerTest.php b/app/code/Magento/Ui/Test/Unit/Model/ManagerTest.php index 37f97af4597ac069312dbb1e1fb404e36cbdf12f..fe60a646d5ae42906e5fe230c272b550e3d1ed25 100644 --- a/app/code/Magento/Ui/Test/Unit/Model/ManagerTest.php +++ b/app/code/Magento/Ui/Test/Unit/Model/ManagerTest.php @@ -75,6 +75,9 @@ class ManagerTest extends \PHPUnit_Framework_TestCase */ protected $aggregatedFileCollectorFactory; + /** @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject */ + private $serializer; + protected function setUp() { $this->componentConfigProvider = $this->getMockBuilder( @@ -105,6 +108,24 @@ class ManagerTest extends \PHPUnit_Framework_TestCase ->getMockForAbstractClass(); $this->argumentInterpreter = $this->getMockBuilder(\Magento\Framework\Data\Argument\InterpreterInterface::class) ->getMockForAbstractClass(); + $this->serializer = $this->getMockBuilder( + \Magento\Framework\Serialize\SerializerInterface::class + )->getMockForAbstractClass(); + $this->serializer->expects($this->any()) + ->method('serialize') + ->willReturnCallback( + function ($value) { + return json_encode($value); + } + ); + $this->serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + } + ); + $this->manager = new Manager( $this->componentConfigProvider, $this->domMerger, @@ -112,7 +133,8 @@ class ManagerTest extends \PHPUnit_Framework_TestCase $this->arrayObjectFactory, $this->aggregatedFileCollectorFactory, $this->cacheConfig, - $this->argumentInterpreter + $this->argumentInterpreter, + $this->serializer ); } @@ -192,7 +214,7 @@ class ManagerTest extends \PHPUnit_Framework_TestCase [ 'test_component1', new \ArrayObject(), - $cachedData->serialize(), + json_encode($cachedData->getArrayCopy()), [], [ 'test_component1' => [