gustavosantos/base-pagination-filters

此包已被弃用,不再维护。未建议替代包。

BasePaginationFilters 是一个简单的分页和过滤实现,用于与服务和存储库连接。

v1.0.4 2020-01-27 13:21 UTC

This package is auto-updated.

Last update: 2021-02-04 15:28:57 UTC


README

License Minimum PHP Version

安装

执行以下命令

composer require gustavosantos/base-pagination-filters

实现

  • 过滤

    要使用过滤,只需在 filters 数组中指定实体中存在的/映射的列。

    在 URL 中传递 querystring

    ?filters[]=id:123&filters[]=name:Gustavo

  • 分页

    要使用分页,只需指定 limitoffset

    在 URL 中传递 querystring

    ?limit=100&offset=0

    然后连接到您的服务或存储库

       /**
         * @param BasePaginationInterface $pagination
         * @return array
         * @throws ProductDatabaseException
         */
        public function findAllProducts(BasePaginationInterface $pagination): array
        {
            try {
                return $this->findBy(
                    $pagination->getFilters(), $pagination->getOrderBy(),
                    $pagination->getLimit(), $pagination->getOffSet());
            } catch (ORMException $e) {
                throw new ProductDatabaseException(StatusHttp::INTERNAL_SERVER_ERROR,
                    ErrorMessage::ERROR_QUERY_ALL_RECORD, $e->getMessage());
            } catch (Exception $e) {
                throw new ProductDatabaseException(StatusHttp::INTERNAL_SERVER_ERROR,
                    ErrorMessage::ERROR_QUERY_ALL_RECORD, $e->getMessage());
            }
        }

    通过传递参数调用方法

    $this->productRepository->findAllProducts($this->basePagination->addPagination($queryParams));