Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbcfdac7

Browse files
[Bridge/Doctrine] Reset the EM lazy-proxy instead of the EM service
1 parent76791fe commitbcfdac7

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

‎src/Symfony/Bridge/Doctrine/ManagerRegistry.php‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespaceSymfony\Bridge\Doctrine;
1313

14+
useProxyManager\Proxy\LazyLoadingInterface;
15+
useProxyManager\Proxy\ValueHolderInterface;
1416
useSymfony\Component\DependencyInjection\ContainerAwareInterface;
1517
useSymfony\Component\DependencyInjection\ContainerAwareTrait;
1618
useDoctrine\Common\Persistence\AbstractManagerRegistry;
@@ -37,6 +39,35 @@ protected function getService($name)
3739
*/
3840
protectedfunctionresetService($name)
3941
{
40-
$this->container->set($name,null);
42+
if (!$this->container->initialized($name)) {
43+
return;
44+
}
45+
$manager =$this->container->get($name);
46+
47+
if (!$managerinstanceof LazyLoadingInterface) {
48+
@trigger_error(sprintf('Resetting a non-lazy manager service is deprecated since Symfony 3.2 and won\'t be supported in version 4.0. Set the "%s" service as lazy instead.',$name));
49+
50+
$this->container->set($name,null);
51+
52+
return;
53+
}
54+
$manager->setProxyInitializer(
55+
function (&$wrappedInstance,LazyLoadingInterface$manager)use ($name) {
56+
$this->container->set($name,null);
57+
$proxy =$this->container->get($name);
58+
59+
if ($proxyinstanceof LazyLoadingInterface && !$proxy->isProxyInitialized() &&$proxyinstanceof ValueHolderInterface) {
60+
$proxy->initializeProxy();
61+
$wrappedInstance =$proxy->getWrappedValueHolderValue();
62+
}else {
63+
$wrappedInstance =$proxy;
64+
}
65+
66+
$manager->setProxyInitializer(null);
67+
$this->container->set($name,$manager);
68+
69+
returntrue;
70+
}
71+
);
4172
}
4273
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bridge\Doctrine\Tests;
13+
14+
useSymfony\Bridge\Doctrine\ManagerRegistry;
15+
useSymfony\Bridge\ProxyManager\Tests\LazyProxy\Dumper\PhpDumperTest;
16+
useSymfony\Component\DependencyInjection\Container;
17+
18+
class ManagerRegistryTestextends \PHPUnit_Framework_TestCase
19+
{
20+
publicstaticfunctionsetUpBeforeClass()
21+
{
22+
$test =newPhpDumperTest();
23+
$test->testDumpContainerWithProxyServiceWillShareProxies();
24+
}
25+
26+
publicfunctiontestLegacyResetService()
27+
{
28+
$container =new \LazyServiceProjectServiceContainer();
29+
30+
$registry =newTestManagerRegistry('name',array(),array('defaultManager' =>'foo'),'defaultConnection','defaultManager','proxyInterfaceName');
31+
$registry->setContainer($container);
32+
33+
$foo =$container->get('foo');
34+
$foo->bar =123;
35+
$this->assertTrue(isset($foo->bar));
36+
37+
$registry->resetManager();
38+
39+
$this->assertSame($foo,$container->get('foo'));
40+
$this->assertFalse(isset($foo->bar));
41+
}
42+
}
43+
44+
class TestManagerRegistryextends ManagerRegistry
45+
{
46+
publicfunctiongetAliasNamespace($alias)
47+
{
48+
return'Foo';
49+
}
50+
}

‎src/Symfony/Bridge/Doctrine/composer.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"symfony/http-kernel":"~2.8|~3.0",
2828
"symfony/property-access":"~2.8|~3.0",
2929
"symfony/property-info":"~2.8|3.0",
30+
"symfony/proxy-manager-bridge":"~2.8|~3.0",
3031
"symfony/security":"~2.8|~3.0",
3132
"symfony/expression-language":"~2.8|~3.0",
3233
"symfony/validator":"~2.8|~3.0",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp