soluti / data-filter-bundle
提供数据过滤常见接口的包
该软件包的规范仓库似乎已丢失,因此软件包已被冻结。
v1.2.3
2020-07-28 09:42 UTC
Requires
- php: >=7.1.0
- symfony/framework-bundle: ~2.8|~3.0|~4.0|~5.0
Requires (Dev)
- doctrine/mongodb-odm: ^2.1
- doctrine/orm: ^2.5
- league/fractal: 0.*
- phpunit/phpunit: ^6.2
Suggests
- doctrine/orm: In order to filter via Doctrine ORM.
- league/fractal: For using API transformers
- soluti/mongo-bundle: In order to filter on a MongoDB database.
README
数据过滤和分页变得简单。
实现基于
- 支持输入过滤器格式适配器。包含2个默认实现(DataTables和Api)
- 输出格式(DataTables,Api,原始)的格式化器
- 底层数据库(MongoDB和Doctrine ORM)的适配器
可以根据需要扩展每个方面,通过替换实现或实现接口。
安装
在您的composer.json中要求安装soluti/data-filter-bundle
包,并更新您的依赖关系。
$ composer require soluti/data-filter-bundle
将SolutiDataFilterBundle添加到您的应用程序内核
public function registerBundles()
{
$bundles = array(
// ...
new Soluti\DataFilterBundle\SolutiDataFilterBundle(),
// ...
);
// ...
}
创建您的第一个过滤器
该软件包包含2个预定义的输入适配器
- DataTables适配器(
Soluti\DataFilterBundle\Adapter\DataTableAdapter
):用于解析来自DataTables的请求 - Api适配器(
Soluti\DataFilterBundle\Adapter\ApiAdapter
):用于Api请求
为了使其工作,我们首先需要进行一些设置。需要以下3个东西
- 过滤器定义
- 转换器
- 存储库服务
每个过滤器定义都实现了Soluti\DataFilterBundle\Definition\FilterDefinitionInterface
,您也可以使用
* the repository service that implements `Soluti\DataFilterBundle\Repository\FilterableRepositoryInterface` there are 2 default implementations:
* `Soluti\DataFilterBundle\Repository\DoctrineORMRepository`
* `Soluti\DataFilterBundle\Repository\MongoRepository`
* the transformer that implements ```Soluti\DataFilterBundle\Transformer\TransformerInterface```, normally you should extend:
* for Api ```Soluti\DataFilterBundle\Transformer\ApiAbstractTransformer```
* for DataTables ```Soluti\DataFilterBundle\Transformer\AbstractTransformer```
Normally both the transformer and the Filter Definition should be registered as services inside the app.
After that inside the controller it is as simple as:
```php
use Soluti\DataFilterBundle\Adapter\DataTableAdapter;
use App\Filter\Definition\UserDefinition;
...
return new JsonResponse(
$this
->get(DataTableAdapter::class)
->process($this->get(UserDefinition::class), $request)
);
...
```
**Hint:** you can inject your services as method parameters instead of getting them from the Controller.
Please check the following files for examples:
[Definition example](doc/example_definition.md)
[Transformer example](doc/example_transformers.md)
## License
This package is available under the [MIT license](LICENSE).