Use Doctrine Collections expressions with Zend\Db\Sql for smart criteria / filtering / query building.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test/RoaveTest/DbCriteria
.gitignore
.scrutinizer.yml
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml.dist

README.md

RoaveDbCriteria

Build Status Scrutinizer Code Quality Code Coverage

v0.0.1

Example Usage

<?php
use Roave\DbCriteria\QueryExpressionVisitor;
use Doctrine\Common\Collections\Criteria;

class ContactMapper
{
    protected $visitor;
    protected $tableGateway;

    public function find(Criteria $citeria)
    {
        $select = $this->tableGateway->getSql()->select()
                       // You can apply your own Zend\Db\Sql query conditions
                       ->where(array('user_id' => $this->activeUser->id));

        // Then apply the criteria to the query
        $where  = $this->visitor->dispatch($criteria->getWhereExpression());
        $select->where($where);

        // Finally, apply limit, offset, order, and execute the select query
        QueryExpressionVisitor::apply($select, $criteria);

        return $this->tableGateway->selectWith($select);
    }
}
<?php
use Doctrine\Common\Collections\Criteria;

$criteria = Criteria::create()
                ->where(Criteria::expr()->eq('first_name', 'Evan'))
                ->andWhere(Criteria::expr()->eq('last_name', 'Coury'));

$contacts = $contactMapper->find($criteria);

In practice, you can create domain-specific criteria objects and plenty of other cool things.