phprest/phprest-service-request-filter
Composer 安装命令:
composer require phprest/phprest-service-request-filter
包简介
Phprest Request Filter Service.
README 文档
README
Description
Request Filter Service which is able to filter your incoming request by:
- query
- sort
- limit
- offset
Components
There are 3 main component in filtering:
- Obtainer
- Parser
- Processor
Obtainer
Is the way as you get the filtering key and its data from the request.
E.g.: QueryInHeader Obtainer
Parser
Is the way how you analyze the obtained filter.
E.g.: CommaMinus Parser
Processor
Which is processing your parsed filter.
E.g.: Orm Processor
Installation
Install it through composer.
{
"require": {
"phprest/phprest-service-request-filter": "@stable"
}
}
tip: you should browse the phprest/phprest-service-request-filter
page to choose a stable version to use, avoid the @stable meta constraint.
Usage
Configuration
For the configuration you should check the Config class.
Registration
<?php use Phprest\Service\RequestFilter; # ... /** @var \Phprest\Application $app */ $app->registerService(new RequestFilter\Service(), new RequestFilter\Config()); # ...
Reaching from a Controller
To reach your Service from a Controller you should use the Service's Getter Trait.
<?php namespace App\Module\Controller; use Phprest\Service; class Index extends \Phprest\Util\Controller { use Service\RequestFilter\Getter; public function get(Request $request) { $this->serviceRequestFilter()->processQuery(...); } }
Utils
Most of the Services in Phprest provides some utility mechanism (helper functions).
For the utilities you should check the Util class.
Example
With the Orm Processor.
<?php namespace App\Module\Controller; use Phprest\Service; use Doctrine\Common\Collections\Criteria; class Index extends \Phprest\Util\Controller { use Service\RequestFilter\Getter; use Service\RequestFilter\Util; public function getAll(Request $request) { $processor = new Service\RequestFilter\Processor\Orm(Criteria::create()); try { $this->serviceRequestFilter()->processQuery($request, $processor); $this->serviceRequestFilter()->processSort($request, $processor); } catch (\Exception $e) { throw new Exception\BadRequest(0, [$e->getMessage()]); } } }
统计信息
- 总下载量: 880
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 3
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-11