diff --git a/UPGRADE.md b/UPGRADE.md index 8fcbe22b..fdfa7b27 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -12,6 +12,14 @@ * The `Bitwise` operands was removed. * The `Happyr\DoctrineSpecification\Specification\Having` class was removed, use `Happyr\DoctrineSpecification\Query\Having` instead. +* The `Happyr\DoctrineSpecification\EntitySpecificationRepository` class was removed, use + `Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository` instead. +* The `Happyr\DoctrineSpecification\EntitySpecificationRepositoryInterface` class was removed, use + `Happyr\DoctrineSpecification\Repository\EntitySpecificationRepositoryInterface` instead. +* The `Happyr\DoctrineSpecification\EntitySpecificationRepositoryTrait` class was removed, use + `Happyr\DoctrineSpecification\Repository\EntitySpecificationRepositoryTrait` instead. +* The `Happyr\DoctrineSpecification\RepositoryFactory` class was removed, use + `Happyr\DoctrineSpecification\Repository\RepositoryFactory` instead. * Removes the ability to use `array` as argument for the `PlatformFunction` operand. Before: diff --git a/docs/0-0-symfony.md b/docs/0-0-symfony.md index 5feefdee..553105e8 100644 --- a/docs/0-0-symfony.md +++ b/docs/0-0-symfony.md @@ -2,12 +2,12 @@ ## Replacing the default repository type -Replacing Doctrine's default repository type with `Happyr\DoctrineSpecification\EntitySpecificationRepository` is easy +Replacing Doctrine's default repository type with `Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository` is easy in Symfony. The doctrine bundle provides a place in configuration to specify the new type. ```yml // app/config/config.yml doctrine: orm: - default_repository_class: Happyr\DoctrineSpecification\EntitySpecificationRepository + default_repository_class: Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository ``` diff --git a/docs/0-1-zend1.md b/docs/0-1-zend1.md index ee59ed38..f94527b7 100644 --- a/docs/0-1-zend1.md +++ b/docs/0-1-zend1.md @@ -5,9 +5,9 @@ Doctrine integration with Zend Framework 1 is done manually. However, replacing the default repository type is still simple. In the bootstrap (or wherever Doctrine is configured in the system in question), use Doctrine configurations `setRepositoryFactory` method and provide an implementation of `Doctrine\ORM\Repository\RepositoryFactory`. A basic -implementation is provided with `Happyr\DoctrineSpecification\RepositoryFactory`. +implementation is provided with `Happyr\DoctrineSpecification\Repository\RepositoryFactory`. ```php // During doctrine configuration -$config->setRepositoryFactory(new \Happyr\DoctrineSpecification\RepositoryFactory()); +$config->setRepositoryFactory(new \Happyr\DoctrineSpecification\Repository\RepositoryFactory()); ``` diff --git a/docs/0-2-zend2.md b/docs/0-2-zend2.md index 861df80d..eac4d21b 100644 --- a/docs/0-2-zend2.md +++ b/docs/0-2-zend2.md @@ -4,7 +4,7 @@ Doctrine integration with Zend Framework 2 can be achieved using the `DoctrineORM` bundle. This bundle contains configuration options for the repository factory. To replace the default repository type, provide a factory creating - an instance of `Happyr\DoctrineSpecification\EntitySpecificationRepository` and any necessary configuration options. +an instance of `Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository` and any necessary configuration options. ```php // Application configuration @@ -17,7 +17,7 @@ configuration options for the repository factory. To replace the default reposit 'service_manager' => [ 'services' => [ - 'happyr_doctrinespecification_repository' => new Happyr\DoctrineSpecification\RepositoryFactory(), + 'happyr_doctrinespecification_repository' => new Happyr\DoctrineSpecification\Repository\RepositoryFactory(), ], ], ]; diff --git a/docs/0-3-laravel.md b/docs/0-3-laravel.md index 71e5d87f..52b5cbde 100644 --- a/docs/0-3-laravel.md +++ b/docs/0-3-laravel.md @@ -6,9 +6,8 @@ If you're choosing to use Doctrine with Laravel, there are some common Doctrine ### atrauzzi/laravel-doctrine -For this package, in its configuration settings, set the `defaultRepository` setting to `Happyr\DoctrineSpecification\EntitySpecificationRepository` +For this package, in its configuration settings, set the `defaultRepository` setting to `Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository` ### mitchellvanw/laravel-doctrine -For this package, in its configuration settings, set the `repository` setting to `Happyr\DoctrineSpecification\EntitySpecificationRepository` - +For this package, in its configuration settings, set the `repository` setting to `Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository` diff --git a/docs/0-usage.md b/docs/0-usage.md index 5f33178f..4d587472 100644 --- a/docs/0-usage.md +++ b/docs/0-usage.md @@ -13,7 +13,7 @@ Install this lib with composer. } ``` -Let your repositories extend `Happyr\DoctrineSpecification\EntitySpecificationRepository` instead of `Doctrine\ORM\EntityRepository`, or use the `EntitySpecificationRepositoryTrait` in your repositories, like so: +Let your repositories extend `Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository` instead of `Doctrine\ORM\EntityRepository`, or use the `EntitySpecificationRepositoryTrait` in your repositories, like so: ```php em->getRepository('xxx')` to return a instance of `Happyr\DoctrineSpecification\EntitySpecificationRepository`. +then you will have to tell `$this->em->getRepository('xxx')` to return a instance of `Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository`. See instructions for [Laravel](0-3-laravel.md), [Symfony2](0-0-symfony.md), [Zend1](0-1-zend1.md) and [Zend2](0-2-zend2.md). Then you may start to create your specifications. Put them in `Acme\DemoBundle\Entity\Spec`. Lets start with a simple one: diff --git a/src/EntitySpecificationRepository.php b/src/Repository/EntitySpecificationRepository.php similarity index 93% rename from src/EntitySpecificationRepository.php rename to src/Repository/EntitySpecificationRepository.php index 6e1f9e02..9bde7d10 100644 --- a/src/EntitySpecificationRepository.php +++ b/src/Repository/EntitySpecificationRepository.php @@ -12,7 +12,7 @@ * file that was distributed with this source code. */ -namespace Happyr\DoctrineSpecification; +namespace Happyr\DoctrineSpecification\Repository; use Doctrine\ORM\EntityRepository; diff --git a/src/EntitySpecificationRepositoryInterface.php b/src/Repository/EntitySpecificationRepositoryInterface.php similarity index 98% rename from src/EntitySpecificationRepositoryInterface.php rename to src/Repository/EntitySpecificationRepositoryInterface.php index f89fad82..a4fb38f5 100644 --- a/src/EntitySpecificationRepositoryInterface.php +++ b/src/Repository/EntitySpecificationRepositoryInterface.php @@ -12,7 +12,7 @@ * file that was distributed with this source code. */ -namespace Happyr\DoctrineSpecification; +namespace Happyr\DoctrineSpecification\Repository; use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\Query; diff --git a/src/EntitySpecificationRepositoryTrait.php b/src/Repository/EntitySpecificationRepositoryTrait.php similarity index 88% rename from src/EntitySpecificationRepositoryTrait.php rename to src/Repository/EntitySpecificationRepositoryTrait.php index c8327b50..671bd1c1 100644 --- a/src/EntitySpecificationRepositoryTrait.php +++ b/src/Repository/EntitySpecificationRepositoryTrait.php @@ -12,13 +12,15 @@ * file that was distributed with this source code. */ -namespace Happyr\DoctrineSpecification; +namespace Happyr\DoctrineSpecification\Repository; use Doctrine\ORM\AbstractQuery; -use Doctrine\ORM\NonUniqueResultException; -use Doctrine\ORM\NoResultException; +use Doctrine\ORM\NonUniqueResultException as DoctrineNonUniqueResultException; +use Doctrine\ORM\NoResultException as DoctrineNoResultException; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; +use Happyr\DoctrineSpecification\Exception\NonUniqueResultException; +use Happyr\DoctrineSpecification\Exception\NoResultException; use Happyr\DoctrineSpecification\Filter\Filter; use Happyr\DoctrineSpecification\Query\QueryModifier; use Happyr\DoctrineSpecification\Result\ResultModifier; @@ -65,10 +67,10 @@ public function matchSingleResult($specification, ?ResultModifier $modifier = nu try { return $query->getSingleResult(); - } catch (NonUniqueResultException $e) { - throw new Exception\NonUniqueResultException($e->getMessage(), $e->getCode(), $e); - } catch (NoResultException $e) { - throw new Exception\NoResultException($e->getMessage(), $e->getCode(), $e); + } catch (DoctrineNonUniqueResultException $e) { + throw new NonUniqueResultException($e->getMessage(), $e->getCode(), $e); + } catch (DoctrineNoResultException $e) { + throw new NoResultException($e->getMessage(), $e->getCode(), $e); } } @@ -86,7 +88,7 @@ public function matchOneOrNullResult($specification, ?ResultModifier $modifier = { try { return $this->matchSingleResult($specification, $modifier); - } catch (Exception\NoResultException $e) { + } catch (NoResultException $e) { return null; } } @@ -108,8 +110,8 @@ public function matchSingleScalarResult($specification, ?ResultModifier $modifie try { return $query->getSingleScalarResult(); - } catch (NonUniqueResultException $e) { - throw new Exception\NonUniqueResultException($e->getMessage(), $e->getCode(), $e); + } catch (DoctrineNonUniqueResultException $e) { + throw new NonUniqueResultException($e->getMessage(), $e->getCode(), $e); } } diff --git a/src/RepositoryFactory.php b/src/Repository/RepositoryFactory.php similarity index 96% rename from src/RepositoryFactory.php rename to src/Repository/RepositoryFactory.php index af6d25e1..04c68130 100644 --- a/src/RepositoryFactory.php +++ b/src/Repository/RepositoryFactory.php @@ -12,7 +12,7 @@ * file that was distributed with this source code. */ -namespace Happyr\DoctrineSpecification; +namespace Happyr\DoctrineSpecification\Repository; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; diff --git a/tests/EntitySpecificationRepositorySpec.php b/tests/Repository/EntitySpecificationRepositorySpec.php similarity index 98% rename from tests/EntitySpecificationRepositorySpec.php rename to tests/Repository/EntitySpecificationRepositorySpec.php index b8efec4d..867a7d9f 100644 --- a/tests/EntitySpecificationRepositorySpec.php +++ b/tests/Repository/EntitySpecificationRepositorySpec.php @@ -12,7 +12,7 @@ * file that was distributed with this source code. */ -namespace tests\Happyr\DoctrineSpecification; +namespace tests\Happyr\DoctrineSpecification\Repository; use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\EntityManager; @@ -20,12 +20,12 @@ use Doctrine\ORM\NonUniqueResultException as DoctrineNonUniqueResultException; use Doctrine\ORM\NoResultException as DoctrineNoResultException; use Doctrine\ORM\QueryBuilder; -use Happyr\DoctrineSpecification\EntitySpecificationRepository; use Happyr\DoctrineSpecification\Exception\NonUniqueResultException; use Happyr\DoctrineSpecification\Exception\NoResultException; use Happyr\DoctrineSpecification\Exception\UnexpectedResultException; use Happyr\DoctrineSpecification\Filter\Filter; use Happyr\DoctrineSpecification\Query\QueryModifier; +use Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository; use Happyr\DoctrineSpecification\Result\ResultModifier; use Happyr\DoctrineSpecification\Specification\Specification; use PhpSpec\ObjectBehavior;