2017 © Pedro Peláez
 

library osmosis

A filtering api

image

lune/osmosis

A filtering api

  • Sunday, January 15, 2017
  • by studiowbe
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Osmosis

A fluent interface for filtering data., (*1)

Installation

The (highly) recommended way to install Osmosis is by using Composer, (*2)

composer require lune/osmosis

Operators

The following operators are available:, (*3)

equals, (*4)

inArray, (*5)

greaterThan, (*6)

greaterThanOrEqual, (*7)

lessThan, (*8)

lessThanOrEqual, (*9)

not, (*10)

notInArray, (*11)

DataSources

The following DataSources are bundled:, (*12)

ArrayDataSource

Wraps an array and filters it, (*13)

$filter = new Lune\Osmosis\Filter()
$filter
    ->equals('a', 1)
    ->greaterThan('b', 100);

$array = [
    ['a'=>1, 'b'=>20],
    ['a'=>1, 'b'=>120],
    ['a'=>3, 'b'=>120]        
];

//Convert our array to a DataSourceInterface object
$source = new Lune\Osmosis\DataSource\ArrayDataSource($array);

//Apply the filter to our datasource
$result = $filter->apply($source);

print_r((array) $result);
//[['a'=>1, 'b'=>'120']];

SQLDataSource

Creates partial sql:, (*14)

$filter = new Lune\Osmosis\Filter()
$filter->equals('ID', 1);

$source = new Lune\Osmosis\DataSource\SQLDataSource();
$result = $filter->apply($source);

//Execution example
$pdo = new \PDO(...);
$statement = $pdo->prepare("SELECT * FROM `users` WHERE {$result}");
$statement->execute($result->getVariables())->fetchAll();

Please note Osmosis is by no means a complete query builder, nor does it aim to be one., (*15)

Defining filters

To add filters, simply use the methods provided:, (*16)

$filter = new Lune\Osmosis\Filter()
$filter
    ->equals('a', 1)
    ->greaterThan('b', 100);

You can also use a callable as the constructor parameter:, (*17)

$filter = new Lune\Osmosis\Filter(function(FilterInterface $f){
        $f->equals('a', 1)->greaterThan('b', 100);
});

The Versions

15/01 2017

dev-master

9999999-dev

A filtering api

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

15/01 2017

v0.0.1

0.0.1.0

A filtering api

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires