8000 [DI][ProxyManager] Pass the factory code to execute to DumperInterfac… · symfony/symfony@0754617 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0754617

Browse files
[DI][ProxyManager] Pass the factory code to execute to DumperInterface::getProxyFactoryCode()
1 parent 6bbb391 commit 0754617

File tree

8 files changed

+17
-15
lines changed

8 files changed

+17
-15
lines changed

src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,20 @@ public function isProxyCandidate(Definition $definition)
6565
/**
6666
* {@inheritdoc}
6767
*/
68-
public function getProxyFactoryCode(Definition $definition, $id, $methodName = null)
68+
public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null)
6969
{
7070
$instantiation = 'return';
7171

7272
if ($definition->isShared()) {
7373
$instantiation .= " \$this->services['$id'] =";
7474
}
7575

76-
if (func_num_args() >= 3) {
77-
$methodName = func_get_arg(2);
78-
} else {
79-
@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);
80-
$methodName = 'get'.Container::camelize($id).'Service';
76+
if (null === $factoryCode) {
77+
@trigger_error(sprintf('The "%s()" method expects a third argument defining the code to execute to construct your service since version 3.4, providing it will be required in 4.0.', __METHOD__), E_USER_DEPRECATED);
78+
$factoryCode = '$this->get'.Container::camelize($id).'Service(false)';
79+
} elseif (false === strpos($factoryCode, '(')) {
80+
@trigger_error(sprintf('The "%s()" method expects its third argument to define the code to execute to construct your service since version 3.4, providing it will be required in 4.0.', __METHOD__), E_USER_DEPRECATED);
81+
$factoryCode = "\$this->$factoryCode(false)";
8182
}
8283
$proxyClass = $this->getProxyClassName($definition);
8384

@@ -92,7 +93,7 @@ public function getProxyFactoryCode(Definition $definition, $id, $methodName = n
9293
9394
$instantiation $constructorCall(
9495
function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) {
95-
\$wrappedInstance = \$this->$methodName(false);
96+
\$wrappedInstance = $factoryCode;
9697
9798
\$proxy->setProxyInitializer(null);
9899

src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testGetProxyFactoryCodeWithCustomMethod()
6767

6868
$definition->setLazy(true);
6969

70-
$code = $this->dumper->getProxyFactoryCode($definition, 'foo', 'getFoo2Service');
70+
$code = $this->dumper->getProxyFactoryCode($definition, 'foo', '$this->getFoo2Service(false)');
7171

7272
$this->assertStringMatchesFormat(
7373
'%wif ($lazyLoad) {%wreturn $this->services[\'foo\'] =%s'

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ private function addService($id, Definition $definition)
639639
640640
EOF;
641641

642-
$code .= $isProxyCandidate ? $this->getProxyDumper()->getProxyFactoryCode($definition, $id, $methodName) : '';
642+
$code .= $isProxyCandidate ? $this->getProxyDumper()->getProxyFactoryCode($definition, $id, "\$this->$methodName(false)") : '';
643643

644644
if ($definition->isDeprecated()) {
645645
$code .= sprintf(" @trigger_error(%s, E_USER_DEPRECATED);\n\n", $this->export($definition->getDeprecationMessage($id)));

src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/DumperInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public function isProxyCandidate(Definition $definition);
3333
* Generates the code to be used to instantiate a proxy in the dumped factory code.
3434
*
3535
* @param Definition $definition
36-
* @param string $id service identifier
37-
* @param string $methodName the method name to get the service, will be added to the interface in 4.0
36+
* @param string $id service identifier
37+
* @param string $factoryCode the code to execute to create the service, will be added to the interface in 4.0
3838
*
3939
* @return string
4040
*/
41-
public function getProxyFactoryCode(Definition $definition, $id/**, $methodName = null */);
41+
public function getProxyFactoryCode(Definition $definition, $id/**, $factoryCode = null */);
4242

4343
/**
4444
* Generates the code for the lazy proxy.

src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/NullDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function isProxyCandidate(Definition $definition)
3333
/**
3434
* {@inheritdoc}
3535
*/
36-
public function getProxyFactoryCode(Definition $definition, $id, $methodName = null)
36+
public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null)
3737
{
3838
return '';
3939
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/classes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function isProxyCandidate(Definition $definition)
8888
return false;
8989
}
9090

91-
public function getProxyFactoryCode(Definition $definition, $id, $methodName = null)
91+
public function getProxyFactoryCode(Definition $definition, $id, $factoryCall = null)
9292
{
9393
return '';
9494
}

src/Symfony/Component/DependencyInjection/Tests/LazyProxy/PhpDumper/NullDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testNullDumper()
2828
$definition = new Definition('stdClass');
2929

3030
$this->assertFalse($dumper->isProxyCandidate($definition));
31-
$this->assertSame('', $dumper->getProxyFactoryCode($definition, 'foo'));
31+
$this->assertSame('', $dumper->getProxyFactoryCode($definition, 'foo', '(false)'));
3232
$this->assertSame('', $dumper->getProxyCode($definition));
3333
}
3434
}

src/Symfony/Component/DependencyInjection/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"conflict": {
3535
"symfony/config": "<3.3.1",
3636
"symfony/finder": "<3.3",
37+
"symfony/proxy-manager-bridge": "<3.4",
3738
"symfony/yaml": "<3.3"
3839
},
3940
"provide": {

0 commit comments

Comments
 (0)
0