MDL-83401 core: Upgrade laravel/serializable to 1.3.5

This commit is contained in:
Andrew Nicols
2025-01-29 11:58:43 +08:00
parent 75dedf1d87
commit ede7bcbd7a
11 changed files with 48 additions and 87 deletions
@@ -18,13 +18,14 @@
}
],
"require": {
"php": "^7.3|^8.0"
"php": "^8.1"
},
"require-dev": {
"nesbot/carbon": "^2.61",
"pestphp/pest": "^1.21.3",
"phpstan/phpstan": "^1.8.2",
"symfony/var-dumper": "^5.4.11"
"illuminate/support": "^10.0|^11.0|^12.0",
"nesbot/carbon": "^2.67|^3.0",
"pestphp/pest": "^2.36|^3.0",
"phpstan/phpstan": "^2.0",
"symfony/var-dumper": "^6.2.0|^7.0.0"
},
"autoload": {
"psr-4": {
@@ -38,7 +39,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
"dev-master": "2.x-dev"
}
},
"config": {
@@ -1,3 +1 @@
Please note that this library is required for use of PHP-DI.
Please update it in accordance with PHP-DI and see lib/php-di/readme_moodle.md for more information.
See instructions in lib/php-di/readme_moodle.md
@@ -4,7 +4,6 @@ namespace Laravel\SerializableClosure;
use Closure;
use Laravel\SerializableClosure\Exceptions\InvalidSignatureException;
use Laravel\SerializableClosure\Exceptions\PhpVersionNotSupportedException;
use Laravel\SerializableClosure\Serializers\Signed;
use Laravel\SerializableClosure\Signers\Hmac;
@@ -25,10 +24,6 @@ class SerializableClosure
*/
public function __construct(Closure $closure)
{
if (\PHP_VERSION_ID < 70400) {
throw new PhpVersionNotSupportedException();
}
$this->serializable = Serializers\Signed::$signer
? new Serializers\Signed($closure)
: new Serializers\Native($closure);
@@ -41,10 +36,6 @@ class SerializableClosure
*/
public function __invoke()
{
if (\PHP_VERSION_ID < 70400) {
throw new PhpVersionNotSupportedException();
}
return call_user_func_array($this->serializable, func_get_args());
}
@@ -55,10 +46,6 @@ class SerializableClosure
*/
public function getClosure()
{
if (\PHP_VERSION_ID < 70400) {
throw new PhpVersionNotSupportedException();
}
return $this->serializable->getClosure();
}
@@ -111,7 +98,7 @@ class SerializableClosure
/**
* Get the serializable representation of the closure.
*
* @return array
* @return array{serializable: \Laravel\SerializableClosure\Serializers\Signed|\Laravel\SerializableClosure\Contracts\Serializable}
*/
public function __serialize()
{
@@ -123,7 +110,7 @@ class SerializableClosure
/**
* Restore the closure after serialization.
*
* @param array $data
* @param array{serializable: \Laravel\SerializableClosure\Serializers\Signed|\Laravel\SerializableClosure\Contracts\Serializable} $data
* @return void
*
* @throws \Laravel\SerializableClosure\Exceptions\InvalidSignatureException
@@ -274,7 +274,7 @@ class Native implements Serializable
$property->setAccessible(true);
if (PHP_VERSION >= 7.4 && ! $property->isInitialized($instance)) {
if (! $property->isInitialized($instance)) {
continue;
}
@@ -374,7 +374,7 @@ class Native implements Serializable
$property->setAccessible(true);
if (PHP_VERSION >= 7.4 && ! $property->isInitialized($data)) {
if (! $property->isInitialized($data) || $property->isReadOnly()) {
continue;
}
@@ -496,7 +496,7 @@ class Native implements Serializable
$property->setAccessible(true);
if (PHP_VERSION >= 7.4 && ! $property->isInitialized($instance)) {
if (! $property->isInitialized($instance) || ($property->isReadOnly() && $property->class !== $reflection->name)) {
continue;
}
@@ -72,7 +72,7 @@ class Signed implements Serializable
/**
* Restore the closure after serialization.
*
* @param array $signature
* @param array{serializable: string, hash: string} $signature
* @return void
*
* @throws \Laravel\SerializableClosure\Exceptions\InvalidSignatureException
@@ -41,7 +41,7 @@ class Hmac implements Signer
/**
* Verify the given signature.
*
* @param array $signature
* @param array{serializable: string, hash: string} $signature
* @return bool
*/
public function verify($signature)
@@ -7,6 +7,8 @@ class ClosureStream
{
/**
* The stream protocol.
*
* @var string
*/
const STREAM_PROTO = 'laravel-serializable-closure';
@@ -508,7 +508,7 @@ class ReflectionClosure extends ReflectionFunction
break;
case 'id_name':
switch ($token[0]) {
case $token[0] === ':' && $context !== 'instanceof':
case $token[0] === ':' && ! in_array($context, ['instanceof', 'new'], true):
if ($lastState === 'closure' && $context === 'root') {
$state = 'closure';
$code .= $id_start.$token;
@@ -680,27 +680,25 @@ class ReflectionClosure extends ReflectionFunction
$this->isBindingRequired = $isUsingThisObject;
$this->isScopeRequired = $isUsingScope;
if (PHP_VERSION_ID >= 80100) {
$attributesCode = array_map(function ($attribute) {
$arguments = $attribute->getArguments();
$attributesCode = array_map(function ($attribute) {
$arguments = $attribute->getArguments();
$name = $attribute->getName();
$arguments = implode(', ', array_map(function ($argument, $key) {
$argument = sprintf("'%s'", str_replace("'", "\\'", $argument));
$name = $attribute->getName();
$arguments = implode(', ', array_map(function ($argument, $key) {
$argument = sprintf("'%s'", str_replace("'", "\\'", $argument));
if (is_string($key)) {
$argument = sprintf('%s: %s', $key, $argument);
}
if (is_string($key)) {
$argument = sprintf('%s: %s', $key, $argument);
}
return $argument;
}, $arguments, array_keys($arguments)));
return $argument;
}, $arguments, array_keys($arguments)));
return "#[$name($arguments)]";
}, $this->getAttributes());
return "#[$name($arguments)]";
}, $this->getAttributes());
if (! empty($attributesCode)) {
$code = implode("\n", array_merge($attributesCode, [$code]));
}
if (! empty($attributesCode)) {
$code = implode("\n", array_merge($attributesCode, [$code]));
}
$this->code = $code;
@@ -715,25 +713,7 @@ class ReflectionClosure extends ReflectionFunction
*/
protected static function getBuiltinTypes()
{
// PHP 8.1
if (PHP_VERSION_ID >= 80100) {
return ['array', 'callable', 'string', 'int', 'bool', 'float', 'iterable', 'void', 'object', 'mixed', 'false', 'null', 'never'];
}
// PHP 8
if (\PHP_MAJOR_VERSION === 8) {
return ['array', 'callable', 'string', 'int', 'bool', 'float', 'iterable', 'void', 'object', 'mixed', 'false', 'null'];
}
// PHP 7
switch (\PHP_MINOR_VERSION) {
case 0:
return ['array', 'callable', 'string', 'int', 'bool', 'float'];
case 1:
return ['array', 'callable', 'string', 'int', 'bool', 'float', 'iterable', 'void'];
default:
return ['array', 'callable', 'string', 'int', 'bool', 'float', 'iterable', 'void', 'object'];
}
return ['array', 'callable', 'string', 'int', 'bool', 'float', 'iterable', 'void', 'object', 'mixed', 'false', 'null', 'never'];
}
/**
@@ -806,7 +786,7 @@ class ReflectionClosure extends ReflectionFunction
}
/**
* The the hash of the current file name.
* The hash of the current file name.
*
* @return string
*/
@@ -1135,10 +1115,10 @@ class ReflectionClosure extends ReflectionFunction
if (--$open == 0) {
if (! $structIgnore) {
$structures[] = [
'type' => $structType,
'name' => $structName,
'type' => $structType,
'name' => $structName,
'start' => $startLine,
'end' => $endLine,
'end' => $endLine,
];
}
$structIgnore = false;
@@ -1169,8 +1149,14 @@ class ReflectionClosure extends ReflectionFunction
{
$ns = $this->getNamespaceName();
$name = $this->getName();
// First class callables...
if ($this->getName() !== '{closure}' && empty($ns) && ! is_null($this->getClosureScopeClass())) {
if ($name !== '{closure}'
&& ! str_contains($name, '{closure:/')
&& ! str_contains($name, '{closure:\\')
&& empty($ns)
&& ! is_null($this->getClosureScopeClass())) {
$ns = $this->getClosureScopeClass()->getNamespaceName();
}
@@ -3,7 +3,6 @@
namespace Laravel\SerializableClosure;
use Closure;
use Laravel\SerializableClosure\Exceptions\PhpVersionNotSupportedException;
class UnsignedSerializableClosure
{
@@ -22,10 +21,6 @@ class UnsignedSerializableClosure
*/
public function __construct(Closure $closure)
{
if (\PHP_VERSION_ID < 70400) {
throw new PhpVersionNotSupportedException();
}
$this->serializable = new Serializers\Native($closure);
}
@@ -36,10 +31,6 @@ class UnsignedSerializableClosure
*/
public function __invoke()
{
if (\PHP_VERSION_ID < 70400) {
throw new PhpVersionNotSupportedException();
}
return call_user_func_array($this->serializable, func_get_args());
}
@@ -50,17 +41,13 @@ class UnsignedSerializableClosure
*/
public function getClosure()
{
if (\PHP_VERSION_ID < 70400) {
throw new PhpVersionNotSupportedException();
}
return $this->serializable->getClosure();
}
/**
* Get the serializable representation of the closure.
*
* @return array
* @return array{serializable: \Laravel\SerializableClosure\Contracts\Serializable}
*/
public function __serialize()
{
@@ -72,7 +59,7 @@ class UnsignedSerializableClosure
/**
* Restore the closure after serialization.
*
* @param array $data
* @param array{serializable: \Laravel\SerializableClosure\Contracts\Serializable} $data
* @return void
*/
public function __unserialize($data)
+1 -1
View File
@@ -25,7 +25,7 @@ git add lib/php-di/invoker
cp -rf "$installdir"/vendor/laravel/serializable-closure lib/laravel/serializable-closure
echo "See instructions in lib/php-di/readme_moodle.md" > lib/laravel/serializable-closure/readme_moodle.txt
git add lib/phplaravel/serializable-closure
git add lib/laravel/serializable-closure
```
Now update the thirdpartylibs.xml as appropriate.
+1 -1
View File
@@ -775,7 +775,7 @@ All rights reserved.</copyright>
<library>
<location>laravel/serializable-closure</location>
<name>Serializable Closure</name>
<version>1.3.3</version>
<version>2.0.1</version>
<license>MIT</license>
<repository>https://github.com/laravel/serializable-closure</repository>
</library>