public function testExecute() { $qr = $this->query->execute(); $this->assertInstanceOf('PHPCR\\Query\\QueryResultInterface', $qr); $this->assertCount(5, $qr->getRows()); // we assume content is the same as for sql2 }
/** * 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; }
/** * 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()); }
/** * @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(); }
/** * 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); }
/** * {@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); }