Skip to content

phprest/phprest-service-request-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phprest Request Filter Service

Author Software License

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()]);
        }
    }
}

About

Phprest Request Filter Service.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages