예제 #1
0
 /**
  * @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);
     }
     // trigger event for manipulating $where
     $providerEvent = new Event(Event::EVENT_QUERYBUILDER, $queryBuilder, array('entityClass' => $entityClass));
     $providerEvent->setEntityManager($this->getObjectManager());
     $this->getEventManager()->trigger($providerEvent);
     return $queryBuilder;
 }
예제 #2
0
 /**
  * @depends testRouteMatchIsMutable
  */
 public function testRouteMatchIsNullable(ResourceEvent $event)
 {
     $event->setRouteMatch(null);
     $this->assertNull($event->getRouteMatch());
 }
 /**
  * @param ResourceEvent $event
  * @return array
  */
 protected function getRouteParams(ResourceEvent $event)
 {
     $params = $event->getRouteMatch()->getParams();
     unset($params['controller']);
     return $params;
 }