diff --git a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php index 447549b97044..cf9161440178 100644 --- a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php +++ b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php @@ -14,7 +14,6 @@ use ProxyManager\Generator\ClassGenerator; use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy; use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator; -use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface; @@ -63,7 +62,7 @@ public function isProxyCandidate(Definition $definition) /** * {@inheritdoc} */ - public function getProxyFactoryCode(Definition $definition, $id) + public function getProxyFactoryCode(Definition $definition, $id, $methodName = null) { $instantiation = 'return'; @@ -71,12 +70,10 @@ public function getProxyFactoryCode(Definition $definition, $id) $instantiation .= " \$this->services['$id'] ="; } - if (func_num_args() >= 3) { - $methodName = func_get_arg(2); - } else { - @trigger_error(sprintf('You must use the third argument of %s to define the method to call to construct your service since version 3.1, not using it won\'t be supported in 4.0.', __METHOD__), E_USER_DEPRECATED); - $methodName = 'get'.Container::camelize($id).'Service'; + if (null === $methodName) { + throw new \InvalidArgumentException(sprintf('Missing name of method to call to construct the service "%s".', $id)); } + $proxyClass = $this->getProxyClassName($definition); $generatedClass = $this->generateProxyClass($definition); diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php index 64082c8f7f3f..d4d143a56f7d 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php @@ -80,24 +80,14 @@ public function testGetProxyFactoryCodeWithCustomMethod() } /** - * @group legacy + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Missing name of method to call to construct the service "foo". */ - public function testGetProxyFactoryCode() + public function testGetProxyFactoryCodeWithoutCustomMethod() { $definition = new Definition(__CLASS__); - $definition->setLazy(true); - - $code = $this->dumper->getProxyFactoryCode($definition, 'foo'); - - $this->assertStringMatchesFormat( - '%wif ($lazyLoad) {%wreturn $this->services[\'foo\'] =%s' - .'SymfonyBridgeProxyManagerTestsLazyProxyPhpDumperProxyDumperTest_%s(%wfunction ' - .'(&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) {' - .'%w$wrappedInstance = $this->getFooService(false);%w$proxy->setProxyInitializer(null);' - .'%wreturn true;%w}%w);%w}%w', - $code - ); + $this->dumper->getProxyFactoryCode($definition, 'foo'); } /** diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index e95f82b945e7..e7d8baeb4a8c 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -4,6 +4,8 @@ CHANGELOG 4.0.0 ----- + * added a third `$methodName` argument to the `getProxyFactoryCode()` method + of the `DumperInterface` * removed support for autowiring types * removed `Container::isFrozen` * removed support for dumping an ucompiled container in `PhpDumper` diff --git a/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/DumperInterface.php b/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/DumperInterface.php index ce88eba9742f..9697be53a76d 100644 --- a/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/DumperInterface.php +++ b/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/DumperInterface.php @@ -34,11 +34,11 @@ public function isProxyCandidate(Definition $definition); * * @param Definition $definition * @param string $id service identifier - * @param string $methodName the method name to get the service, will be added to the interface in 4.0 + * @param string $methodName the method name to get the service * * @return string */ - public function getProxyFactoryCode(Definition $definition, $id/**, $methodName = null */); + public function getProxyFactoryCode(Definition $definition, $id, $methodName); /** * Generates the code for the lazy proxy. diff --git a/src/Symfony/Component/DependencyInjection/Tests/LazyProxy/PhpDumper/NullDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/LazyProxy/PhpDumper/NullDumperTest.php index cde2c147e752..1cd8d1a279c0 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/LazyProxy/PhpDumper/NullDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/LazyProxy/PhpDumper/NullDumperTest.php @@ -28,7 +28,7 @@ public function testNullDumper() $definition = new Definition('stdClass'); $this->assertFalse($dumper->isProxyCandidate($definition)); - $this->assertSame('', $dumper->getProxyFactoryCode($definition, 'foo')); + $this->assertSame('', $dumper->getProxyFactoryCode($definition, 'foo', 'getFooService')); $this->assertSame('', $dumper->getProxyCode($definition)); } }