[ProxyManagerBridge] replace ProxyManager\Version by feature detection
This commit is contained in:
parent
e5ec20400c
commit
5f77aad6ca
|
@ -11,9 +11,10 @@
|
|||
|
||||
namespace Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper;
|
||||
|
||||
use ProxyManager\Exception\ExceptionInterface;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy;
|
||||
use ProxyManager\Version;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
|
||||
|
||||
|
@ -87,7 +88,7 @@ EOF;
|
|||
$code = $this->classGenerator->generate($this->generateProxyClass($definition));
|
||||
$code = preg_replace('/^(class [^ ]++ extends )([^\\\\])/', '$1\\\\$2', $code);
|
||||
|
||||
if (version_compare(self::getProxyManagerVersion(), '2.2', '<')) {
|
||||
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),
|
||||
|
@ -95,22 +96,13 @@ EOF;
|
|||
);
|
||||
}
|
||||
|
||||
if (version_compare(self::getProxyManagerVersion(), '2.5', '<')) {
|
||||
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;
|
||||
}
|
||||
|
||||
private static function getProxyManagerVersion(): string
|
||||
{
|
||||
if (!class_exists(Version::class)) {
|
||||
return '0.0.1';
|
||||
}
|
||||
|
||||
return \defined(Version::class.'::VERSION') ? Version::VERSION : Version::getVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces the proxy class name for the given definition.
|
||||
*/
|
||||
|
|
Reference in New Issue