From 389f5304c755178fb8c485e8b07d3d5c7f91c301 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 12 Nov 2020 16:15:02 +0100 Subject: [PATCH] [ProxyManagerBridge] fix PHP notice, switch to "friendsofphp/proxy-manager-lts" --- composer.json | 2 +- .../Instantiator/RuntimeInstantiator.php | 6 +- .../LazyLoadingValueHolderGenerator.php | 69 ++----------------- .../LazyProxy/PhpDumper/ProxyDumper.php | 20 ++---- src/Symfony/Bridge/ProxyManager/README.md | 2 +- .../PhpDumper/Fixtures/proxy-implem.php | 10 +-- src/Symfony/Bridge/ProxyManager/composer.json | 7 +- 7 files changed, 22 insertions(+), 94 deletions(-) diff --git a/composer.json b/composer.json index 55f83ce8e724e..e614299e5937a 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "require": { "php": ">=7.1.3", "ext-xml": "*", + "friendsofphp/proxy-manager-lts": "^1.0", "doctrine/event-manager": "~1.0", "doctrine/persistence": "^1.3|^2", "twig/twig": "^1.41|^2.10|^3.0", @@ -112,7 +113,6 @@ "masterminds/html5": "^2.6", "monolog/monolog": "^1.25.1", "nyholm/psr7": "^1.0", - "ocramius/proxy-manager": "^2.1", "paragonie/sodium_compat": "^1.8", "php-http/httplug": "^1.0|^2.0", "predis/predis": "~1.1", diff --git a/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php b/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php index 7b6ce56b0fbe9..7f5aa8ab51d86 100644 --- a/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php +++ b/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php @@ -48,7 +48,11 @@ function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($realInstantiator $proxy->setProxyInitializer(null); return true; - } + }, + [ + 'fluentSafe' => $definition->hasTag('proxy'), + 'skipDestructor' => true, + ] ); } } diff --git a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/LazyLoadingValueHolderGenerator.php b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/LazyLoadingValueHolderGenerator.php index 2ff31bbda353b..2ce78cd5237d6 100644 --- a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/LazyLoadingValueHolderGenerator.php +++ b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/LazyLoadingValueHolderGenerator.php @@ -11,87 +11,26 @@ namespace Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper; +use Laminas\Code\Generator\ClassGenerator; use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator as BaseGenerator; use Symfony\Component\DependencyInjection\Definition; -use Zend\Code\Generator\ClassGenerator; /** * @internal */ class LazyLoadingValueHolderGenerator extends BaseGenerator { - private $fluentSafe = false; - - public function setFluentSafe(bool $fluentSafe) - { - $this->fluentSafe = $fluentSafe; - } - /** * {@inheritdoc} */ - public function generate(\ReflectionClass $originalClass, ClassGenerator $classGenerator): void + public function generate(\ReflectionClass $originalClass, ClassGenerator $classGenerator, array $proxyOptions = []): void { - parent::generate($originalClass, $classGenerator); + parent::generate($originalClass, $classGenerator, $proxyOptions); foreach ($classGenerator->getMethods() as $method) { - $body = preg_replace( - '/(\$this->initializer[0-9a-f]++) && \1->__invoke\(\$this->(valueHolder[0-9a-f]++), (.*?), \1\);/', - '$1 && ($1->__invoke(\$$2, $3, $1) || 1) && $this->$2 = \$$2;', - $method->getBody() - ); - $body = str_replace('(new \ReflectionClass(get_class()))', '$reflection', $body); - $body = str_replace('$reflection = $reflection ?: ', '$reflection = $reflection ?? ', $body); - $body = str_replace('$reflection ?? $reflection = ', '$reflection ?? ', $body); - - if ($originalClass->isInterface()) { - $body = str_replace('get_parent_class($this)', var_export($originalClass->name, true), $body); - $body = preg_replace_callback('/\n\n\$realInstanceReflection = [^{]++\{([^}]++)\}\n\n.*/s', function ($m) { - $r = ''; - foreach (explode("\n", $m[1]) as $line) { - $r .= "\n".substr($line, 4); - if (0 === strpos($line, ' return ')) { - break; - } - } - - return $r; - }, $body); - } - - if ($this->fluentSafe) { - $indent = $method->getIndentation(); - $method->setIndentation(''); - $code = $method->generate(); - if (null !== $docBlock = $method->getDocBlock()) { - $code = substr($code, \strlen($docBlock->generate())); - } - $refAmp = (strpos($code, '&') ?: \PHP_INT_MAX) <= strpos($code, '(') ? '&' : ''; - $body = preg_replace( - '/\nreturn (\$this->valueHolder[0-9a-f]++)(->[^;]++);$/', - "\nif ($1 === \$returnValue = {$refAmp}$1$2) {\n \$returnValue = \$this;\n}\n\nreturn \$returnValue;", - $body - ); - $method->setIndentation($indent); - } - if (0 === strpos($originalClass->getFilename(), __FILE__)) { - $body = str_replace(var_export($originalClass->name, true), '__CLASS__', $body); - } - - $method->setBody($body); - } - - if ($classGenerator->hasMethod('__destruct')) { - $destructor = $classGenerator->getMethod('__destruct'); - $body = $destructor->getBody(); - $newBody = preg_replace('/^(\$this->initializer[a-zA-Z0-9]++) && .*;\n\nreturn (\$this->valueHolder)/', '$1 || $2', $body); - - if ($body === $newBody) { - throw new \UnexpectedValueException(sprintf('Unexpected lazy-proxy format generated for method "%s::__destruct()".', $originalClass->name)); + $method->setBody(str_replace(var_export($originalClass->name, true), '__CLASS__', $method->getBody())); } - - $destructor->setBody($newBody); } if (0 === strpos($originalClass->getFilename(), __FILE__)) { diff --git a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php index c657e940dc74e..61edbd6306d2a 100644 --- a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php +++ b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php @@ -11,9 +11,7 @@ namespace Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper; -use ProxyManager\Exception\ExceptionInterface; use ProxyManager\Generator\ClassGenerator; -use ProxyManager\Generator\MethodGenerator; use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface; @@ -88,18 +86,6 @@ public function getProxyCode(Definition $definition): string $code = $this->classGenerator->generate($this->generateProxyClass($definition)); $code = preg_replace('/^(class [^ ]++ extends )([^\\\\])/', '$1\\\\$2', $code); - if (!method_exists(MethodGenerator::class, 'fromReflectionWithoutBodyAndDocBlock')) { // proxy-manager < 2.2 - $code = preg_replace( - '/((?:\$(?:this|initializer|instance)->)?(?:publicProperties|initializer|valueHolder))[0-9a-f]++/', - '${1}'.$this->getIdentifierSuffix($definition), - $code - ); - } - - if (!is_subclass_of(ExceptionInterface::class, 'Throwable')) { // proxy-manager < 2.5 - $code = preg_replace('/ \\\\Closure::bind\(function ((?:& )?\(\$instance(?:, \$value)?\))/', ' \Closure::bind(static function \1', $code); - } - return $code; } @@ -118,8 +104,10 @@ private function generateProxyClass(Definition $definition): ClassGenerator $generatedClass = new ClassGenerator($this->getProxyClassName($definition)); $class = $this->proxyGenerator->getProxifiedClass($definition); - $this->proxyGenerator->setFluentSafe($definition->hasTag('proxy')); - $this->proxyGenerator->generate(new \ReflectionClass($class), $generatedClass); + $this->proxyGenerator->generate(new \ReflectionClass($class), $generatedClass, [ + 'fluentSafe' => $definition->hasTag('proxy'), + 'skipDestructor' => true, + ]); return $generatedClass; } diff --git a/src/Symfony/Bridge/ProxyManager/README.md b/src/Symfony/Bridge/ProxyManager/README.md index 38d3d6964527f..f50fbd97eb754 100644 --- a/src/Symfony/Bridge/ProxyManager/README.md +++ b/src/Symfony/Bridge/ProxyManager/README.md @@ -11,4 +11,4 @@ Resources [send Pull Requests](https://github.com/symfony/symfony/pulls) in the [main Symfony repository](https://github.com/symfony/symfony) -[1]: https://github.com/Ocramius/ProxyManager +[1]: https://github.com/FriendsOfPHP/proxy-manager-lts diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php index 684ff36581776..324304f68392f 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php @@ -16,7 +16,7 @@ public function dummy() $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, 'dummy', array(), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; if ($this->valueHolder%s === $returnValue = $this->valueHolder%s->dummy()) { - $returnValue = $this; + return $this; } return $returnValue; @@ -26,8 +26,8 @@ public function & dummyRef() { $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, 'dummyRef', array(), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; - if ($this->valueHolder%s === $returnValue = &$this->valueHolder%s->dummyRef()) { - $returnValue = $this; + if ($this->valueHolder%s === $returnValue = & $this->valueHolder%s->dummyRef()) { + return $this; } return $returnValue; @@ -38,7 +38,7 @@ public function sunny() $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, 'sunny', array(), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; if ($this->valueHolder%s === $returnValue = $this->valueHolder%s->sunny()) { - $returnValue = $this; + return $this; } return $returnValue; @@ -96,7 +96,7 @@ public function __set($name, $value) $targetObject = $this->valueHolder%s; - return $targetObject->$name = $value; + $targetObject->$name = $value; return $targetObject->$name; } public function __isset($name) diff --git a/src/Symfony/Bridge/ProxyManager/composer.json b/src/Symfony/Bridge/ProxyManager/composer.json index b34def8465dd2..ad3900225898d 100644 --- a/src/Symfony/Bridge/ProxyManager/composer.json +++ b/src/Symfony/Bridge/ProxyManager/composer.json @@ -18,15 +18,12 @@ "require": { "php": ">=7.1.3", "composer/package-versions-deprecated": "^1.8", - "symfony/dependency-injection": "^4.0|^5.0", - "ocramius/proxy-manager": "~2.1" + "friendsofphp/proxy-manager-lts": "^1.0", + "symfony/dependency-injection": "^4.0|^5.0" }, "require-dev": { "symfony/config": "^3.4|^4.0|^5.0" }, - "conflict": { - "zendframework/zend-eventmanager": "2.6.0" - }, "autoload": { "psr-4": { "Symfony\\Bridge\\ProxyManager\\": "" }, "exclude-from-classmap": [ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy