From 104a76a6b1cac718696e8d7ccf1b6c7db0aa6aa7 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Wed, 1 Aug 2012 21:37:22 +0200 Subject: [PATCH] Update EntityRepository and PersistentCollection to new Criteria#expr() method instead of having to implement themselves. --- lib/Doctrine/ORM/EntityRepository.php | 19 +---------------- lib/Doctrine/ORM/PersistentCollection.php | 21 +------------------ lib/vendor/doctrine-common | 2 +- .../Functional/ClassTableInheritanceTest.php | 4 ++-- .../ORM/Functional/EntityRepositoryTest.php | 16 +++++++------- .../OneToManyBidirectionalAssociationTest.php | 8 +++---- .../Functional/SingleTableInheritanceTest.php | 4 ++-- 7 files changed, 19 insertions(+), 55 deletions(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 2dbf37a50..6956ada89 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -42,11 +42,6 @@ use Doctrine\Common\Collections\ExpressionBuilder; */ class EntityRepository implements ObjectRepository, Selectable { - /** - * @var Doctrine\Common\Collections\ExpressionBuilder - */ - private static $expressionBuilder; - /** * @var string */ @@ -277,17 +272,5 @@ class EntityRepository implements ObjectRepository, Selectable return new ArrayCollection($persister->loadCriteria($criteria)); } - - /** - * Return Builder object that helps with building criteria expressions. - * - * @return \Doctrine\Common\Collections\ExpressionBuilder - */ - public function expr() - { - if (self::$expressionBuilder === null) { - self::$expressionBuilder = new ExpressionBuilder(); - } - return self::$expressionBuilder; - } } + diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 19fae830d..30b0e01e7 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -46,11 +46,6 @@ use Closure; */ final class PersistentCollection implements Collection, Selectable { - /** - * @var Doctrine\Common\Collections\ExpressionBuilder - */ - static private $expressionBuilder; - /** * A snapshot of the collection at the moment it was fetched from the database. * This is used to create a diff of the collection at commit time. @@ -820,7 +815,7 @@ final class PersistentCollection implements Collection, Selectable $targetClass = $this->em->getClassMetadata(get_class($this->owner)); $id = $targetClass->getSingleIdReflectionProperty()->getValue($this->owner); - $builder = $this->expr(); + $builder = Criteria::expr(); $ownerExpression = $builder->eq($this->backRefFieldName, $id); $expression = $criteria->getWhereExpression(); $expression = $expression ? $builder->andX($expression, $ownerExpression) : $ownerExpression; @@ -831,19 +826,5 @@ final class PersistentCollection implements Collection, Selectable return new ArrayCollection($persister->loadCriteria($criteria)); } - - /** - * Return Builder object that helps with building criteria expressions. - * - * @return \Doctrine\Common\Collections\ExpressionBuilder - */ - public function expr() - { - if (self::$expressionBuilder === null) { - self::$expressionBuilder = new ExpressionBuilder(); - } - - return self::$expressionBuilder; - } } diff --git a/lib/vendor/doctrine-common b/lib/vendor/doctrine-common index 15b04ec52..0f7ba7fa7 160000 --- a/lib/vendor/doctrine-common +++ b/lib/vendor/doctrine-common @@ -1 +1 @@ -Subproject commit 15b04ec520ccded3dc0eba65b12a69ff1931360f +Subproject commit 0f7ba7fa7179bf445779f63fe5ccad355c81c06b diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index f7a6e93d7..c5193eaa7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -484,13 +484,13 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyEmployee"); $users = $repository->matching(new Criteria( - $repository->expr()->eq('department', 'IT') + Criteria::expr()->eq('department', 'IT') )); $this->assertEquals(1, count($users)); $repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyManager"); $users = $repository->matching(new Criteria( - $repository->expr()->eq('department', 'IT') + Criteria::expr()->eq('department', 'IT') )); $this->assertEquals(1, count($users)); } diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php index 9b5a845b8..2ce949478 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php @@ -582,7 +582,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $users = $repository->matching(new Criteria( - $repository->expr()->eq('username', 'beberlei') + Criteria::expr()->eq('username', 'beberlei') )); $this->assertEquals(1, count($users)); @@ -597,7 +597,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $users = $repository->matching(new Criteria( - $repository->expr()->neq('username', 'beberlei') + Criteria::expr()->neq('username', 'beberlei') )); $this->assertEquals(3, count($users)); @@ -612,7 +612,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $users = $repository->matching(new Criteria( - $repository->expr()->in('username', array('beberlei', 'gblanco')) + Criteria::expr()->in('username', array('beberlei', 'gblanco')) )); $this->assertEquals(2, count($users)); @@ -627,7 +627,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $users = $repository->matching(new Criteria( - $repository->expr()->notIn('username', array('beberlei', 'gblanco', 'asm89')) + Criteria::expr()->notIn('username', array('beberlei', 'gblanco', 'asm89')) )); $this->assertEquals(1, count($users)); @@ -642,7 +642,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $users = $repository->matching(new Criteria( - $repository->expr()->lt('id', $firstUserId + 1) + Criteria::expr()->lt('id', $firstUserId + 1) )); $this->assertEquals(1, count($users)); @@ -657,7 +657,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $users = $repository->matching(new Criteria( - $repository->expr()->lte('id', $firstUserId + 1) + Criteria::expr()->lte('id', $firstUserId + 1) )); $this->assertEquals(2, count($users)); @@ -672,7 +672,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $users = $repository->matching(new Criteria( - $repository->expr()->gt('id', $firstUserId) + Criteria::expr()->gt('id', $firstUserId) )); $this->assertEquals(3, count($users)); @@ -687,7 +687,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $users = $repository->matching(new Criteria( - $repository->expr()->gte('id', $firstUserId) + Criteria::expr()->gte('id', $firstUserId) )); $this->assertEquals(4, count($users)); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php index 18928f1d8..cea80fd6b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php @@ -4,7 +4,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\ECommerce\ECommerceProduct; use Doctrine\Tests\Models\ECommerce\ECommerceFeature; -use Doctrine\ORM\Mapping\AssociationMapping; +use Doctrine\Common\Collections\Criteria; require_once __DIR__ . '/../../TestInit.php'; @@ -161,14 +161,14 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->product->getId()); $features = $product->getFeatures(); - $results = $features->matching(new \Doctrine\Common\Collections\Criteria( - $features->expr()->eq('description', 'Model writing tutorial') + $results = $features->matching(new Criteria( + Criteria::expr()->eq('description', 'Model writing tutorial') )); $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $results); $this->assertEquals(1, count($results)); - $results = $features->matching(new \Doctrine\Common\Collections\Criteria()); + $results = $features->matching(new Criteria()); $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $results); $this->assertEquals(2, count($results)); diff --git a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php index 47d772542..1c1dbdc58 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php @@ -343,13 +343,13 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyContract"); $contracts = $repository->matching(new Criteria( - $repository->expr()->eq('salesPerson', $this->salesPerson->getId()) + Criteria::expr()->eq('salesPerson', $this->salesPerson->getId()) )); $this->assertEquals(3, count($contracts)); $repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyFixContract"); $contracts = $repository->matching(new Criteria( - $repository->expr()->eq('salesPerson', $this->salesPerson->getId()) + Criteria::expr()->eq('salesPerson', $this->salesPerson->getId()) )); $this->assertEquals(1, count($contracts)); }