Beispiel #1
0
 /**
  * Executes the query and returns the result based on the hydration mode.
  *
  * @param array $parameters    Parameters, alternative to calling setParameters.
  * @param int   $hydrationMode Processing mode to be used during the hydration
  *                             process. One of the Query::HYDRATE_* constants.
  *
  * @return mixed A Collection for HYDRATE_DOCUMENT, \PHPCR\Query\QueryResultInterface for HYDRATE_PHPCR
  *
  * @throws QueryException If $hydrationMode is not known.
  */
 public function execute($parameters = null, $hydrationMode = null)
 {
     if (!empty($parameters)) {
         $this->setParameters($parameters);
     }
     if (null !== $hydrationMode) {
         $this->setHydrationMode($hydrationMode);
     }
     if (null !== $this->maxResults) {
         $this->query->setLimit($this->maxResults);
     }
     if (null !== $this->firstResult) {
         $this->query->setOffset($this->firstResult);
     }
     foreach ($this->parameters as $key => $value) {
         $this->query->bindValue($key, $value);
     }
     switch ($this->hydrationMode) {
         case self::HYDRATE_PHPCR:
             $data = $this->query->execute();
             break;
         case self::HYDRATE_DOCUMENT:
             $data = $this->dm->getDocumentsByPhpcrQuery($this->query, $this->documentClass, $this->primaryAlias);
             break;
         default:
             throw QueryException::hydrationModeNotKnown($this->hydrationMode);
     }
     if (is_array($data)) {
         $data = new ArrayCollection($data);
     }
     return $data;
 }
Beispiel #2
0
 /**
  * @param array $parameters
  * @param string $hydrationMode
  *
  * @return mixed|\PHPCR\Query\QueryResultInterface
  *
  * @throws DocumentManagerException
  */
 public function execute(array $parameters = [], $hydrationMode = self::HYDRATE_DOCUMENT)
 {
     if (null !== $this->maxResults) {
         $this->phpcrQuery->setLimit($this->maxResults);
     }
     if (null !== $this->firstResult) {
         $this->phpcrQuery->setOffset($this->firstResult);
     }
     foreach ($parameters as $key => $value) {
         $this->phpcrQuery->bindValue($key, $value);
     }
     if ($hydrationMode === self::HYDRATE_PHPCR) {
         return $this->phpcrQuery->execute();
     }
     if ($hydrationMode !== self::HYDRATE_DOCUMENT) {
         throw new DocumentManagerException(sprintf('Unknown hydration mode "%s", should be either "document" or "phpcr_node"', $hydrationMode));
     }
     $event = new QueryExecuteEvent($this, $this->options);
     $this->dispatcher->dispatch(Events::QUERY_EXECUTE, $event);
     return $event->getResult();
 }