class Query (View source)

Query.

Wraps the given PHPCR query object in the ODM, emulating the Query object from the ORM.

Constants

HYDRATE_DOCUMENT

HYDRATE_PHPCR

Properties

protected $hydrationMode
protected $parameters
protected $primaryAlias
protected $firstResult
protected $maxResults
protected $documentClass
protected QueryInterface $query
protected DocumentManagerInterface $dm

Methods

__construct(QueryInterface $query, DocumentManagerInterface $dm, $primaryAlias = null)

No description

setHydrationMode(string $hydrationMode)

Defines the processing mode to be used during hydration / result set transformation.

string
getHydrationMode()

Gets the hydration mode currently used by the query.

array
getParameters()

Get all defined parameters.

setParameters(array $parameters)

Sets a collection of query parameters.

setParameter(string $key, mixed $value)

Sets a query parameter.

mixed|null
getParameter(mixed $key)

Gets a query parameter.

setDocumentClass(string $documentClass)

Set the document class to use when using HYDRATION_DOCUMENT.

mixed
execute(array $parameters = null, int $hydrationMode = null)

Executes the query and returns the result based on the hydration mode.

array
getResult(int $hydrationMode = self::HYDRATE_DOCUMENT)

Gets the list of results for the query.

array
getPhpcrNodeResult()

Gets the phpcr node results for the query.

mixed
getOneOrNullResult(int $hydrationMode = null)

Get exactly one result or null.

mixed
getSingleResult(int $hydrationMode = null)

Gets the single result of the query.

TODO
iterate(array $parameters = null, int $hydrationMode = null)

Executes the query and returns an IterableResult that can be used to incrementally iterate over the result.

setMaxResults(int $maxResults)

Sets the maximum number of results to retrieve (the "limit").

int
getMaxResults()

Gets the maximum number of results the query object was set to retrieve (the "limit"). Returns NULL if {@link setMaxResults} was not applied to this query.

setFirstResult(int $firstResult)

Sets the position of the first result to retrieve (the "offset").

int
getFirstResult()

Gets the position of the first result the query object was set to retrieve (the "offset"). Returns NULL if {@link setFirstResult} was not applied to this query.

string
getStatement()

Proxy method to return statement of the wrapped PHPCR Query.

string
getLanguage()

Proxy method to return language of the wrapped PHPCR Query.

QueryInterface
getPhpcrQuery()

Return wrapped PHPCR query object.

Details

__construct(QueryInterface $query, DocumentManagerInterface $dm, $primaryAlias = null)

Parameters

QueryInterface $query
DocumentManagerInterface $dm
$primaryAlias

Query setHydrationMode(string $hydrationMode)

Defines the processing mode to be used during hydration / result set transformation.

Parameters

string $hydrationMode The mode to return the result in execute.

Return Value

Query This query instance.

Exceptions

QueryException If $hydrationMode is not known.

See also

execute

string getHydrationMode()

Gets the hydration mode currently used by the query.

Return Value

string

array getParameters()

Get all defined parameters.

Return Value

array The defined query parameters.

Query setParameters(array $parameters)

Sets a collection of query parameters.

Parameters

array $parameters

Return Value

Query This query instance.

Query setParameter(string $key, mixed $value)

Sets a query parameter.

Parameters

string $key The parameter name.
mixed $value The parameter value.

Return Value

Query This query instance.

mixed|null getParameter(mixed $key)

Gets a query parameter.

Parameters

mixed $key The key of the bound parameter.

Return Value

mixed|null The value of the bound parameter.

Query setDocumentClass(string $documentClass)

Set the document class to use when using HYDRATION_DOCUMENT.

Note: This is useful in the following two cases:

  1. You want to be sure that the ODM returns the correct document type (A query can return multiple document types, the ODM will ignore Documents not matching the type given here)

  2. The PHPCR Node does not contain the phpcr:class metadata property.

Parameters

string $documentClass FQN of document class

Return Value

Query This query instance.

mixed execute(array $parameters = null, int $hydrationMode = null)

Executes the query and returns the result based on the hydration mode.

Parameters

array $parameters Parameters, alternative to calling setParameters.
int $hydrationMode Processing mode to be used during the hydration process. One of the Query::HYDRATE_* constants.

Return Value

mixed A Collection for HYDRATE_DOCUMENT, \PHPCR\Query\QueryResultInterface for HYDRATE_PHPCR

Exceptions

QueryException If $hydrationMode is not known.

array getResult(int $hydrationMode = self::HYDRATE_DOCUMENT)

Gets the list of results for the query.

Alias for execute(null, $hydrationMode = HYDRATE_DOCUMENT).

Parameters

int $hydrationMode One of the hydration class constants

Return Value

array

array getPhpcrNodeResult()

Gets the phpcr node results for the query.

Alias for execute(null, HYDRATE_PHPCR).

Return Value

array

mixed getOneOrNullResult(int $hydrationMode = null)

Get exactly one result or null.

Parameters

int $hydrationMode

Return Value

mixed

Exceptions

QueryException if more than one result found

mixed getSingleResult(int $hydrationMode = null)

Gets the single result of the query.

Enforces the presence as well as the uniqueness of the result.

If the result is not unique, a NonUniqueResultException is thrown. If there is no result, a NoResultException is thrown.

Parameters

int $hydrationMode

Return Value

mixed

Exceptions

QueryException if no result or more than one result found

TODO iterate(array $parameters = null, int $hydrationMode = null)

Executes the query and returns an IterableResult that can be used to incrementally iterate over the result.

Parameters

array $parameters The query parameters.
int $hydrationMode The hydration mode to use.

Return Value

TODO \Doctrine\ORM\Internal\Hydration\IterableResult

Query setMaxResults(int $maxResults)

Sets the maximum number of results to retrieve (the "limit").

Parameters

int $maxResults

Return Value

Query This query object.

int getMaxResults()

Gets the maximum number of results the query object was set to retrieve (the "limit"). Returns NULL if {@link setMaxResults} was not applied to this query.

Return Value

int Maximum number of results.

Query setFirstResult(int $firstResult)

Sets the position of the first result to retrieve (the "offset").

Parameters

int $firstResult The first result to return.

Return Value

Query This query object.

int getFirstResult()

Gets the position of the first result the query object was set to retrieve (the "offset"). Returns NULL if {@link setFirstResult} was not applied to this query.

Return Value

int The position of the first result.

string getStatement()

Proxy method to return statement of the wrapped PHPCR Query.

Return Value

string The query statement.

string getLanguage()

Proxy method to return language of the wrapped PHPCR Query.

Return Value

string The language used

QueryInterface getPhpcrQuery()

Return wrapped PHPCR query object.

Return Value

QueryInterface