Skip to content

Commit

Permalink
Merge pull request #753 from Matth--/fix/generics
Browse files Browse the repository at this point in the history
Implement/Extend Paginator generics
  • Loading branch information
garak authored Jan 16, 2023
2 parents 813c1b2 + a825bc5 commit 15e5af1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 34 deletions.
24 changes: 12 additions & 12 deletions src/Helper/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public function __construct(UrlGeneratorInterface $router, TranslatorInterface $
/**
* Generates pagination template data.
*
* @param SlidingPaginationInterface<mixed> $pagination
* @param array<string, mixed> $queryParams
* @param array<string, mixed> $viewParams
* @param SlidingPaginationInterface<mixed, mixed> $pagination
* @param array<string, mixed> $queryParams
* @param array<string, mixed> $viewParams
*
* @return array<string, mixed>
*/
Expand All @@ -57,11 +57,11 @@ public function render(SlidingPaginationInterface $pagination, array $queryParam
*
* $key examples: "article.title" or "['article.title', 'article.subtitle']"
*
* @param SlidingPaginationInterface<mixed> $pagination
* @param string|array<string, mixed> $title
* @param string|array<string, mixed> $key
* @param array<string, mixed> $options
* @param array<string, mixed> $params
* @param SlidingPaginationInterface<mixed, mixed> $pagination
* @param string|array<string, mixed> $title
* @param string|array<string, mixed> $key
* @param array<string, mixed> $options
* @param array<string, mixed> $params
*
* @return array<string, mixed>
*/
Expand Down Expand Up @@ -156,10 +156,10 @@ public function sortable(SlidingPaginationInterface $pagination, $title, $key, a
*
* $key example: "article.title"
*
* @param SlidingPaginationInterface<mixed> $pagination
* @param array<string, mixed> $fields
* @param array<string, mixed> $options
* @param array<string, mixed> $params
* @param SlidingPaginationInterface<mixed, mixed> $pagination
* @param array<string, mixed> $fields
* @param array<string, mixed> $options
* @param array<string, mixed> $params
*
* @return array<string, mixed>
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Pagination/SlidingPagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

use Knp\Component\Pager\Pagination\AbstractPagination;

/**
* @template TKey
* @template TValue
*
* @template-extends AbstractPagination<TKey, TValue>
*
* @template-implements SlidingPaginationInterface<TKey, TValue>
*/
final class SlidingPagination extends AbstractPagination implements SlidingPaginationInterface
{
private ?string $route = null;
Expand Down
6 changes: 6 additions & 0 deletions src/Pagination/SlidingPaginationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

use Knp\Component\Pager\Pagination\PaginationInterface;

/**
* @template TKey
* @template TValue
*
* @template-extends PaginationInterface<TKey, TValue>
*/
interface SlidingPaginationInterface extends PaginationInterface
{
public function getRoute(): ?string;
Expand Down
22 changes: 11 additions & 11 deletions src/Templating/PaginationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public function __construct(Processor $processor, PhpEngine $templating)
/**
* Renders the pagination template.
*
* @param \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination<mixed> $pagination
* @param array<string, mixed> $queryParams
* @param array<string, mixed> $viewParams
* @param \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination<mixed, mixed> $pagination
* @param array<string, mixed> $queryParams
* @param array<string, mixed> $viewParams
*/
public function render(SlidingPaginationInterface $pagination, ?string $template = null, array $queryParams = [], array $viewParams = []): string
{
Expand All @@ -49,10 +49,10 @@ public function render(SlidingPaginationInterface $pagination, ?string $template
*
* $key example: "article.title"
*
* @param \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination<mixed> $pagination
* @param string|array<string, mixed> $key
* @param array<string, mixed> $options
* @param array<string, mixed> $params
* @param \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination<mixed, mixed> $pagination
* @param string|array<string, mixed> $key
* @param array<string, mixed> $options
* @param array<string, mixed> $params
*/
public function sortable(SlidingPaginationInterface $pagination, string $title, $key, array $options = [], array $params = [], ?string $template = null): string
{
Expand All @@ -70,10 +70,10 @@ public function sortable(SlidingPaginationInterface $pagination, string $title,
*
* $key example: "article.title"
*
* @param \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination<mixed> $pagination
* @param array<string, mixed> $fields
* @param array<string, mixed> $options
* @param array<string, mixed> $params
* @param \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination<mixed, mixed> $pagination
* @param array<string, mixed> $fields
* @param array<string, mixed> $options
* @param array<string, mixed> $params
*/
public function filter(SlidingPaginationInterface $pagination, array $fields, array $options = [], array $params = [], ?string $template = null): string
{
Expand Down
22 changes: 11 additions & 11 deletions src/Twig/Extension/PaginationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public function getFunctions(): array
/**
* Renders the pagination template.
*
* @param \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination<mixed> $pagination
* @param array<string, mixed> $queryParams
* @param array<string, mixed> $viewParams
* @param \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination<mixed, mixed> $pagination
* @param array<string, mixed> $queryParams
* @param array<string, mixed> $viewParams
*/
public function render(Environment $env, SlidingPaginationInterface $pagination, ?string $template = null, ?array $queryParams = [], ?array $viewParams = []): string
{
Expand All @@ -49,10 +49,10 @@ public function render(Environment $env, SlidingPaginationInterface $pagination,
*
* $key example: "article.title"
*
* @param \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination<mixed> $pagination
* @param string|array<string, mixed> $key
* @param array<string, mixed> $options
* @param array<string, mixed> $params
* @param \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination<mixed, mixed> $pagination
* @param string|array<string, mixed> $key
* @param array<string, mixed> $options
* @param array<string, mixed> $params
*/
public function sortable(Environment $env, SlidingPaginationInterface $pagination, string $title, $key, array $options = [], array $params = [], ?string $template = null): string
{
Expand All @@ -70,10 +70,10 @@ public function sortable(Environment $env, SlidingPaginationInterface $paginatio
*
* $key example: "article.title"
*
* @param \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination<mixed> $pagination
* @param array<string, mixed> $fields
* @param array<string, mixed> $options
* @param array<string, mixed>|null $params
* @param \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination<mixed, mixed> $pagination
* @param array<string, mixed> $fields
* @param array<string, mixed> $options
* @param array<string, mixed>|null $params
*/
public function filter(Environment $env, SlidingPaginationInterface $pagination, array $fields, ?array $options = [], ?array $params = [], ?string $template = null): string
{
Expand Down

0 comments on commit 15e5af1

Please sign in to comment.