Skip to content

Commit

Permalink
Merge adapter contracts and typehint paginator contract instead of im…
Browse files Browse the repository at this point in the history
…plementation
  • Loading branch information
dvdheiden committed Nov 6, 2017
1 parent 95c6c08 commit 835f211
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 72 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This package requires PHP 5.6+.

## Installation

This package can be used in any PHP project or with any framework. The packages is tested in PHP 5.6 and PHP 7.0.
This package can be used in any PHP project or with any framework. The package is tested in PHP 5.6 and PHP 7.0.

You can install the package via composer:

Expand Down Expand Up @@ -92,16 +92,6 @@ The manager can decode the filter and will return a new filter instance:
$decodedFilter = $manager->decode($encodedFilter);
```

A query builder is provided to easily query your database with the filter configuration for the illuminate query
builder:

```php
$filterAdapter = new QueryBuilder();

$queryBuilder = $filterAdapter->getFilterQuery($queryBuilder, $decodedFilter);
return $queryBuilder->get();
```

A group can be retrieved by it's name from the filter:

```php
Expand All @@ -118,6 +108,20 @@ $group->getFields('manufacturer');

Which will return an array of groups.

### Adapter

A query builder is provided to easily query your database with the filter configuration for the illuminate query
builder:

```php
$filterAdapter = new QueryBuilder();

$queryBuilder = $filterAdapter->getFilterQuery($queryBuilder, $decodedFilter);
return $queryBuilder->get();
```

You are free to implement your own adapter, as long as it implements the `FilterAdapter` contract.

## Tests

Full code coverage unit tests are available in the tests folder. Run via phpunit:
Expand Down
53 changes: 28 additions & 25 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Adapters/FilterAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Vdhicts\Dicms\Filter\Group;
use Vdhicts\Dicms\Filter\Order;
use Vdhicts\Dicms\Filter\OrderField;
use Vdhicts\Dicms\Filter\Pagination;
use Vdhicts\Dicms\Pagination\Contracts\Paginator;

class FilterAdapter implements Contracts\FilterAdapter, Contracts\OrderAdapter, Contracts\PaginationAdapter
class FilterAdapter implements Contracts\FilterAdapter
{
/**
* Returns the filter field operator.
Expand Down Expand Up @@ -122,10 +122,10 @@ public function getOrderQuery($builder, Order $order)
/**
* Returns the query builder with the pagination applied.
* @param mixed $builder
* @param Pagination $pagination
* @param Paginator $pagination
* @return mixed
*/
public function getPaginationQuery($builder, Pagination $pagination)
public function getPaginationQuery($builder, Paginator $pagination)
{
return $builder->limit($pagination->getLimit())
->offset($pagination->getOffset());
Expand Down
18 changes: 18 additions & 0 deletions src/Contracts/FilterAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Vdhicts\Dicms\Filter\Contracts;

use Vdhicts\Dicms\Filter\Filter;
use Vdhicts\Dicms\Filter\Order;
use Vdhicts\Dicms\Pagination\Contracts\Paginator;

interface FilterAdapter
{
Expand All @@ -13,4 +15,20 @@ interface FilterAdapter
* @return mixed
*/
public function getFilterQuery($builder, Filter $filter);

/**
* Returns the query builder with the order applied.
* @param mixed $builder
* @param Order $order
* @return mixed
*/
public function getOrderQuery($builder, Order $order);

/**
* Returns the query builder with the pagination applied.
* @param mixed $builder
* @param Paginator $pagination
* @return mixed
*/
public function getPaginationQuery($builder, Paginator $pagination);
}
16 changes: 0 additions & 16 deletions src/Contracts/OrderAdapter.php

This file was deleted.

16 changes: 0 additions & 16 deletions src/Contracts/PaginationAdapter.php

This file was deleted.

0 comments on commit 835f211

Please sign in to comment.