Skip to content

Commit 13ad511

Browse files
author
Mykola Palamar
committed
MAGETWO-65293: Remove uses of unserialize
1 parent 3f75fac commit 13ad511

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/internal/Magento/Framework/Unserialize/Test/Unit/UnserializeTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Framework\Unserialize\Test\Unit;
77

8+
use Magento\Framework\Serialize\Serializer\Serialize;
9+
810
/**
911
* @package Magento\Framework
1012
*/
@@ -15,7 +17,9 @@ class UnserializeTest extends \PHPUnit_Framework_TestCase
1517

1618
protected function setUp()
1719
{
18-
$this->unserialize = new \Magento\Framework\Unserialize\Unserialize();
20+
$this->unserialize = new \Magento\Framework\Unserialize\Unserialize(
21+
new Serialize()
22+
);
1923
}
2024

2125
public function testUnserializeArray()

lib/internal/Magento/Framework/Unserialize/Unserialize.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,29 @@
66

77
namespace Magento\Framework\Unserialize;
88

9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Serialize\Serializer\Serialize;
11+
912
/**
1013
* @deprecated
1114
*/
1215
class Unserialize
1316
{
17+
/**
18+
* Serializer for safe string unserialization.
19+
*
20+
* @var Serialize
21+
*/
22+
private $serializer;
23+
24+
/**
25+
* @param Serialize|null $serializer Optional parameter for backward compatibility.
26+
*/
27+
public function __construct (Serialize $serializer = null)
28+
{
29+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Serialize::class);
30+
}
31+
1432
/**
1533
* @param string $string
1634
* @return bool|mixed
@@ -21,6 +39,6 @@ public function unserialize($string)
2139
trigger_error('String contains serialized object');
2240
return false;
2341
}
24-
return unserialize($string);
42+
return $this->serializer->unserialize($string);
2543
}
2644
}

0 commit comments

Comments
 (0)