PHP code example of biera / filter

1. Go to this page and download the library: Download biera/filter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

biera / filter example snippets


use Biera\Filter\Operator;

// all drama and biography movies released in XX century
$filterExpression = Operator::and(
    [
        Operator::lte('releaseDate', new DateTimeImmutable('2000-12-31')),
        Operator::in('genre', ['bigraphy', 'drama'])
    ]       
);

assert($filterExpression instanceof Operator);

use Biera\Filter\Operator;
use Biera\Filter\FilterExpressionBuilder;

// all biography movies which are released before 2001-01-01 or last at least 120 minutes 
$filterExpression = FilterExpressionBuilder::create()
    ->and()
        ->eq('genre', 'biography')
        ->or()
            ->lt('releaseDate', new DateTimeImmutable('2001-01-01'))
            ->gte('duration', 120)
        ->end()
    ->end()
    ->build();

assert($filterExpression instanceof Operator);
 

use Biera\Filter\Operator;
use Biera\Filter\FilterExpressionFactory;

$filterExpression = FilterExpressionFactory::createFromJson($_GET['filters']);

assert($filterExpression instanceof Operator);

use Doctrine\ORM\EntityRepository;
use Biera\Filter\Operator as FilterExpression;
use Biera\Filter\Binding\Doctrine\ORM\WhereClauseFactory;

class MovieRepository extends EntityRepository
{   
    public function findAllByFilters(FilterExpression $filters): array
    {                
        $whereClause = WhereClauseFactory::createFromFilterExpression($filters);
           
        return $this->createQueryBuilder('movie')
            ->where($whereClause)
            ->getQuery()
            ->getResult();
    }
}