[ create a new paste ] login | about

Project: fedecarg
Link: http://fedecarg.codepad.org/w1RXD0PR    [ raw code | output | fork ]

fedecarg - PHP, pasted on Mar 10:
<?php

/*** Doctrine **********************/

class Doctrine_ORM_EntityRepository 
{
    public function findBy(array $criteria)
    {
        return $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->loadAll($criteria);
    }
}

/*** Zf_Orm **********************/

class Zf_Orm_Repository 
{
    public function findBy() 
    {
        $args = func_get_args();
        if (isset($args[0]) && $args[0] instanceof Zf_Orm_Query) {
            return $args[0]->getConditions();
            //return $this->getDataAccessObject()->findBy($args[0]->getConditions());
        } elseif (isset($args[0]) && is_array($args[0])) {
            return $args;
            //return $this->getDataAccessObject()->findBy($args);
        }
        throw new InvalidArgumentException();
    }
}

class Zf_Orm_Query
{
    public function getConditions()
    {
        // WHERE (title = 'a' AND is_published = 1) OR (title = 'b' AND is_published = 0)
        return array(
            array('title'=>'a', 'is_published'=>1), 
            array('title'=>'b', 'is_published'=>0)
        );
    }
}

$repository = new Zf_Orm_Repository();
print_r($repository->findBy(new Zf_Orm_Query()));
print_r($repository->findBy(
    array('title'=>'a', /* AND */ 'is_published'=>1), /* OR */
    array('title'=>'b', /* AND */ 'is_published'=>0)
));


Output:
Array
(
    [0] => Array
        (
            [title] => a
            [is_published] => 1
        )

    [1] => Array
        (
            [title] => b
            [is_published] => 0
        )

)
Array
(
    [0] => Array
        (
            [title] => a
            [is_published] => 1
        )

    [1] => Array
        (
            [title] => b
            [is_published] => 0
        )

)


Create a new paste based on this one


Comments: