Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bipiane/criteria-builder

Doctrine Criteria Builder from HTTP parameters in PHP
https://github.com/bipiane/criteria-builder

doctrine-orm query-builder query-params restful-api symfony

Last synced: 7 days ago
JSON representation

Doctrine Criteria Builder from HTTP parameters in PHP

Awesome Lists containing this project

README

        

[![Latest Stable Version](https://poser.pugx.org/bipiane/criteria-builder/v/stable)](https://packagist.org/packages/bipiane/criteria-builder)
[![Total Downloads](https://poser.pugx.org/bipiane/criteria-builder/downloads)](https://packagist.org/packages/bipiane/criteria-builder)
[![License](https://poser.pugx.org/bipiane/criteria-builder/license)](https://packagist.org/packages/bipiane/criteria-builder)

Doctrine Criteria Builder from HTTP parameters in PHP
------------

Installation
------------

```bash
composer require bipiane/criteria-builder
```

Example
------------

```php
CriteriaDoctrine::CRITERIAS_NUMBER,
'name' => CriteriaDoctrine::CRITERIAS_STRING,
'lastname' => CriteriaDoctrine::CRITERIAS_STRING,
'city' => [
'id' => CriteriaDoctrine::CRITERIAS_NUMBER,
'name' => CriteriaDoctrine::CRITERIAS_STRING,
'state' => [
'id' => CriteriaDoctrine::CRITERIAS_NUMBER,
'name' => CriteriaDoctrine::CRITERIAS_STRING,
'code' => CriteriaDoctrine::CRITERIAS_STRING,
'country' => [
'id' => CriteriaDoctrine::CRITERIAS_NUMBER,
'name' => CriteriaDoctrine::CRITERIAS_STRING,
'enabled' => CriteriaDoctrine::CRITERIAS_BOOLEAN,
],
'enabled' => CriteriaDoctrine::CRITERIAS_BOOLEAN,
],
'enabled' => CriteriaDoctrine::CRITERIAS_BOOLEAN,
],
'enabled' => CriteriaDoctrine::CRITERIAS_BOOLEAN,
];

try {
$qb = $this->getDoctrine()->getManager()
->getRepository('ModelBundle:User')
->createQueryBuilder('usr');

$qb = CriteriaBuilder::fetchFromQuery(
$qb,
$request->query->all(),
$criteriaUser
);

var_dump($qb->getQuery()->getArrayResult());
} catch (CriteriaException $e) {
}
// ...
}
```

Testing
------------

```
./vendor/bin/simple-phpunit
```