digitalcharacter/filter-collection

simple filter collection

1.0.0 2018-03-28 11:11 UTC

This package is not auto-updated.

Last update: 2024-11-10 06:28:14 UTC


README

Build Status PHP from Packagist Scrutinizer Code Quality Code Coverage Packagist

FilterCollection

Simple nested Filter Collection

Composer Install

composer require dc/FilterCollection@stable
{
    "require": {
        "dc/FilterCollection": "@stable"
    }
}

Usage

Change Logical Collection

<?php
use dc\Filter\Collection;

$collection = new Collection(Collection::LOGICAL_AND);
$collection = new Collection(Collection::LOGICAL_OR);
$collection = new Collection(Collection::LOGICAL_XAND);
$collection = new Collection(Collection::LOGICAL_XOR);

Add Parent Collection

<?php
use dc\Filter\Collection;

$parent = new Collection();
$child = new Collection(Collection::LOGICAL_AND, $parent);

Available Filter

<?php
use dc\Filter\Collection;

$collection = new Collection();

//Equal
$collection->addEqual('key', 'value');

//Not Equal
$collection->addNotEqual('key', 'value');

//Exists
$collection->addExists('key', true);

//Greater Than
$collection->addGreaterThan('key', 1);

//Greater Than Equal
$collection->addGreaterThanEqual('key', 1);

//Lower Than
$collection->addLowerThan('key', 1);

//Lower Than Equal
$collection->addLowerThanEqual('key', 1);

//In 
$collection->addIn('key', [1,2,3]);

//Not In 
$collection->addNotIn('key', [1,2,3]);

//Query
$collection->addQuery('key', '%value%');

//Regex
$collection->addRegex('key', '/value/');

//Custom Filter
$collection->addCustomFilter('key', 'value', 'find_in_set');

Example

<?php 
use dc\Filter\Collection;

$collection = new Collection();
$collection->addEqual('user', 'user@example.com')
    ->addEqual('active', 1)
    ->addCollection(Collection::LOGICAL_OR)
        ->addEqual('role', 'admin')
        ->addEqual('role', 'superadmin')
        ->parent()
    ->addCollection(Collection::LOGICAL_XAND)
        ->addEqual('foo', 'bar');