Skip to content
Snippets Groups Projects
Commit 9b7be0ea authored by Igor Melnikov's avatar Igor Melnikov
Browse files

MAGETWO-59764: Create Serialize implementation of SerializerInterface

Creating Serialize implementation
parent 00363d01
No related merge requests found
...@@ -8,6 +8,8 @@ namespace Magento\Framework\App\ObjectManager\ConfigLoader; ...@@ -8,6 +8,8 @@ namespace Magento\Framework\App\ObjectManager\ConfigLoader;
use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\ObjectManager\ConfigLoaderInterface; use Magento\Framework\ObjectManager\ConfigLoaderInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\Serialize\Serializer\Serialize;
class Compiled implements ConfigLoaderInterface class Compiled implements ConfigLoaderInterface
{ {
...@@ -18,6 +20,11 @@ class Compiled implements ConfigLoaderInterface ...@@ -18,6 +20,11 @@ class Compiled implements ConfigLoaderInterface
*/ */
private $configCache = []; private $configCache = [];
/**
* @var SerializerInterface
*/
private $serializer;
/** /**
* {inheritdoc} * {inheritdoc}
*/ */
...@@ -26,7 +33,7 @@ class Compiled implements ConfigLoaderInterface ...@@ -26,7 +33,7 @@ class Compiled implements ConfigLoaderInterface
if (isset($this->configCache[$area])) { if (isset($this->configCache[$area])) {
return $this->configCache[$area]; return $this->configCache[$area];
} }
$this->configCache[$area] = unserialize(\file_get_contents(self::getFilePath($area))); $this->configCache[$area] = $this->getSerializer()->unserialize(\file_get_contents(self::getFilePath($area)));
return $this->configCache[$area]; return $this->configCache[$area];
} }
...@@ -39,6 +46,20 @@ class Compiled implements ConfigLoaderInterface ...@@ -39,6 +46,20 @@ class Compiled implements ConfigLoaderInterface
public static function getFilePath($area) public static function getFilePath($area)
{ {
$diPath = DirectoryList::getDefaultConfig()[DirectoryList::DI][DirectoryList::PATH]; $diPath = DirectoryList::getDefaultConfig()[DirectoryList::DI][DirectoryList::PATH];
return BP . '/' . $diPath . '/' . $area . '.json'; return BP . $diPath . '/' . $area . '.json';
}
/**
* Get serializer
*
* @return SerializerInterface
* @deprecated
*/
private function getSerializer()
{
if (null === $this->serializer) {
$this->serializer = new \Magento\Framework\Serialize\Serializer\Serialize();
}
return $this->serializer;
} }
} }
...@@ -9,6 +9,8 @@ namespace Magento\Setup\Module\Di\Compiler\Config\Writer; ...@@ -9,6 +9,8 @@ namespace Magento\Setup\Module\Di\Compiler\Config\Writer;
use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Setup\Module\Di\Compiler\Config\WriterInterface; use Magento\Setup\Module\Di\Compiler\Config\WriterInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\Serialize\Serializer\Serialize;
class Filesystem implements WriterInterface class Filesystem implements WriterInterface
{ {
...@@ -17,6 +19,11 @@ class Filesystem implements WriterInterface ...@@ -17,6 +19,11 @@ class Filesystem implements WriterInterface
*/ */
private $directoryList; private $directoryList;
/**
* @var SerializerInterface
*/
private $serializer;
/** /**
* Constructor * Constructor
* *
...@@ -40,7 +47,7 @@ class Filesystem implements WriterInterface ...@@ -40,7 +47,7 @@ class Filesystem implements WriterInterface
file_put_contents( file_put_contents(
$this->directoryList->getPath(DirectoryList::DI) . '/' . $key . '.json', $this->directoryList->getPath(DirectoryList::DI) . '/' . $key . '.json',
serialize($config) $this->getSerializer()->serialize($config)
); );
} }
...@@ -55,4 +62,19 @@ class Filesystem implements WriterInterface ...@@ -55,4 +62,19 @@ class Filesystem implements WriterInterface
mkdir($this->directoryList->getPath(DirectoryList::DI)); mkdir($this->directoryList->getPath(DirectoryList::DI));
} }
} }
/**
* Get serializer
*
* @return SerializerInterface
* @deprecated
*/
private function getSerializer()
{
if (null === $this->serializer) {
$this->serializer = \Magento\Framework\App\ObjectManager::getInstance()
->get(Serialize::class);
}
return $this->serializer;
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment