Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DI][ProxyManager] Pass the factory code to execute to DumperInterface::getProxyFactoryCode() #23693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,20 @@ public function isProxyCandidate(Definition $definition)
/**
* {@inheritdoc}
*/
public function getProxyFactoryCode(Definition $definition, $id, $methodName = null)
public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null)
{
$instantiation = 'return';

if ($definition->isShared()) {
$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 === $factoryCode) {
@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);
$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 version 3.4, providing it will be required in 4.0.', __METHOD__), E_USER_DEPRECATED);
$factoryCode = "\$this->$factoryCode(false)";
}
$proxyClass = $this->getProxyClassName($definition);

Expand All @@ -92,7 +93,7 @@ public function getProxyFactoryCode(Definition $definition, $id, $methodName = n

$instantiation $constructorCall(
function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) {
\$wrappedInstance = \$this->$methodName(false);
\$wrappedInstance = $factoryCode;

\$proxy->setProxyInitializer(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testGetProxyFactoryCodeWithCustomMethod()

$definition->setLazy(true);

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

$this->assertStringMatchesFormat(
'%wif ($lazyLoad) {%wreturn $this->services[\'foo\'] =%s'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ private function addService($id, Definition $definition)

EOF;

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

if ($definition->isDeprecated()) {
$code .= sprintf(" @trigger_error(%s, E_USER_DEPRECATED);\n\n", $this->export($definition->getDeprecationMessage($id)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public function isProxyCandidate(Definition $definition);
* 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 $methodName the method name to get the service, will be added to the interface in 4.0
* @param string $id service identifier
* @param string $factoryCode the code to execute to create the service, will be added to the interface in 4.0
*
* @return string
*/
public function getProxyFactoryCode(Definition $definition, $id/**, $methodName = null */);
public function getProxyFactoryCode(Definition $definition, $id/**, $factoryCode = null */);

/**
* Generates the code for the lazy proxy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function isProxyCandidate(Definition $definition)
/**
* {@inheritdoc}
*/
public function getProxyFactoryCode(Definition $definition, $id, $methodName = null)
public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null)
{
return '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function isProxyCandidate(Definition $definition)
return false;
}

public function getProxyFactoryCode(Definition $definition, $id, $methodName = null)
public function getProxyFactoryCode(Definition $definition, $id, $factoryCall = null)
{
return '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', '(false)'));
$this->assertSame('', $dumper->getProxyCode($definition));
}
}
1 change: 1 addition & 0 deletions src/Symfony/Component/DependencyInjection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"conflict": {
"symfony/config": "<3.3.1",
"symfony/finder": "<3.3",
"symfony/proxy-manager-bridge": "<3.4",
"symfony/yaml": "<3.3"
},
"provide": {
Expand Down