Skip to content
Snippets Groups Projects
Commit 6b5009dd authored by David Prévot's avatar David Prévot
Browse files

New upstream version 2.11.1+1.0.13

parents 08a4d36c 88354616
No related branches found
No related tags found
No related merge requests found
Showing
with 92 additions and 27 deletions
......@@ -4,6 +4,10 @@ on:
pull_request:
push:
defaults:
run:
shell: bash
jobs:
phpunit:
name: "PHPUnit tests"
......@@ -19,8 +23,10 @@ jobs:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
operating-system:
- "ubuntu-latest"
fail-fast: false
steps:
- name: "Checkout"
......@@ -44,7 +50,10 @@ jobs:
restore-keys: "php-${{ matrix.php-version }}"
- name: "Test with lowest dependencies"
run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest && vendor/bin/simple-phpunit"
if: "matrix.php-version != '8.2'"
run: |
composer update --prefer-lowest --no-interaction --no-progress --no-suggest && vendor/bin/simple-phpunit
- name: "Test with highest dependencies"
run: "composer update --no-interaction --no-progress --no-suggest && vendor/bin/simple-phpunit"
run: |
composer update --no-interaction --no-progress --no-suggest $([[ "${{ matrix.php-version }}" = "8.2" ]] && echo ' --ignore-platform-req=php+') && vendor/bin/simple-phpunit
......@@ -10,6 +10,7 @@ use ReflectionParameter;
use function explode;
use function implode;
use function in_array;
use function preg_replace;
use function preg_split;
use function rtrim;
......@@ -17,6 +18,7 @@ use function substr;
use function var_export;
use const PREG_SPLIT_DELIM_CAPTURE;
use const PREG_SPLIT_NO_EMPTY;
/**
* @internal do not use this in your code: it is only here for internal use
......@@ -50,16 +52,20 @@ class ValueGenerator extends LaminasValueGenerator
return parent::generate();
} catch (RuntimeException $e) {
if ($this->reflection) {
$value = rtrim(substr(explode('$' . $this->reflection->getName() . ' = ', (string) $this->reflection, 2)[1], 0, -2));
$value = self::exportDefault($this->reflection);
} else {
$value = var_export($this->value, true);
if (\PHP_VERSION_ID < 80200) {
return self::fixVarExport($value);
}
}
return self::fixExport($value);
return $value;
}
}
private static function fixExport(string $value): string
private static function fixVarExport(string $value): string
{
$parts = preg_split('{(\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')}', $value, -1, PREG_SPLIT_DELIM_CAPTURE);
......@@ -73,4 +79,47 @@ class ValueGenerator extends LaminasValueGenerator
return implode('', $parts);
}
private static function exportDefault(\ReflectionParameter $param): string
{
$default = rtrim(substr(explode('$'.$param->name.' = ', (string) $param, 2)[1] ?? '', 0, -2));
if (in_array($default, ['<default>', 'NULL'], true)) {
return 'null';
}
if (str_ends_with($default, "...'") && preg_match("/^'(?:[^'\\\\]*+(?:\\\\.)*+)*+'$/", $default)) {
return var_export($param->getDefaultValue(), true);
}
$regexp = "/(\"(?:[^\"\\\\]*+(?:\\\\.)*+)*+\"|'(?:[^'\\\\]*+(?:\\\\.)*+)*+')/";
$parts = preg_split($regexp, $default, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$regexp = '/([\[\( ]|^)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z0-9_\x7f-\xff]++)*+)(?!: )/';
$callback = (false !== strpbrk($default, "\\:('") && $class = $param->getDeclaringClass())
? function ($m) use ($class) {
switch ($m[2]) {
case 'new': case 'false': case 'true': case 'null': return $m[1].$m[2];
case 'NULL': return $m[1].'null';
case 'self': return $m[1].'\\'.$class->name;
case 'namespace\\parent':
case 'parent': $m[1].(($parent = $class->getParentClass()) ? '\\'.$parent->name : 'parent');
default: return $m[1].'\\'.$m[2];
}
}
: function ($m) {
switch ($m[2]) {
case 'new': case 'false': case 'true': case 'null': return $m[1].$m[2];
case 'NULL': return $m[1].'null';
default: return $m[1].'\\'.$m[2];
}
};
return implode('', array_map(function ($part) use ($regexp, $callback) {
switch ($part[0]) {
case '"': return $part; // for internal classes only
case "'": return false !== strpbrk($part, "\\\0\r\n") ? '"'.substr(str_replace(['$', "\0", "\r", "\n"], ['\$', '\0', '\r', '\n'], $part), 1, -1).'"' : $part;
default: return preg_replace_callback($regexp, $callback, $part);
}
}, $parts));
}
}
......@@ -175,7 +175,7 @@ PHP;
. '$' . $cacheKey . ' ?? $' . $cacheKey
. " = \\Closure::bind(function (\$instance, array & \$properties) {\n"
. $this->generatePrivatePropertiesAssignmentsCode($classPrivateProperties)
. '}, $this, ' . var_export($className, true) . ");\n\n"
. '}, null, ' . var_export($className, true) . ");\n\n"
. '$' . $cacheKey . '($this, $properties);';
}
......@@ -232,10 +232,10 @@ PHP;
foreach ($scopedProperties as $property) {
$propertyAlias = $property->getName() . ($property->isPrivate() ? '_on_' . str_replace('\\', '_', $property->getDeclaringClass()->getName()) : '');
$code[] = sprintf(' isset($nonReferenceableProperties->%s) && $this->%s = $nonReferenceableProperties->%1$s;', $propertyAlias, $property->getName());
$code[] = sprintf(' isset($nonReferenceableProperties->%s) && $instance->%s = $nonReferenceableProperties->%1$s;', $propertyAlias, $property->getName());
}
$code[] = '}, $this, ' . var_export($className, true) . ");\n";
$code[] = '}, null, ' . var_export($className, true) . ");\n";
$code[] = '$' . $cacheKey . '($this, $nonReferenceableProperties);';
}
......
......@@ -76,7 +76,7 @@ $cacheFetchProxyManagerTestAsset_ClassWithMixedProperties ?? $cacheFetchProxyMan
$properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedProperties' . "\0" . 'privateProperty0'] = & $instance->privateProperty0;
$properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedProperties' . "\0" . 'privateProperty1'] = & $instance->privateProperty1;
$properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedProperties' . "\0" . 'privateProperty2'] = & $instance->privateProperty2;
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedProperties');
}, null, 'ProxyManagerTestAsset\\ClassWithMixedProperties');
$cacheFetchProxyManagerTestAsset_ClassWithMixedProperties($this, $properties);
......@@ -314,7 +314,7 @@ $cacheFetchProxyManagerTestAsset_ClassWithMixedTypedProperties ?? $cacheFetchPro
$properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateNullableIterablePropertyWithoutDefaultValue'] = & $instance->privateNullableIterablePropertyWithoutDefaultValue;
$properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateNullableObjectProperty'] = & $instance->privateNullableObjectProperty;
$properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateNullableClassProperty'] = & $instance->privateNullableClassProperty;
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties');
}, null, 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties');
$cacheFetchProxyManagerTestAsset_ClassWithMixedTypedProperties($this, $properties);
......@@ -338,15 +338,15 @@ isset($nonReferenceableProperties->protectedClassProperty) && $this->protectedCl
static $cacheAssignProxyManagerTestAsset_ClassWithMixedTypedProperties;
$cacheAssignProxyManagerTestAsset_ClassWithMixedTypedProperties ?? $cacheAssignProxyManagerTestAsset_ClassWithMixedTypedProperties = \Closure::bind(function ($instance, $nonReferenceableProperties) {
isset($nonReferenceableProperties->privateBoolPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $this->privateBoolPropertyWithoutDefaultValue = $nonReferenceableProperties->privateBoolPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateIntPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $this->privateIntPropertyWithoutDefaultValue = $nonReferenceableProperties->privateIntPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateFloatPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $this->privateFloatPropertyWithoutDefaultValue = $nonReferenceableProperties->privateFloatPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateStringPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $this->privateStringPropertyWithoutDefaultValue = $nonReferenceableProperties->privateStringPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateArrayPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $this->privateArrayPropertyWithoutDefaultValue = $nonReferenceableProperties->privateArrayPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateIterablePropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $this->privateIterablePropertyWithoutDefaultValue = $nonReferenceableProperties->privateIterablePropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateObjectProperty_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $this->privateObjectProperty = $nonReferenceableProperties->privateObjectProperty_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateClassProperty_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $this->privateClassProperty = $nonReferenceableProperties->privateClassProperty_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
}, $this, 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties');
isset($nonReferenceableProperties->privateBoolPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $instance->privateBoolPropertyWithoutDefaultValue = $nonReferenceableProperties->privateBoolPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateIntPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $instance->privateIntPropertyWithoutDefaultValue = $nonReferenceableProperties->privateIntPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateFloatPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $instance->privateFloatPropertyWithoutDefaultValue = $nonReferenceableProperties->privateFloatPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateStringPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $instance->privateStringPropertyWithoutDefaultValue = $nonReferenceableProperties->privateStringPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateArrayPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $instance->privateArrayPropertyWithoutDefaultValue = $nonReferenceableProperties->privateArrayPropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateIterablePropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $instance->privateIterablePropertyWithoutDefaultValue = $nonReferenceableProperties->privateIterablePropertyWithoutDefaultValue_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateObjectProperty_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $instance->privateObjectProperty = $nonReferenceableProperties->privateObjectProperty_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
isset($nonReferenceableProperties->privateClassProperty_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties) && $instance->privateClassProperty = $nonReferenceableProperties->privateClassProperty_on_ProxyManagerTestAsset_ClassWithMixedTypedProperties;
}, null, 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties');
$cacheAssignProxyManagerTestAsset_ClassWithMixedTypedProperties($this, $nonReferenceableProperties);
$this->track = false;
......@@ -404,10 +404,10 @@ $result = $this->init->__invoke($this, $methodName, $parameters, $this->init, $p
static $cacheAssignProxyManagerTestAsset_ClassWithReadOnlyProperties;
$cacheAssignProxyManagerTestAsset_ClassWithReadOnlyProperties ?? $cacheAssignProxyManagerTestAsset_ClassWithReadOnlyProperties = \Closure::bind(function ($instance, $nonReferenceableProperties) {
isset($nonReferenceableProperties->property0) && $this->property0 = $nonReferenceableProperties->property0;
isset($nonReferenceableProperties->property1) && $this->property1 = $nonReferenceableProperties->property1;
isset($nonReferenceableProperties->property2_on_ProxyManagerTestAsset_ClassWithReadOnlyProperties) && $this->property2 = $nonReferenceableProperties->property2_on_ProxyManagerTestAsset_ClassWithReadOnlyProperties;
}, $this, 'ProxyManagerTestAsset\\ClassWithReadOnlyProperties');
isset($nonReferenceableProperties->property0) && $instance->property0 = $nonReferenceableProperties->property0;
isset($nonReferenceableProperties->property1) && $instance->property1 = $nonReferenceableProperties->property1;
isset($nonReferenceableProperties->property2_on_ProxyManagerTestAsset_ClassWithReadOnlyProperties) && $instance->property2 = $nonReferenceableProperties->property2_on_ProxyManagerTestAsset_ClassWithReadOnlyProperties;
}, null, 'ProxyManagerTestAsset\\ClassWithReadOnlyProperties');
$cacheAssignProxyManagerTestAsset_ClassWithReadOnlyProperties($this, $nonReferenceableProperties);
$this->track = false;
......
......@@ -5,6 +5,7 @@ Verifies that generated lazy loading ghost objects disallow reading non-existing
require_once __DIR__ . '/init.php';
#[AllowDynamicProperties]
class Kitchen
{
private $sweets;
......@@ -22,4 +23,4 @@ $proxy = $factory->createProxy(Kitchen::class, function () {});
echo $proxy->nonExisting;
?>
--EXPECTF--
nonExisting
\ No newline at end of file
nonExisting
......@@ -5,6 +5,7 @@ Verifies that generated lazy loading ghost objects disallow reading non-existing
require_once __DIR__ . '/init.php';
#[AllowDynamicProperties]
class Kitchen
{
private $sweets;
......@@ -18,4 +19,4 @@ $proxy->nonExisting = 'I do not exist';
echo $proxy->nonExisting;
?>
--EXPECTF--
I do not exist
\ No newline at end of file
I do not exist
......@@ -5,6 +5,7 @@ Verifies that generated lazy loading ghost objects disallow reading non-existing
require_once __DIR__ . '/init.php';
#[AllowDynamicProperties]
class Kitchen
{
private $sweets;
......@@ -17,4 +18,4 @@ $proxy = $factory->createProxy(Kitchen::class, function () {});
$proxy->nonExisting;
?>
--EXPECTF--
%SNotice: Undefined property: Kitchen::$nonExisting in %a
\ No newline at end of file
%SNotice: Undefined property: Kitchen::$nonExisting in %a
......@@ -5,6 +5,7 @@ Verifies that generated lazy loading ghost objects can skip calling the proxied
require_once __DIR__ . '/init.php';
#[AllowDynamicProperties]
class Destructable
{
public function __destruct()
......
......@@ -14,7 +14,8 @@ $factory = new \ProxyManager\Factory\LazyLoadingValueHolderFactory($configuratio
$proxy = $factory
->createProxy(MyInterface::class, function (& $wrapped, $proxy, $method, array $parameters, & $initializer) : bool {
$initializer = null;
$wrapped = new class implements MyInterface {
$wrapped = new #[AllowDynamicProperties]
class implements MyInterface {
};
return true;
......
......@@ -10,6 +10,7 @@ interface MyInterface
public function do();
}
#[AllowDynamicProperties]
class MyClass implements MyInterface
{
public function do()
......
......@@ -5,6 +5,7 @@ Verifies that generated lazy loading value holders can skip calling the proxied
require_once __DIR__ . '/init.php';
#[AllowDynamicProperties]
class Destructable
{
public function __destruct()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment