2017 © Pedro Peláez
 

library domains

PHP DSL for quering between app and business layers.

image

taco/domains

PHP DSL for quering between app and business layers.

  • Saturday, May 19, 2018
  • by tacoberu
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Criteria

Build Status, (*1)

PHP DSL for quering between app and business layers., (*2)

Inspirated by SQL, LINQ, or Dibi. Used for quering to database, file, filesystem, xml, anything., (*3)

  • with - o jaká data máme zájem.
  • where - podmínka, který musí být splněna na požadovaných datech.
  • limit - kolik toho chceme,
  • offset - posunutí okna
  • orderByDesc, orderByAsc - seřazení výsledků.

Example

Příklad dotazu na soubor - dvacet souborů menších jak 400B včetně obsahu a informace o souboru:, (*4)

Criteria::range('IO/File', 20)
    ->with('fileInfo')
    ->with('content')
    ->where('fileInfo.size <', 400);


Criteria::range('Article', 20)
    ->with('fileInfo')
    ->with('content')
    ->where('fileInfo.size <', 400)
    ->orderByDesc('fileInfo.size');


Criteria::count('Article')
    ->with('fileInfo')
    ->with('content')
    ->where('fileInfo.size <', 400);


Criteria::first('Article')
    ->with('fileInfo')
    ->with('content')
    ->where('fileInfo.size <', 400);



$f = (new Filter('Album'))
    ->where('created <', new DateTime())
    ->where('author.name LIKE', 'Sinead%');
$f = Parser::parseFilter('Album WHERE created < ? AND name LIKE ?', new DateTime(), 'Sinead%');
$repository->range($f);

function range(Filterable $filter = Null, Sortable $sort = Null, $limit = Null, $offset = Null)
{

    (new Validation($schema))->assertFilter($filter);
    $con = $this->dibi;

    foreach ($filter as $name as $args) {
        switch($name) {
            'author':
                $con->leftJoin(...);
                break;
        }
    }
    foreach ($filter as $name as $args) {
        if ($args instanceof Cond) {
            ...
        }
        else {
            switch($name) {
                'author.name':
                    $con->where('b.name = ?', $args);
                    break;
                default:
                    $con->where("a.{$name} = ?", $args);
            }
        }
    }
}

Pseudocode:, (*5)

-- Posledních pět článků konkrétního uživatele.
article[user.id = 42|limit 5]{*}

-- Všechny kočky, mající více jak 2 černé koťata. Přičemž nás zajímá celkový počet koček, jméno kočky, a barva kočky.
cats[children[color = black]{count} > 2]{children.count, name, color}

-- Patnáct uživatelů z mariánek. U každého chceme krom základních atributů také ulici a město z adresy.
-- Dále chceme pro každého pět (povolených) posledních článků. Z každého článku chceme jen jméno a popis.
users[address.city = "marianky"|limit 15]{*, address{street, city}, article[enabled = true|sort-desc-by date|limit 5]{name, description}}

PHP Code:, (*6)

// Posledních pět článků konkrétního uživatele.
Criteria::range('article', [
    Condition::is('user.id', 42),
    Range::limit(5)
],
['*']);

// Všechny kočky, mající více jak 2 černé koťata. Přičemž nás zajímá celkový počet koček, jméno kočky, a barva kočky.
// cats[children[color = black]{count} > 2]{children.count, name, color}
// cats[children{count} > 2]{children.count, name, color}
// [children[color = black]{count} > 2]
// [children{count} > 2]
Criteria::range('cat', [
    Condition::largerThan(
        Criteria::range('cat', []
    , 2),
],
['children.count', 'name', 'color']);


// AND
Criteria::range('article', [
    Condition::like('user.name', 'Pepa'),
    Condition::like('user.name', 'Pavel'),
],
['*']);


// OR
Criteria::range('article', new ConditionOr([
    Condition::like('user.name', 'Pepa'),
    Condition::like('user.name', 'Pavel'),
]),
['*']);

Selector

Helper for selectin attribs in criteriam, (*7)

Validator

Slouží k validaci criteria. Omezujeme tím prvky, nebo podmínky které může klient uvádět., (*8)

Formater

Překládá kriterium na jiný formát. Například pro dibi, pro Doctrine a podobně., (*9)

TODO

  • refactoring názvů
  • zanořený dotazy
  • print, deserialize tak aby to vrátilo hodnotu
  • oprava pojmenovaných argumnentů
  • validace na elementy

The Versions

19/05 2018

v0.3.x-dev

0.3.9999999.9999999-dev

PHP DSL for quering between app and business layers.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

30/11 2016

v0.1.x-dev

0.1.9999999.9999999-dev

PHP DSL for quering between app and business layers.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

30/11 2016

0.1

0.1.0.0

PHP DSL for quering between app and business layers.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

30/11 2016

v0.2.x-dev

0.2.9999999.9999999-dev

PHP DSL for quering between app and business layers.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

30/11 2016

dev-master

9999999-dev

PHP DSL for quering between app and business layers.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

30/11 2016

v0.2.0

0.2.0.0

PHP DSL for quering between app and business layers.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

02/08 2015

v0.2

0.2.0.0

PHP DSL for quering between app and business layers.

  Sources   Download

MIT

The Requires

  • php >=5.3.0