bartlomiejbeta/filter-sorter-bundle
Composer 安装命令:
composer require bartlomiejbeta/filter-sorter-bundle
包简介
README 文档
README
This Symfony bundle aims to provide structurized filtering and sorting with usage of the specification pattern (see doctrine-specification). It was design to use in the api applications but it could be also used with standard web apps.
Provides feature like:
FilterQueryManager- it collects allfilter servicesand gives you queryBuilder with applied specifications.FilterParamConverter- providefilter objectby the data in query stringSortParamConverter- providesort objectby the data in query string
Installation
1. Install via composer:
composer require bartlomiejbeta/filter-sorter-bundle
2. Register bundle in AppKernel:
public function registerBundles() { $bundles = array( // ... new BartB\FilterSorterBundle\FilterSorterBundle(), ); }
Usage
I assume that you already have entities, and so one.
1. Change parent of the entities to AbstractEntitySpecificationAwareRepository:
example:
class CarRepository extends AbstractEntitySpecificationAwareRepository { }
2. Add specifications (example)
3. Add Collection filter (example)
4. Add Sort Enum (example)
5. Build and register your first service adapter (adapter example, register adapter example)
5. Run (standard, api with paramConverters)
$carCollectionFilter = (new CarCollectionFilter())->setGearboxType('automatic'); $carSorter = new CarSort(CarSort::FUEL_TYPE); $sortDirection = new SortDirectionType(SortDirectionType::DESC); /** @var FilterQueryManager $filterQueryManager */ $filterQueryManager = $this->filterQueryManager; $carRepository = $this->repostioryCar; $sort = new Sort($sortDirection, $carSorter); $limit = new Limit(1); $basicRepositoryDTO = new BasicRepositoryDTO($carRepository); $queryAttributesDTO = new QueryAttributesDTO($carCollectionFilter, $sort, $limit); $queryBuilder = $filterQueryManager->getQueryBuilder($basicRepositoryDTO, $queryAttributesDTO); $query = $queryBuilder->getQuery(); $result = $query->execute();
TODO: Upgrade example to symfony 3.4 Also I prepared full stand alone example
统计信息
- 总下载量: 756
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-09-01