Skip to content

Commit

Permalink
Merge pull request #281 from peter-gribanov/group_repositories_2.0
Browse files Browse the repository at this point in the history
Group repository classes in Repository folder
  • Loading branch information
peter-gribanov authored Jan 20, 2021
2 parents 5877a98 + 57abf14 commit 9fa07d6
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 26 deletions.
8 changes: 8 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions docs/0-0-symfony.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
4 changes: 2 additions & 2 deletions docs/0-1-zend1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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());
```
4 changes: 2 additions & 2 deletions docs/0-2-zend2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
],
],
];
Expand Down
5 changes: 2 additions & 3 deletions docs/0-3-laravel.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
4 changes: 2 additions & 2 deletions docs/0-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
Expand All @@ -40,7 +40,7 @@ class MyRepository extends ServiceEntityRepository
```

Also make sure that the default repository is changed. If you haven't created a repository class in your source
then you will have to tell `$this->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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* file that was distributed with this source code.
*/

namespace Happyr\DoctrineSpecification;
namespace Happyr\DoctrineSpecification\Repository;

use Doctrine\ORM\EntityRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
}
}
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
* 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;
use Doctrine\ORM\Mapping\ClassMetadata;
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;
Expand Down

0 comments on commit 9fa07d6

Please sign in to comment.