Skip to content
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

Monorepo v6 refactoring: EasyRepository #1436

Merged
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
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
"EonX\\EasyPipeline\\": "packages/EasyPipeline/src",
"EonX\\EasyRandom\\": "packages/EasyRandom/src",
"EonX\\EasyRepository\\": "packages/EasyRepository/src",
"EonX\\EasyRepository\\Bundle\\": "packages/EasyRepository/bundle",
"EonX\\EasyRepository\\Laravel\\": "packages/EasyRepository/laravel",
"EonX\\EasyRequestId\\": "packages/EasyRequestId/src",
"EonX\\EasySchedule\\": "packages/EasySchedule/src",
"EonX\\EasySecurity\\": "packages/EasySecurity/src",
Expand Down Expand Up @@ -163,6 +165,8 @@
"EonX\\EasyPipeline\\Tests\\": "packages/EasyPipeline/tests",
"EonX\\EasyRandom\\Tests\\": "packages/EasyRandom/tests",
"EonX\\EasyRepository\\Tests\\": "packages/EasyRepository/tests",
"EonX\\EasyRepository\\Tests\\Unit\\": "packages/EasyRepository/tests/Unit/src",
"EonX\\EasyRepository\\Tests\\Unit\\Laravel\\": "packages/EasyRepository/tests/Unit/laravel",
"EonX\\EasyRequestId\\Tests\\": "packages/EasyRequestId/tests",
"EonX\\EasySchedule\\Tests\\": "packages/EasySchedule/tests",
"EonX\\EasySecurity\\Tests\\": "packages/EasySecurity/tests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
declare(strict_types=1);

namespace EonX\EasyRepository\Bridge\Symfony\DependencyInjection\Compiler;
namespace EonX\EasyRepository\Bundle\CompilerPass;

use EonX\EasyPagination\Interfaces\PaginationInterface;
use EonX\EasyRepository\Bridge\BridgeConstantsInterface;
use EonX\EasyRepository\Bundle\Enum\ConfigTag;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

final class SetPaginationOnRepositoryPass implements CompilerPassInterface
final class SetPaginationOnRepositoryCompilerPass implements CompilerPassInterface
{
private const PAGINATION_SETTER = 'setPagination';

Expand All @@ -25,7 +25,7 @@ public function process(ContainerBuilder $container): void
}

// Find all paginated repo, if they have setPagination method, then add the method call
$paginatedRepoDefs = $container->findTaggedServiceIds(BridgeConstantsInterface::TAG_PAGINATED_REPOSITORY);
$paginatedRepoDefs = $container->findTaggedServiceIds(ConfigTag::PaginatedRepository->value);
$paginationRef = new Reference(PaginationInterface::class);

foreach ($paginatedRepoDefs as $id => $tags) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
<?php
declare(strict_types=1);

namespace EonX\EasyRepository\Bridge\Symfony;
namespace EonX\EasyRepository\Bundle;

use EonX\EasyRepository\Bridge\BridgeConstantsInterface;
use EonX\EasyRepository\Bridge\Symfony\DependencyInjection\Compiler\SetPaginationOnRepositoryPass;
use EonX\EasyRepository\Interfaces\PaginatedObjectRepositoryInterface;
use EonX\EasyRepository\Bundle\CompilerPass\SetPaginationOnRepositoryCompilerPass;
use EonX\EasyRepository\Bundle\Enum\ConfigTag;
use EonX\EasyRepository\Repository\PaginatedObjectRepositoryInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;

final class EasyRepositorySymfonyBundle extends AbstractBundle
final class EasyRepositoryBundle extends AbstractBundle
{
protected string $extensionAlias = 'easy_repository';

public function __construct()
{
$this->path = \realpath(__DIR__);
}

public function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new SetPaginationOnRepositoryPass());
$container->addCompilerPass(new SetPaginationOnRepositoryCompilerPass());
}

public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
{
$builder
->registerForAutoconfiguration(PaginatedObjectRepositoryInterface::class)
->addTag(BridgeConstantsInterface::TAG_PAGINATED_REPOSITORY);
->addTag(ConfigTag::PaginatedRepository->value);
}
}
9 changes: 9 additions & 0 deletions packages/EasyRepository/bundle/Enum/ConfigTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);

namespace EonX\EasyRepository\Bundle\Enum;

