-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: api platform support * add link to api page * feat(`OpenApi`): change all 'page' parameters to accept string * test: provider returning PageInterface * feat(ApiPlatform): add `PageNormalizer` & `PagerFactory` * bump flex * add --no-scripts to CI * remove flex from root composer.json * suppress toomanyarguments for pagenormalizer * check CI on highest dep only for now * remove apiresource from mapping path * limit ci to symfony 7 * Doctrine ORM support * refactor * spinoff common bundle classes to symfony-bridge package * obtain itemsPerPage in PagerFactory * add api test * fix tests * add type detection to QueryBuilderAdapter * disable orm support by default, add config to enable it * release 0.8.0
- Loading branch information
Showing
53 changed files
with
1,702 additions
and
58 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# rekalogika/rekapager-api-platform | ||
|
||
Integrates Rekapager with the API Platform framework. | ||
|
||
Rekapager is a pagination library for PHP, supporting both offset-based and | ||
keyset-based pagination. | ||
|
||
## Documentation | ||
|
||
[rekalogika.dev/rekapager](https://rekalogika.dev/rekapager) | ||
|
||
## License | ||
|
||
MIT | ||
|
||
## Contributing | ||
|
||
This framework consists of multiple repositories split from a monorepo. Be | ||
sure to submit issues and pull requests to the | ||
[`rekalogika/rekapager`](https://github.com/rekalogika/rekapager) monorepo. |
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,43 @@ | ||
{ | ||
"name": "rekalogika/rekapager-api-platform", | ||
"description": "Adds Rekapager support to API Platform", | ||
"homepage": "https://rekalogika.dev/rekapager", | ||
"keywords": [ | ||
"pagination", | ||
"symfony", | ||
"api-platform", | ||
"api", | ||
"bundle", | ||
"symfony-bundle", | ||
"rekapager", | ||
"pager", | ||
"keyset-pagination", | ||
"offset-pagination" | ||
], | ||
"license": "MIT", | ||
"type": "symfony-bundle", | ||
"authors": [ | ||
{ | ||
"name": "Priyadi Iman Nurcahyo", | ||
"email": "priyadi@rekalogika.com" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Rekalogika\\Rekapager\\ApiPlatform\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"php": "^8.2", | ||
"api-platform/core": "^3.2", | ||
"psr/container": "^2.0", | ||
"rekalogika/rekapager-contracts": "^0.8", | ||
"rekalogika/rekapager-core": "^0.8", | ||
"rekalogika/rekapager-symfony-bridge": "^0.8", | ||
"symfony/config": "^6.4 || ^7.0", | ||
"symfony/dependency-injection": "^6.4 || ^7.0", | ||
"symfony/flex": "^2.4", | ||
"symfony/http-foundation": "^6.4 || ^7.0", | ||
"symfony/http-kernel": "^6.4 || ^7.0" | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/rekapager package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
}; |
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,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/rekapager package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
use Rekalogika\Rekapager\ApiPlatform\Implementation\PageNormalizer; | ||
use Rekalogika\Rekapager\ApiPlatform\Implementation\PagerFactory; | ||
use Rekalogika\Rekapager\ApiPlatform\Implementation\RekapagerExtension; | ||
use Rekalogika\Rekapager\ApiPlatform\Implementation\RekapagerOpenApiFactoryDecorator; | ||
use Rekalogika\Rekapager\Contracts\PageIdentifierEncoderLocatorInterface; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
use function Symfony\Component\DependencyInjection\Loader\Configurator\service; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$parameters = $containerConfigurator->parameters(); | ||
|
||
$parameters | ||
->set( | ||
'rekalogika.rekapager.api_platform.enable_orm_support_by_default', | ||
false | ||
); | ||
|
||
$services = $containerConfigurator->services(); | ||
|
||
$services->set('rekalogika.rekapager.api_platform.open_api_factory_decorator') | ||
->class(RekapagerOpenApiFactoryDecorator::class) | ||
->decorate('api_platform.openapi.factory') | ||
->args([ | ||
'$decorated' => service('.inner'), | ||
]); | ||
|
||
$services->set(PagerFactory::class) | ||
->args([ | ||
'$resourceMetadataFactory' => service('api_platform.metadata.resource.metadata_collection_factory'), | ||
'$pageIdentifierEncoderLocator' => service(PageIdentifierEncoderLocatorInterface::class), | ||
'$pagination' => service('api_platform.pagination'), | ||
'$pageParameterName' => '%api_platform.collection.pagination.page_parameter_name%', | ||
'$urlGenerationStrategy' => '%api_platform.url_generation_strategy%' | ||
]); | ||
|
||
$services->set('rekalogika.rekapager.api_platform.page_normalizer') | ||
->class(PageNormalizer::class) | ||
->decorate('api_platform.hydra.normalizer.collection') | ||
->args([ | ||
'$collectionNormalizer' => service('.inner'), | ||
]); | ||
|
||
$services->set('rekalogika.rekapager.api_platform.orm.extension') | ||
->class(RekapagerExtension::class) | ||
->args([ | ||
'$pagerFactory' => service(PagerFactory::class), | ||
'$pagination' => service('api_platform.pagination'), | ||
'$enabledByDefault' => '%rekalogika.rekapager.api_platform.enable_orm_support_by_default%', | ||
]) | ||
->tag('api_platform.doctrine.orm.query_extension.collection', [ | ||
'priority' => -48, | ||
]); | ||
}; |
39 changes: 39 additions & 0 deletions
39
packages/rekapager-api-platform/src/DependencyInjection/Configuration.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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/rekapager package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\Rekapager\ApiPlatform\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class Configuration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$treeBuilder = new TreeBuilder('rekalogika_rekapager_api_platform'); | ||
|
||
/** @var ArrayNodeDefinition $rootNode */ | ||
$rootNode = $treeBuilder->getRootNode(); | ||
|
||
$rootNode | ||
->children() | ||
->booleanNode('enable_orm_support_by_default') | ||
->defaultValue(false) | ||
->end() | ||
->end() | ||
; | ||
|
||
return $treeBuilder; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...ekapager-api-platform/src/DependencyInjection/RekalogikaRekapagerApiPlatformExtension.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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/rekapager package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\Rekapager\ApiPlatform\DependencyInjection; | ||
|
||
use Rekalogika\Rekapager\Symfony\RekapagerSymfonyBridge; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\Extension; | ||
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; | ||
|
||
class RekalogikaRekapagerApiPlatformExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
// load configuration | ||
|
||
$configuration = new Configuration(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
|
||
// load our services | ||
|
||
$loader = new PhpFileLoader( | ||
$container, | ||
new FileLocator(__DIR__ . '/../../config') | ||
); | ||
$loader->load('services.php'); | ||
|
||
// load debug services | ||
|
||
$debug = (bool) $container->getParameter('kernel.debug'); | ||
|
||
if ($debug) { | ||
$loader->load('debug.php'); | ||
} | ||
|
||
// load services from symfony-bridge package | ||
|
||
RekapagerSymfonyBridge::loadServices($container); | ||
|
||
// process config | ||
$enableOrmSupportByDefault = $config['enable_orm_support_by_default'] ?? false; | ||
if (!\is_bool($enableOrmSupportByDefault)) { | ||
throw new \InvalidArgumentException('The "enable_orm_support_by_default" option must be a boolean.'); | ||
} | ||
|
||
$container->setParameter( | ||
'rekalogika.rekapager.api_platform.enable_orm_support_by_default', | ||
$enableOrmSupportByDefault | ||
); | ||
} | ||
} |
Oops, something went wrong.