Augmentation vers version 3.3.0
This commit is contained in:
2
vendor/symfony/proxy-manager-bridge/LICENSE
vendored
2
vendor/symfony/proxy-manager-bridge/LICENSE
vendored
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2004-2018 Fabien Potencier
|
||||
Copyright (c) 2004-2019 Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -13,8 +13,9 @@ namespace Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper;
|
||||
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy;
|
||||
use ProxyManager\Version;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
|
||||
|
||||
@@ -22,6 +23,8 @@ use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
|
||||
* Generates dumped PHP code of proxies via reflection.
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
*
|
||||
* @final since version 3.3
|
||||
*/
|
||||
class ProxyDumper implements DumperInterface
|
||||
{
|
||||
@@ -44,46 +47,44 @@ class ProxyDumper implements DumperInterface
|
||||
*/
|
||||
public function isProxyCandidate(Definition $definition)
|
||||
{
|
||||
return $definition->isLazy() && ($class = $definition->getClass()) && class_exists($class);
|
||||
return $definition->isLazy() && ($class = $definition->getClass()) && (class_exists($class) || interface_exists($class));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getProxyFactoryCode(Definition $definition, $id)
|
||||
public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null)
|
||||
{
|
||||
$instantiation = 'return';
|
||||
|
||||
if ($definition->isShared()) {
|
||||
$instantiation .= " \$this->services['$id'] =";
|
||||
|
||||
if (\defined('Symfony\Component\DependencyInjection\ContainerInterface::SCOPE_CONTAINER') && ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope(false)) {
|
||||
$instantiation .= " \$this->scopedServices['$scope']['$id'] =";
|
||||
}
|
||||
$instantiation .= sprintf(' $this->%s[%s] =', method_exists(ContainerBuilder::class, 'addClassResource') || ($definition->isPublic() && !$definition->isPrivate()) ? 'services' : 'privates', var_export($id, true));
|
||||
}
|
||||
|
||||
$methodName = 'get'.Container::camelize($id).'Service';
|
||||
if (null === $factoryCode) {
|
||||
@trigger_error(sprintf('The "%s()" method expects a third argument defining the code to execute to construct your service since Symfony 3.4, providing it will be required in 4.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
$factoryCode = '$this->get'.Container::camelize($id).'Service(false)';
|
||||
} elseif (false === strpos($factoryCode, '(')) {
|
||||
@trigger_error(sprintf('The "%s()" method expects its third argument to define the code to execute to construct your service since Symfony 3.4, providing it will be required in 4.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
$factoryCode = "\$this->$factoryCode(false)";
|
||||
}
|
||||
$proxyClass = $this->getProxyClassName($definition);
|
||||
|
||||
$generatedClass = $this->generateProxyClass($definition);
|
||||
$hasStaticConstructor = $this->generateProxyClass($definition)->hasMethod('staticProxyConstructor');
|
||||
|
||||
$constructorCall = $generatedClass->hasMethod('staticProxyConstructor')
|
||||
? $proxyClass.'::staticProxyConstructor'
|
||||
: 'new '.$proxyClass;
|
||||
$constructorCall = sprintf($hasStaticConstructor ? '%s::staticProxyConstructor' : 'new %s', '\\'.$proxyClass);
|
||||
|
||||
return <<<EOF
|
||||
if (\$lazyLoad) {
|
||||
\$container = \$this;
|
||||
|
||||
$instantiation $constructorCall(
|
||||
function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) use (\$container) {
|
||||
\$wrappedInstance = \$container->$methodName(false);
|
||||
$instantiation \$this->createProxy('$proxyClass', function () {
|
||||
return $constructorCall(function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) {
|
||||
\$wrappedInstance = $factoryCode;
|
||||
|
||||
\$proxy->setProxyInitializer(null);
|
||||
|
||||
return true;
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -95,11 +96,39 @@ EOF;
|
||||
*/
|
||||
public function getProxyCode(Definition $definition)
|
||||
{
|
||||
return preg_replace(
|
||||
$code = $this->classGenerator->generate($this->generateProxyClass($definition));
|
||||
|
||||
$code = 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;',
|
||||
$this->classGenerator->generate($this->generateProxyClass($definition))
|
||||
$code
|
||||
);
|
||||
|
||||
if (version_compare(self::getProxyManagerVersion(), '2.2', '<')) {
|
||||
$code = preg_replace(
|
||||
'/((?:\$(?:this|initializer|instance)->)?(?:publicProperties|initializer|valueHolder))[0-9a-f]++/',
|
||||
'${1}'.$this->getIdentifierSuffix($definition),
|
||||
$code
|
||||
);
|
||||
}
|
||||
|
||||
if (version_compare(self::getProxyManagerVersion(), '2.5', '<')) {
|
||||
$code = preg_replace('/ \\\\Closure::bind\(function ((?:& )?\(\$instance(?:, \$value)?\))/', ' \Closure::bind(static function \1', $code);
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private static function getProxyManagerVersion()
|
||||
{
|
||||
if (!class_exists(Version::class)) {
|
||||
return '0.0.1';
|
||||
}
|
||||
|
||||
return \defined(Version::class.'::VERSION') ? Version::VERSION : Version::getVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +138,7 @@ EOF;
|
||||
*/
|
||||
private function getProxyClassName(Definition $definition)
|
||||
{
|
||||
return str_replace('\\', '', $definition->getClass()).'_'.spl_object_hash($definition).$this->salt;
|
||||
return preg_replace('/^.*\\\\/', '', $definition->getClass()).'_'.$this->getIdentifierSuffix($definition);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,4 +152,12 @@ EOF;
|
||||
|
||||
return $generatedClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getIdentifierSuffix(Definition $definition)
|
||||
{
|
||||
return substr(hash('sha256', $definition->getClass().$this->salt), -7);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.9",
|
||||
"symfony/dependency-injection": "~2.8|~3.0.0",
|
||||
"php": "^5.5.9|>=7.0.8",
|
||||
"symfony/dependency-injection": "~3.4|~4.0",
|
||||
"ocramius/proxy-manager": "~0.4|~1.0|~2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/config": "~2.3|~3.0.0"
|
||||
"symfony/config": "~2.8|~3.0|~4.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Bridge\\ProxyManager\\": "" },
|
||||
@@ -32,7 +32,7 @@
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.8-dev"
|
||||
"dev-master": "3.4-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user