enum ConfigTag: string
{
case PaginatedRepository = 'easy_repository.paginated_repository';
}
11 changes: 7 additions & 4 deletions packages/EasyRepository/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
"eonx-com/easy-pagination": "^5.12",
"laravel/lumen-framework": "^9.1",
"mockery/mockery": "^1.6",
"phpunit/phpunit": "^10.2",
"vlucas/phpdotenv": "^5.5"
"phpunit/phpunit": "^10.2"
},
"autoload": {
"psr-4": {
"EonX\\EasyRepository\\": "src"
"EonX\\EasyRepository\\": "src",
"EonX\\EasyRepository\\Bundle\\": "bundle",
"EonX\\EasyRepository\\Laravel\\": "laravel"
}
},
"autoload-dev": {
"psr-4": {
"EonX\\EasyRepository\\Tests\\": "tests"
"EonX\\EasyRepository\\Tests\\": "tests",
"EonX\\EasyRepository\\Tests\\Unit\\": "tests/Unit/src",
"EonX\\EasyRepository\\Tests\\Unit\\Laravel\\": "tests/Unit/laravel"
}
},
"suggest": {
Expand Down
17 changes: 10 additions & 7 deletions packages/EasyRepository/docs/laravel_doctrine_orm_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ to use it to avoid you doing work already done.
Make sure all your repositories extend it, then you will be able to use the existing methods and/or create your own. To
be able to work properly this abstraction will ensure an entity class is provided.


Here is a simple example how to use it:

```php
Expand Down Expand Up @@ -76,13 +75,14 @@ final class PostRepository extends AbstractDoctrineRepository implements PostRep

## AbstractPaginatedDoctrineOrmRepository

If you need to deal with paginated sets of objects, this package provides you with `EonX\EasyRepository\Implementations\Doctrine\ORM\AbstractPaginatedDoctrineOrmRepository`
If you need to deal with paginated sets of objects, this package provides you with `EonX\EasyRepository\Repository\AbstractPaginatedDoctrineOrmRepository`
which has everything setup for you. This repository has a dependency on the `StartSizeDataInterface` from the `eonx/pagination`
package so to be able to use it you first need to update your project's dependencies:

```bash
$ composer require eonx/pagination
```
```

And then don't forget to register the service provider into your application, please refer to the [documentation][5].

Once everything setup, the pagination data will be resolved and injected automatically into your repositories. You will
Expand All @@ -96,7 +96,6 @@ Here is a simple example how to use it:
```php
// app/Repositories/PostRepositoryInterface.php

use App\Database\Entities\Post;
use EonX\EasyPagination\Interfaces\LengthAwarePaginatorInterface;

interface PostRepositoryInterface
Expand All @@ -107,7 +106,7 @@ interface PostRepositoryInterface
// app/Repositories/PostRepository.php

use App\Database\Entities\Post;
use EonX\EasyRepository\Implementations\Doctrine\ORM\AbstractPaginatedDoctrineOrmRepository;
use EonX\EasyRepository\Repository\AbstractPaginatedDoctrineOrmRepository;

final class PostRepository extends AbstractPaginatedDoctrineOrmRepository implements PostRepositoryInterface
{
Expand All @@ -117,10 +116,10 @@ final class PostRepository extends AbstractPaginatedDoctrineOrmRepository implem
->where('p.category = :category')
->setParameter('category', $category)
->getQuery();

return $this->doPaginate($query);
}

/**
* Get entity class managed by the repository.
*
Expand All @@ -134,7 +133,11 @@ final class PostRepository extends AbstractPaginatedDoctrineOrmRepository implem
```

[1]: https://laravel.com/

[2]: https://lumen.laravel.com/

[3]: https://www.doctrine-project.org/projects/orm.html

[4]: https://www.laraveldoctrine.org/docs/1.3/orm

[5]: https://github.com/eonx/easy-pagination/blob/master/docs/install_laravel.md
8 changes: 6 additions & 2 deletions packages/EasyRepository/docs/laravel_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ automatically. Make sure to register it:
'providers' => [
// Other Service Providers...

\EonX\EasyRepository\Bridge\Laravel\EasyRepositoryProvider::class,
\EonX\EasyRepository\Laravel\EasyRepositoryServiceProvider::class,
],
```

Expand Down Expand Up @@ -65,7 +65,7 @@ $app = new Laravel\Lumen\Application(\dirname(__DIR__));

// Other actions...

$app->register(\EonX\EasyRepository\Bridge\Laravel\EasyRepositoryProvider::class);
$app->register(\EonX\EasyRepository\Laravel\EasyRepositoryServiceProvider::class);
```

<br>
Expand Down Expand Up @@ -102,7 +102,11 @@ $app->make(\App\Repositories\PostRepositoryInterface::class); // Will be your co
```

[1]: https://laravel.com/

[2]: https://lumen.laravel.com/

[4]: https://laravel.com/docs/5.7/providers

[5]: https://en.wikipedia.org/wiki/Fully_qualified_name

[6]: http://php-di.org/doc/autowiring.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types=1);

namespace EonX\EasyRepository\Bridge\Laravel;
namespace EonX\EasyRepository\Laravel;

use EonX\EasyRepository\Bridge\Laravel\Exceptions\EmptyRepositoriesListException;
use Illuminate\Support\ServiceProvider;
use LogicException;

final class EasyRepositoryProvider extends ServiceProvider
final class EasyRepositoryServiceProvider extends ServiceProvider
{
public function boot(): void
{
Expand All @@ -21,7 +21,7 @@ public function register(): void

$repositories = (array)\config('easy-repository.repositories', []);
if (\count($repositories) === 0) {
throw new EmptyRepositoriesListException(
throw new LogicException(
'No repositories to register. Please make sure your application has the expected configuration'
);
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace EonX\EasyRepository\Exception;

use RuntimeException;

final class EasyPaginationNotInstalledException extends RuntimeException implements EasyRepositoryExceptionInterface
{
// No body needed
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace EonX\EasyRepository\Interfaces;
namespace EonX\EasyRepository\Exception;

interface EasyRepositoryExceptionInterface
{
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php
declare(strict_types=1);

namespace EonX\EasyRepository\Implementations\Doctrine\ORM;
namespace EonX\EasyRepository\Repository;

use Doctrine\Persistence\ManagerRegistry;
use EonX\EasyRepository\Interfaces\DatabaseRepositoryInterface;
use UnexpectedValueException;

abstract class AbstractDoctrineOrmRepository implements DatabaseRepositoryInterface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php
declare(strict_types=1);

namespace EonX\EasyRepository\Implementations\Illuminate;
namespace EonX\EasyRepository\Repository;

use Closure;
use EonX\EasyRepository\Interfaces\DatabaseRepositoryInterface;
use Illuminate\Database\Eloquent\Model;
use Throwable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace EonX\EasyRepository\Implementations\Doctrine\ORM;
namespace EonX\EasyRepository\Repository;

use Closure;
use Doctrine\DBAL\Exception;
Expand All @@ -14,9 +14,8 @@
use EonX\EasyPagination\Interfaces\LengthAwarePaginatorInterface;
use EonX\EasyPagination\Interfaces\PaginationInterface;
use EonX\EasyPagination\Paginators\DoctrineOrmLengthAwarePaginator;
use EonX\EasyRepository\Exceptions\EasyPaginationNotInstalledException;
use EonX\EasyRepository\Interfaces\DatabaseRepositoryInterface;
use EonX\EasyRepository\Interfaces\PaginatedObjectRepositoryInterface as PaginatedObjRepoInterface;
use EonX\EasyRepository\Exception\EasyPaginationNotInstalledException;
use EonX\EasyRepository\Repository\PaginatedObjectRepositoryInterface as PaginatedObjRepoInterface;
use Throwable;

abstract class AbstractOptimizedDoctrineOrmRepository implements DatabaseRepositoryInterface, PaginatedObjRepoInterface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
declare(strict_types=1);

namespace EonX\EasyRepository\Implementations\Doctrine\ORM;
namespace EonX\EasyRepository\Repository;

use Doctrine\ORM\Query;
use Doctrine\Persistence\ManagerRegistry;
use EonX\EasyPagination\Interfaces\LengthAwarePaginatorInterface;
use EonX\EasyPagination\Interfaces\PaginationInterface;
use EonX\EasyPagination\Paginators\DoctrineOrmLengthAwarePaginator;
use EonX\EasyRepository\Interfaces\PaginatedObjectRepositoryInterface as RepoInterface;
use EonX\EasyRepository\Repository\PaginatedObjectRepositoryInterface as RepoInterface;

abstract class AbstractPaginatedDoctrineOrmRepository extends AbstractDoctrineOrmRepository implements RepoInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace EonX\EasyRepository\Interfaces;
namespace EonX\EasyRepository\Repository;

use Closure;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace EonX\EasyRepository\Implementations\Doctrine\ORM;
namespace EonX\EasyRepository\Repository;

use Closure;
use Doctrine\DBAL\Exception;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace EonX\EasyRepository\Interfaces;
namespace EonX\EasyRepository\Repository;

interface ObjectRepositoryInterface
{
Expand Down
Loading