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

Appearance settings

[Bridge/Doctrine] Reset the EM lazy-proxy instead of the EM service #19203

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 1, 2016
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
[Bridge/Doctrine] Reset the EM lazy-proxy instead of the EM service
  • Loading branch information
nicolas-grekas committed Jul 1, 2016
commit c581cd4c8162b08ed713174a2556c078069dfb39
30 changes: 29 additions & 1 deletion 30 src/Symfony/Bridge/Doctrine/ManagerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Bridge\Doctrine;

use ProxyManager\Proxy\LazyLoadingInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Doctrine\Common\Persistence\AbstractManagerRegistry;
Expand All @@ -37,6 +39,32 @@ protected function getService($name)
*/
protected function resetService($name)
{
$this->container->set($name, null);
if (!$this->container->initialized($name)) {
return;
}
$manager = $this->container->get($name);

if (!$manager instanceof LazyLoadingInterface) {
@trigger_error(sprintf('Resetting a non-lazy manager service is deprecated since Symfony 3.2 and will throw an exception in version 4.0. Set the "%s" service as lazy and require "symfony/proxy-manager-bridge" in your composer.json file instead.', $name));

$this->container->set($name, null);

return;
}
$manager->setProxyInitializer(\Closure::bind(
function (&$wrappedInstance, LazyLoadingInterface $manager) use ($name) {
if (isset($this->aliases[$name = strtolower($name)])) {
$name = $this->aliases[$name];
}
$method = !isset($this->methodMap[$name]) ? 'get'.strtr($name, $this->underscoreMap).'Service' : $this->methodMap[$name];
$wrappedInstance = $this->{$method}(false);

$manager->setProxyInitializer(null);

return true;
},
$this->container,
Container::class
));
}
}
49 changes: 49 additions & 0 deletions 49 src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests;

use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Bridge\ProxyManager\Tests\LazyProxy\Dumper\PhpDumperTest;

class ManagerRegistryTest extends \PHPUnit_Framework_TestCase
{
public static function setUpBeforeClass()
{
$test = new PhpDumperTest();
$test->testDumpContainerWithProxyServiceWillShareProxies();
}

public function testResetService()
{
$container = new \LazyServiceProjectServiceContainer();

$registry = new TestManagerRegistry('name', array(), array('defaultManager' => 'foo'), 'defaultConnection', 'defaultManager', 'proxyInterfaceName');
$registry->setContainer($container);

$foo = $container->get('foo');
$foo->bar = 123;
$this->assertTrue(isset($foo->bar));

$registry->resetManager();

$this->assertSame($foo, $container->get('foo'));
$this->assertFalse(isset($foo->bar));
}
}

class TestManagerRegistry extends ManagerRegistry
{
public function getAliasNamespace($alias)
{
return 'Foo';
}
}
1 change: 1 addition & 0 deletions 1 src/Symfony/Bridge/Doctrine/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"symfony/http-kernel": "~2.8|~3.0",
"symfony/property-access": "~2.8|~3.0",
"symfony/property-info": "~2.8|3.0",
"symfony/proxy-manager-bridge": "~2.8|~3.0",
"symfony/security": "~2.8|~3.0",
"symfony/expression-language": "~2.8|~3.0",
"symfony/validator": "~2.8|~3.0",
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.