-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EasyPagination] Clean up + Refactor pagination and paginators (#662)
* [WIP][EasyPagination] Clean up + Refactor pagination and paginators * [WIP][EasyPagination] Fix phpstan * [WIP][EasyPagination] Fix phpstan - 1 * [WIP][EasyPagination] Fix phpstan - 2 * [EasyPagination] Implement bridges for new pagination provider * [EasyPagination] Fix phpstan
- Loading branch information
Showing
81 changed files
with
3,841 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/EasyPagination/src/Bridge/BridgeConstantsInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EonX\EasyPagination\Bridge; | ||
|
||
interface BridgeConstantsInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public const PARAM_PAGE_ATTRIBUTE = 'easy_pagination.page_attribute'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public const PARAM_PAGE_DEFAULT = 'easy_pagination.page_default'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public const PARAM_PER_PAGE_ATTRIBUTE = 'easy_pagination.per_page_attribute'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public const PARAM_PER_PAGE_DEFAULT = 'easy_pagination.per_page_default'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/EasyPagination/src/Bridge/Laravel/Listeners/FromRequestPaginationListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EonX\EasyPagination\Bridge\Laravel\Listeners; | ||
|
||
use EonX\EasyPagination\Interfaces\PaginationProviderInterface; | ||
use EonX\EasyPagination\Resolvers\FromHttpFoundationRequestResolver; | ||
use Illuminate\Routing\Events\RouteMatched; | ||
|
||
final class FromRequestPaginationListener | ||
{ | ||
/** | ||
* @var \EonX\EasyPagination\Interfaces\PaginationProviderInterface | ||
*/ | ||
private $paginationProvider; | ||
|
||
public function __construct(PaginationProviderInterface $paginationProvider) | ||
{ | ||
$this->paginationProvider = $paginationProvider; | ||
} | ||
|
||
public function handle(RouteMatched $event): void | ||
{ | ||
$resolver = new FromHttpFoundationRequestResolver( | ||
$this->paginationProvider->getPaginationConfig(), | ||
$event->request | ||
); | ||
|
||
$this->paginationProvider->setResolver($resolver); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/EasyPagination/src/Bridge/Laravel/Middleware/PaginationFromRequestMiddleware.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EonX\EasyPagination\Bridge\Laravel\Middleware; | ||
|
||
use EonX\EasyPagination\Interfaces\PaginationProviderInterface; | ||
use EonX\EasyPagination\Resolvers\FromHttpFoundationRequestResolver; | ||
use Illuminate\Http\Request; | ||
|
||
final class PaginationFromRequestMiddleware | ||
{ | ||
/** | ||
* @var \EonX\EasyPagination\Interfaces\PaginationProviderInterface | ||
*/ | ||
private $paginationProvider; | ||
|
||
public function __construct(PaginationProviderInterface $paginationProvider) | ||
{ | ||
$this->paginationProvider = $paginationProvider; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function handle(Request $request, \Closure $next) | ||
{ | ||
$resolver = new FromHttpFoundationRequestResolver( | ||
$this->paginationProvider->getPaginationConfig(), | ||
$request | ||
); | ||
|
||
$this->paginationProvider->setResolver($resolver); | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
packages/EasyPagination/src/Bridge/Laravel/Providers/EasyPaginationServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EonX\EasyPagination\Bridge\Laravel\Providers; | ||
|
||
use EonX\EasyPagination\Bridge\Laravel\Listeners\FromRequestPaginationListener; | ||
use EonX\EasyPagination\Bridge\Laravel\Middleware\PaginationFromRequestMiddleware; | ||
use EonX\EasyPagination\Interfaces\PaginationInterface; | ||
use EonX\EasyPagination\Interfaces\PaginationProviderInterface; | ||
use EonX\EasyPagination\PaginationConfig; | ||
use EonX\EasyPagination\PaginationProvider; | ||
use Illuminate\Contracts\Container\Container; | ||
use Illuminate\Routing\Events\RouteMatched; | ||
use Illuminate\Support\ServiceProvider; | ||
use Laravel\Lumen\Application as LumenApplication; | ||
|
||
final class EasyPaginationServiceProvider extends ServiceProvider | ||
{ | ||
public function boot(): void | ||
{ | ||
$this->publishes([ | ||
__DIR__ . '/../config/easy-pagination.php' => \base_path('config/easy-pagination.php'), | ||
]); | ||
} | ||
|
||
/** | ||
* @throws \Illuminate\Contracts\Container\BindingResolutionException | ||
*/ | ||
public function register(): void | ||
{ | ||
$this->mergeConfigFrom(__DIR__ . '/../config/easy-pagination.php', 'easy-pagination'); | ||
|
||
$this->registerPaginationProvider(); | ||
$this->registerDefaultResolver(); | ||
} | ||
|
||
/** | ||
* @throws \Illuminate\Contracts\Container\BindingResolutionException | ||
*/ | ||
private function registerDefaultResolver(): void | ||
{ | ||
if (\config('easy-pagination.user_default_resolver', true) === false) { | ||
return; | ||
} | ||
|
||
// Lumen | ||
if ($this->app instanceof LumenApplication) { | ||
$this->app->singleton( | ||
PaginationFromRequestMiddleware::class, | ||
static function (Container $app): PaginationFromRequestMiddleware { | ||
return new PaginationFromRequestMiddleware($app->make(PaginationProviderInterface::class)); | ||
} | ||
); | ||
$this->app->middleware([PaginationFromRequestMiddleware::class]); | ||
|
||
return; | ||
} | ||
|
||
// Laravel | ||
$this->app->singleton( | ||
FromRequestPaginationListener::class, | ||
static function (Container $app): FromRequestPaginationListener { | ||
return new FromRequestPaginationListener($app->make(PaginationProviderInterface::class)); | ||
} | ||
); | ||
$this->app->make('events')->listen(RouteMatched::class, FromRequestPaginationListener::class); | ||
} | ||
|
||
private function registerPaginationProvider(): void | ||
{ | ||
$this->app->singleton( | ||
PaginationProviderInterface::class, | ||
static function (): PaginationProviderInterface { | ||
$config = new PaginationConfig( | ||
\config('easy-pagination.pagination.page_attribute'), | ||
(int)\config('easy-pagination.pagination.page_default'), | ||
\config('easy-pagination.pagination.per_page_attribute'), | ||
(int)\config('easy-pagination.pagination.per_page_default') | ||
); | ||
|
||
return new PaginationProvider($config); | ||
} | ||
); | ||
|
||
$this->app->singleton(PaginationInterface::class, static function (Container $app): PaginationInterface { | ||
return $app->make(PaginationProviderInterface::class)->getPagination(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/EasyPagination/src/Bridge/Laravel/config/easy-pagination.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use EonX\EasyPagination\Bridge\BridgeConstantsInterface; | ||
|
||
return [ | ||
'pagination' => [ | ||
'page_attribute' => \env('PAGINATION_PAGE_ATTRIBUTE', BridgeConstantsInterface::PARAM_PAGE_ATTRIBUTE), | ||
'page_default' => \env('PAGINATION_PAGE_DEFAULT', BridgeConstantsInterface::PARAM_PAGE_DEFAULT), | ||
'per_page_attribute' => \env('PAGINATION_PER_PAGE_ATTRIBUTE', BridgeConstantsInterface::PARAM_PER_PAGE_ATTRIBUTE), | ||
'per_page_default' => \env('PAGINATION_PER_PAGE_DEFAULT', BridgeConstantsInterface::PARAM_PER_PAGE_DEFAULT), | ||
], | ||
|
||
'use_default_resolver' => \env('PAGINATION_USE_DEFAULT_RESOLVER', true), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.