From e186a8f5de490d6f1ea967f164a22aba1f2b4573 Mon Sep 17 00:00:00 2001 From: Alexander Reichardt Date: Thu, 30 Nov 2023 17:13:13 +0100 Subject: [PATCH] Replaced opis/closure with laravel/serializable-closure --- composer.json | 2 +- src/Intervention/Image/CachedImage.php | 3 +++ src/Intervention/Image/HashableClosure.php | 14 +++++++------- tests/HashableClosureTest.php | 4 ++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 2c82296..6ff7603 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "illuminate/cache": "^5.5|~6|~7|~8|~9|~10", "illuminate/filesystem": "^5.5|~6|~7|~8|~9|~10", "nesbot/carbon": "^2.39", - "opis/closure": "^3.5" + "laravel/serializable-closure": "^1.3" }, "require-dev": { "phpunit/phpunit": "^8.0" diff --git a/src/Intervention/Image/CachedImage.php b/src/Intervention/Image/CachedImage.php index 39180e1..c0579f7 100644 --- a/src/Intervention/Image/CachedImage.php +++ b/src/Intervention/Image/CachedImage.php @@ -4,6 +4,9 @@ class CachedImage extends Image { + + public $cachekey; + public function setFromOriginal(Image $original, $cachekey) { $this->driver = $original->driver; diff --git a/src/Intervention/Image/HashableClosure.php b/src/Intervention/Image/HashableClosure.php index 43091a7..bef7e36 100644 --- a/src/Intervention/Image/HashableClosure.php +++ b/src/Intervention/Image/HashableClosure.php @@ -3,14 +3,14 @@ namespace Intervention\Image; use Closure; -use Opis\Closure\SerializableClosure; +use Laravel\SerializableClosure\UnsignedSerializableClosure; class HashableClosure { /** * Original closure * - * @var \Opis\Closure\SerializableClosure + * @var \Laravel\SerializableClosure\UnsignedSerializableClosure */ protected $closure; @@ -31,8 +31,7 @@ public function __construct(Closure $closure) */ public function setClosure(Closure $closure) { - $closure = new SerializableClosure($closure); - $closure->removeSecurityProvider(); + $closure = new UnsignedSerializableClosure($closure); $this->closure = $closure; @@ -42,7 +41,7 @@ public function setClosure(Closure $closure) /** * Get current closure * - * @return \Opis\Closure\SerializableClosure + * @return \Laravel\SerializableClosure\UnsignedSerializableClosure */ public function getClosure() { @@ -52,7 +51,7 @@ public function getClosure() /** * Get hash of current closure * - * This method uses "opis/closure" to serialize the closure. "opis/closure", + * This method uses "laravel/serializable-closure" to serialize the closure. "laravel/serializable-closure", * however, adds a identifier by "spl_object_hash" to each serialize * call, making it impossible to create unique hashes. This method * removes this identifier and builds the hash afterwards. @@ -61,7 +60,8 @@ public function getClosure() */ public function getHash() { - $data = unserialize($this->closure->serialize()); + $serializable = $this->closure->__serialize(); + $data = $serializable['serializable']->__serialize(); unset($data['self']); // unset identifier added by spl_object_hash diff --git a/tests/HashableClosureTest.php b/tests/HashableClosureTest.php index 60e2f9a..ebff056 100644 --- a/tests/HashableClosureTest.php +++ b/tests/HashableClosureTest.php @@ -3,7 +3,7 @@ namespace Intervention\Image\Test; use Intervention\Image\HashableClosure; -use Opis\Closure\SerializableClosure; +use Laravel\SerializableClosure\UnsignedSerializableClosure; use PHPUnit\Framework\TestCase; class HashableClosureTest extends TestCase @@ -28,7 +28,7 @@ public function testSetGetClosure() }); $this->assertInstanceOf(HashableClosure::class, $result); - $this->assertInstanceOf(SerializableClosure::class, $hashable->getClosure()); + $this->assertInstanceOf(UnsignedSerializableClosure::class, $hashable->getClosure()); } public function testGetHash()