tourze / json-rpc-paginator-bundle
JsonRPC分页实现
Installs: 1 262
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- knplabs/knp-components: ^4.4 || ^5.0
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/json-rpc-core: ^0.0.6
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-05-14 08:47:52 UTC
README
This bundle provides a simple JsonRPC pagination implementation that integrates with Symfony projects. It depends on KnpPaginatorBundle to handle the underlying pagination functionality.
Installation
composer require tourze/json-rpc-paginator-bundle
Features
- Supports Doctrine ORM query pagination
- Supports query result formatting
- Supports custom count callbacks
- Provides empty list structure generation
Basic Usage
Use the PaginatorTrait in your JsonRPC procedure class:
<?php namespace App\JsonRPC; use Doctrine\ORM\QueryBuilder; use Tourze\JsonRPCPaginatorBundle\Procedure\PaginatorTrait; use Tourze\JsonRPC\Core\Attribute\JsonRPCMethod; use Tourze\JsonRPC\Core\Attribute\MethodParam; class UserProcedure { use PaginatorTrait; #[JsonRPCMethod('user.list')] #[MethodParam('keyword')] public string $keyword = ''; public function execute(): array { $qb = $this->createQueryBuilder() ->select('u') ->from('App:User', 'u'); if ($this->keyword) { $qb->andWhere('u.name LIKE :keyword') ->setParameter('keyword', '%' . $this->keyword . '%'); } return $this->fetchList($qb, function ($user) { return [ 'id' => $user->getId(), 'name' => $user->getName(), 'email' => $user->getEmail(), // Other fields... ]; }); } // Optional: Override default page size protected function getDefaultPageSize(int $prevValue): int { return 20; // Custom default page size } }
Return Data Structure
{ "list": [ { "id": 1, "name": "User 1", "email": "user1@example.com" }, { "id": 2, "name": "User 2", "email": "user2@example.com" } ], "pagination": { "current": 1, "pageSize": 20, "total": 42, "hasMore": true } }
License
MIT