Skip to content

Commit f58cfc0

Browse files
committed
merged branch stof/entity_provider_proxy (PR symfony#2922)
Commits ------- 649fa52 [DoctrineBridge] Fixed the entity provider to support proxies 29f4111 [DoctrineBridge] Added a failing test showing the issue for proxy users Discussion ---------- Fixed the entity provider to support proxies Bug fix: yes Feature addition: no Backwards compatibility break: yes Symfony2 tests pass: yes If a proxy object was used, the ``supportsClass`` method would fail becasue it does a string comparison for the class name. This issue has not been reported by users yet because it is an edge case: - ``supportsClass`` is used only in the RememberMe system - getting a proxy in the entity provider is possible only if a listener running before the firewall loaded an object which has a relation to the user, which is far from being a standard use case. --------------------------------------------------------------------------- by schmittjoh at 2011/12/19 10:07:46 -0800 How about using the new proxy tools that Doctrine has? --------------------------------------------------------------------------- by stof at 2011/12/19 10:20:37 -0800 the new tool will only be available in 2.2 so only for Symfony 2.1. Once merged into master, we could eventually refactor it in the master branch to use ``Doctrine\Common\Util\ClassUtils``
2 parents 4316595 + 649fa52 commit f58cfc0

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ public function refreshUser(UserInterface $user)
100100
*/
101101
public function supportsClass($class)
102102
{
103-
return $class === $this->class;
103+
return $class === $this->class || is_subclass_of($class, $this->class);
104104
}
105105
}

tests/Symfony/Tests/Bridge/Doctrine/Security/User/EntityUserProviderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ public function testRefreshInvalidUser()
7575
$provider->refreshUser($user2);
7676
}
7777

78+
public function testSupportProxy()
79+
{
80+
$em = $this->createTestEntityManager();
81+
$this->createSchema($em);
82+
83+
$user1 = new CompositeIdentEntity(1, 1, 'user1');
84+
85+
$em->persist($user1);
86+
$em->flush();
87+
$em->clear();
88+
89+
$provider = new EntityUserProvider($em, 'Symfony\Tests\Bridge\Doctrine\Fixtures\CompositeIdentEntity', 'name');
90+
91+
$user2 = $em->getReference('Symfony\Tests\Bridge\Doctrine\Fixtures\CompositeIdentEntity', array('id1' => 1, 'id2' => 1));
92+
$this->assertTrue($provider->supportsClass(get_class($user2)));
93+
}
94+
7895
private function createSchema($em)
7996
{
8097
$schemaTool = new SchemaTool($em);

0 commit comments

Comments
 (0)