src/App/Doctrine/Repository/SearchableRepositoryTrait.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Doctrine\Repository;
  3. use App\Model\Searching\AbstractSearch;
  4. use App\Util\Pagination;
  5. use Doctrine\ORM\QueryBuilder;
  6. use Doctrine\ORM\Tools\Pagination\Paginator;
  7. /**
  8.  * Basic implementation of the SearchableRepositoryInterface.
  9.  */
  10. trait SearchableRepositoryTrait
  11. {
  12.     /**
  13.      * {@inheritDoc}
  14.      */
  15.     public function findBySearch(
  16.         AbstractSearch $search,
  17.         ?int $limit null,
  18.         ?int $offset null,
  19.         ?QueryBuilder $qb null
  20.     ): Paginator
  21.     {
  22.         // force interface
  23.         if (!$this instanceof SearchableRepositoryInterface) {
  24.             throw new \RuntimeException();
  25.         }
  26.         // default limit and offset
  27.         if (!$limit) {
  28.             $limit $search->getLimit() ?: Pagination::PAGE_LIMIT;
  29.         }
  30.         if (!$offset) {
  31.             $offset $search->getOffset() ?: 0;
  32.         }
  33.         // creat the raw query builder
  34.         $qb $this->qbBySearch(
  35.             $search,
  36.             $qb,
  37.         );
  38.         return Pagination::paginateThenQuery(
  39.             $qb,
  40.             $limit,
  41.             $offset,
  42.         );
  43.     }
  44. }