<commit_before><?php
namespace ZucchiDoctrine\Query\Provider;

use Doctrine\ORM\QueryBuilder;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerAwareTrait;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use ZF\Apigility\Doctrine\Server\Query\Provider\DefaultOrm as ApiDoctrineDefaultOrm;
use ZF\Rest\ResourceEvent;
use Zucchi\Controller\RequestParserTrait;
use Zucchi\Event\EventProviderTrait;
use ZucchiDoctrine\Query\QueryBuilderTrait;

/**
 * Class DefaultOrm
 * @package ZucchiDoctrine\Query\Provider
 */
class DefaultOrm extends ApiDoctrineDefaultOrm implements EventManagerAwareInterface
{
    use ServiceLocatorAwareTrait;
    use RequestParserTrait;
    use QueryBuilderTrait;
    use EventProviderTrait;

    /**
     * @param string $entityClass
     * @param array  $parameters
     *
     * @return mixed This will return an ORM or ODM Query\Builder
     */
    public function createQuery(ResourceEvent $event, $entityClass, $parameters)
    {
        $queryBuilder = $this->getObjectManager()->createQueryBuilder();
        $queryBuilder->select('e')
            ->from($entityClass, 'e');

		$routeParams = $event->getRouteMatch()->getParams();

        $where = $event->getQueryParam('where', []);

        if (is_array($where)) {
            $where = array_merge($where, $routeParams);
            unset($where['controller'], $where['version'], $where['action']);
        }

        // trigger event for manipulating $where
        $providerEvent = new Event(Event::EVENT_WHERE, $where, array('entityClass' => $entityClass));
        $providerEvent->setEntityManager($this->getObjectManager());
        $this->getEventManager()->trigger($providerEvent);
        $where = $providerEvent->getTarget();

		if ($where) {
            $where = $this->parseWhere($where);
            $this->addWhere($queryBuilder, $where);
        }

        // trigger event for manipulating $order
        $order = $event->getQueryParam('order', false);
        $providerEvent = new Event(Event::EVENT_ORDER, $order, array('entityClass' => $entityClass));
        $providerEvent->setEntityManager($this->getObjectManager());
        $this->getEventManager()->trigger($providerEvent);
        $order = $providerEvent->getTarget();

        if ($order) {
            $this->addOrder($queryBuilder, $order);
        }

        // trigger event for manipulating $limit
        $limit = $event->getQueryParam('limit', false);
        $providerEvent = new Event(Event::EVENT_LIMIT, $limit, array('entityClass' => $entityClass));
        $providerEvent->setEntityManager($this->getObjectManager());
        $this->getEventManager()->trigger($providerEvent);
        $limit = $providerEvent->getTarget();

        if ($limit) {
            $this->addLimit($queryBuilder, $limit);
        }

        return $queryBuilder;
    }

}<commit_msg>Update DefaultOrm.php<commit_after><?php
namespace ZucchiDoctrine\Query\Provider;

use Doctrine\ORM\QueryBuilder;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerAwareTrait;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use ZF\Apigility\Doctrine\Server\Query\Provider\DefaultOrm as ApiDoctrineDefaultOrm;
use ZF\Rest\ResourceEvent;
use Zucchi\Controller\RequestParserTrait;
use Zucchi\Event\EventProviderTrait;
use ZucchiDoctrine\Query\QueryBuilderTrait;

/**
 * Class DefaultOrm
 * @package ZucchiDoctrine\Query\Provider
 */
class DefaultOrm extends ApiDoctrineDefaultOrm implements EventManagerAwareInterface
{
    use ServiceLocatorAwareTrait;
    use RequestParserTrait;
    use QueryBuilderTrait;
    use EventProviderTrait;

    protected $entityAlias = 'row';

    /**
     * @param string $entityClass
     * @param array  $parameters
     *
     * @return mixed This will return an ORM or ODM Query\Builder
     */
    public function createQuery(ResourceEvent $event, $entityClass, $parameters)
    {
        $queryBuilder = $this->getObjectManager()->createQueryBuilder();
        $queryBuilder->select($this->entityAlias)
            ->from($entityClass, $this->entityAlias);

		$routeParams = $event->getRouteMatch()->getParams();

        $where = $event->getQueryParam('where', []);

        if (is_array($where)) {
            $where = array_merge($where, $routeParams);
            unset($where['controller'], $where['version'], $where['action']);
        }

        // trigger event for manipulating $where
        $providerEvent = new Event(Event::EVENT_WHERE, $where, array('entityClass' => $entityClass));
        $providerEvent->setEntityManager($this->getObjectManager());
        $this->getEventManager()->trigger($providerEvent);
        $where = $providerEvent->getTarget();

		if ($where) {
            $where = $this->parseWhere($where);
            $this->addWhere($queryBuilder, $where);
        }

        // trigger event for manipulating $order
        $order = $event->getQueryParam('order', false);
        $providerEvent = new Event(Event::EVENT_ORDER, $order, array('entityClass' => $entityClass));
        $providerEvent->setEntityManager($this->getObjectManager());
        $this->getEventManager()->trigger($providerEvent);
        $order = $providerEvent->getTarget();

        if ($order) {
            $this->addOrder($queryBuilder, $order);
        }

        // trigger event for manipulating $limit
        $limit = $event->getQueryParam('limit', false);
        $providerEvent = new Event(Event::EVENT_LIMIT, $limit, array('entityClass' => $entityClass));
        $providerEvent->setEntityManager($this->getObjectManager());
        $this->getEventManager()->trigger($providerEvent);
        $limit = $providerEvent->getTarget();

        if ($limit) {
            $this->addLimit($queryBuilder, $limit);
        }

        return $queryBuilder;
    }

}

{'fraction_non_alphanumeric': 0.13636363636363635, 'fraction_numerical': 0.0, 'mean_word_length': 3.4857142857142858, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6338511', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1599, 'n_words': 298}