From 211b718e28b63891153c284e3d20058898f37821 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Fri, 28 Jun 2019 16:14:04 +0200 Subject: [PATCH] Added type-hints to LazyProxy classes and interfaces. --- .../LazyProxy/Instantiator/RuntimeInstantiator.php | 2 +- .../ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php | 6 +----- .../Tests/LazyProxy/PhpDumper/ProxyDumperTest.php | 11 ----------- src/Symfony/Bridge/ProxyManager/composer.json | 2 +- .../LazyProxy/Instantiator/InstantiatorInterface.php | 2 +- .../Instantiator/RealServiceInstantiator.php | 2 +- .../LazyProxy/PhpDumper/DumperInterface.php | 6 +----- .../LazyProxy/PhpDumper/NullDumper.php | 2 +- .../DependencyInjection/LazyProxy/ProxyHelper.php | 2 +- .../Tests/Fixtures/includes/classes.php | 2 +- 10 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php b/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php index 7b6ce56b0f..eee54e5ca2 100644 --- a/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php +++ b/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php @@ -38,7 +38,7 @@ class RuntimeInstantiator implements InstantiatorInterface /** * {@inheritdoc} */ - public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator) + public function instantiateProxy(ContainerInterface $container, Definition $definition, string $id, callable $realInstantiator) { return $this->factory->createProxy( $this->factory->getGenerator()->getProxifiedClass($definition), diff --git a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php index afe1309016..1977412681 100644 --- a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php +++ b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php @@ -48,7 +48,7 @@ class ProxyDumper implements DumperInterface /** * {@inheritdoc} */ - public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null): string + public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode): string { $instantiation = 'return'; @@ -56,10 +56,6 @@ class ProxyDumper implements DumperInterface $instantiation .= sprintf(' $this->%s[%s] =', $definition->isPublic() && !$definition->isPrivate() ? 'services' : 'privates', var_export($id, true)); } - if (null === $factoryCode) { - throw new \InvalidArgumentException(sprintf('Missing factory code to construct the service "%s".', $id)); - } - $proxyClass = $this->getProxyClassName($definition); return <<setLazy(true); - $this->dumper->getProxyFactoryCode($definition, 'foo'); - } - public function testGetProxyFactoryCodeForInterface() { $class = DummyClass::class; diff --git a/src/Symfony/Bridge/ProxyManager/composer.json b/src/Symfony/Bridge/ProxyManager/composer.json index 6c9bee243f..171b63bdb1 100644 --- a/src/Symfony/Bridge/ProxyManager/composer.json +++ b/src/Symfony/Bridge/ProxyManager/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^7.2.9", - "symfony/dependency-injection": "^4.4|^5.0", + "symfony/dependency-injection": "^5.0", "ocramius/proxy-manager": "~2.1" }, "require-dev": { diff --git a/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/InstantiatorInterface.php b/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/InstantiatorInterface.php index 417ab908a3..e8a20652e3 100644 --- a/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/InstantiatorInterface.php +++ b/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/InstantiatorInterface.php @@ -32,5 +32,5 @@ interface InstantiatorInterface * * @return object */ - public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator); + public function instantiateProxy(ContainerInterface $container, Definition $definition, string $id, callable $realInstantiator); } diff --git a/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/RealServiceInstantiator.php b/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/RealServiceInstantiator.php index 2e36704080..1696e7a904 100644 --- a/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/RealServiceInstantiator.php +++ b/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/RealServiceInstantiator.php @@ -26,7 +26,7 @@ class RealServiceInstantiator implements InstantiatorInterface /** * {@inheritdoc} */ - public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator) + public function instantiateProxy(ContainerInterface $container, Definition $definition, string $id, callable $realInstantiator) { return $realInstantiator(); } diff --git a/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/DumperInterface.php b/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/DumperInterface.php index 60787b7743..351560d292 100644 --- a/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/DumperInterface.php +++ b/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/DumperInterface.php @@ -30,13 +30,9 @@ interface DumperInterface /** * Generates the code to be used to instantiate a proxy in the dumped factory code. * - * @param Definition $definition - * @param string $id Service identifier - * @param string $factoryCode The code to execute to create the service - * * @return string */ - public function getProxyFactoryCode(Definition $definition, $id, $factoryCode); + public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode); /** * Generates the code for the lazy proxy. diff --git a/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/NullDumper.php b/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/NullDumper.php index ebc6a5dc2b..7e0f14c32b 100644 --- a/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/NullDumper.php +++ b/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/NullDumper.php @@ -33,7 +33,7 @@ class NullDumper implements DumperInterface /** * {@inheritdoc} */ - public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null): string + public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode): string { return ''; } diff --git a/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php b/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php index 65e432d93c..63eb4f5b73 100644 --- a/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php +++ b/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php @@ -21,7 +21,7 @@ class ProxyHelper /** * @return string|null The FQCN or builtin name of the type hint, or null when the type hint references an invalid self|parent context */ - public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionParameter $p = null, $noBuiltin = false) + public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionParameter $p = null, bool $noBuiltin = false) { if ($p instanceof \ReflectionParameter) { $type = $p->getType(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/classes.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/classes.php index 29913a8556..b801558d0f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/classes.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/classes.php @@ -88,7 +88,7 @@ class DummyProxyDumper implements ProxyDumper return $definition->isLazy(); } - public function getProxyFactoryCode(Definition $definition, $id, $factoryCall = null) + public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode) { return " // lazy factory for {$definition->getClass()}\n\n"; }