diff --git a/composer.json b/composer.json index 5d7d77a..ac42714 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "opis/closure", + "name": "silverstripe/closure", "description": "A library that can be used to serialize closures (anonymous functions) and arbitrary objects.", "keywords": ["closure", "serialization", "function", "serializable", "serialize", "anonymous functions"], "homepage": "https://opis.io/closure", @@ -15,7 +15,10 @@ } ], "require": { - "php": "^5.4 || ^7.0 || ^8.0" + "php": "^8.1" + }, + "replace": { + "opis/closure":"3.*" }, "require-dev": { "jeremeamia/superclosure": "^2.0", @@ -32,11 +35,6 @@ "Opis\\Closure\\Test\\": "tests/" } }, - "extra": { - "branch-alias": { - "dev-master": "3.6.x-dev" - } - }, "config": { "preferred-install": "dist", "sort-packages": true diff --git a/src/ReflectionClosure.php b/src/ReflectionClosure.php index 1f6a832..983bc8a 100644 --- a/src/ReflectionClosure.php +++ b/src/ReflectionClosure.php @@ -46,13 +46,13 @@ public function __construct(Closure $closure, $code = null) /** * @return bool */ - public function isStatic() + public function isStatic(): bool { if ($this->isStaticClosure === null) { $this->isStaticClosure = strtolower(substr($this->getCode(), 0, 6)) === 'static'; } - return $this->isStaticClosure; + return (bool) $this->isStaticClosure; } public function isShortClosure() diff --git a/src/SerializableClosure.php b/src/SerializableClosure.php index 1025ff5..85c6c7e 100644 --- a/src/SerializableClosure.php +++ b/src/SerializableClosure.php @@ -15,7 +15,7 @@ /** * Provides a wrapper for serialization of closures */ -class SerializableClosure implements Serializable +class SerializableClosure { /** * @var Closure Wrapped closure @@ -109,12 +109,19 @@ public function __invoke() return call_user_func_array($this->closure, func_get_args()); } + public function __serialize(): array + { + return [ + 'serialized' => $this->serialize() + ]; + } + /** * Implementation of Serializable::serialize() * * @return string The serialized closure */ - public function serialize() + private function serialize() { if ($this->scope === null) { $this->scope = new ClosureScope(); @@ -178,13 +185,18 @@ protected function transformUseVariables($data) return $data; } + public function __unserialize(array $data): void + { + $this->unserialize($data['serialized']); + } + /** * Implementation of Serializable::unserialize() * * @param string $data Serialized data * @throws SecurityException */ - public function unserialize($data) + private function unserialize($data) { ClosureStream::register();