Example #1
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();
 }
 /**
  * It should handle query execution and set the result.
  */
 public function testHandleQueryExecute()
 {
     $locale = 'fr';
     $primarySelector = 'p';
     $this->query->getLocale()->willReturn($locale);
     $this->query->getPhpcrQuery()->willReturn($this->phpcrQuery->reveal());
     $this->phpcrQuery->execute()->willReturn($this->phpcrResult->reveal());
     $this->query->getPrimarySelector()->willReturn($primarySelector);
     $this->queryExecuteEvent->getQuery()->willReturn($this->query->reveal());
     $this->queryExecuteEvent->getOptions()->willReturn([]);
     $this->queryExecuteEvent->setResult(new QueryResultCollection($this->phpcrResult->reveal(), $this->dispatcher->reveal(), $locale))->shouldBeCalled();
     $this->subscriber->handleQueryExecute($this->queryExecuteEvent->reveal());
 }
Example #3
0
 /**
  * Proxy method to return language of the wrapped PHPCR Query
  *
  * @return string The language used
  */
 public function getLanguage()
 {
     return $this->query->getLanguage();
 }
Example #4
0
 /**
  * Get document results from a PHPCR query instance
  *
  * @param  \PHPCR\Query\QueryInterface $query the query instance as acquired through createQuery()
  * @param  string $documentName document class
  *
  * @return array of document instances
  */
 public function getDocumentsByQuery(\PHPCR\Query\QueryInterface $query, $className = null)
 {
     $this->errorIfClosed();
     $documents = array();
     // get all nodes from the node iterator
     $nodes = $query->execute()->getNodes(true);
     foreach ($nodes as $node) {
         $documents[$node->getPath()] = $this->unitOfWork->createDocument($className, $node);
     }
     return new ArrayCollection($documents);
 }
Example #5
0
 /**
  * {@inheritDoc}
  */
 public function getDocumentsByPhpcrQuery(QueryInterface $query, $className = null, $primarySelector = null)
 {
     $this->errorIfClosed();
     $result = $query->execute();
     $ids = array();
     foreach ($result->getRows() as $row) {
         /** @var $row \PHPCR\Query\RowInterface */
         $ids[] = $row->getPath($primarySelector);
     }
     return $this->findMany($className, $ids);
 }
 /**
  * a transient query has no stored query path.
  *
  * @expectedException \PHPCR\ItemNotFoundException
  */
 public function testGetStoredQueryPathItemNotFound()
 {
     $this->query->getStoredQueryPath();
 }