class Query implements QueryInterface (View source)

A Query class for Doctrine 2

Properties

protected string $entityClassName
protected LoggerInterface $logger
protected ThrowableStorageInterface $throwableStorage
protected QueryBuilder $queryBuilder
protected EntityManager $entityManager
protected array $settings
protected mixed $constraint
protected array $orderings
protected int|null $limit
protected bool $distinct
protected int|null $offset
protected int $parameterIndex
protected array $parameters
protected array $joins
protected int $joinAliasCounter
protected bool $cacheResult

Methods

__construct(string $entityClassName)

No description

void
injectEntityManager(EntityManagerInterface $entityManager)

No description

void
injectSettings(array $settings)

Injects the Flow settings, the persistence part is kept for further use.

injectLogger(LoggerInterface $logger)

No description

string
getType()

Returns the type this query cares for.

execute(bool $cacheResult = false)

Executes the query and returns the result.

array
getResult()

Gets the results of this query as array.

int
count()

Returns the query result count

setOrderings(array $orderings)

Sets the property names to order the result by. Expected like this: array( 'foo' => \Neos\Flow\Persistence\QueryInterface::ORDER_ASCENDING, 'bar' => \Neos\Flow\Persistence\QueryInterface::ORDER_DESCENDING )

array
getOrderings()

Returns the property names to order the result by, like this: array( 'foo' => \Neos\Flow\Persistence\QueryInterface::ORDER_ASCENDING, 'bar' => \Neos\Flow\Persistence\QueryInterface::ORDER_DESCENDING )

setLimit(int|null $limit)

Sets the maximum size of the result set to limit. Returns $this to allow for chaining (fluid interface)

int|null
getLimit()

Returns the maximum size of the result set to limit.

setDistinct(bool $distinct = true)

Sets the DISTINCT flag for this query.

bool
isDistinct()

Returns the DISTINCT flag for this query.

setOffset(int|null $offset)

Sets the start offset of the result set to offset. Returns $this to allow for chaining (fluid interface)

int|null
getOffset()

Returns the start offset of the result set.

matching(object $constraint)

The constraint used to limit the result set. Returns $this to allow for chaining (fluid interface)

mixed
getConstraint()

Gets the constraint for this query.

object
logicalAnd(mixed $constraint1)

Performs a logical conjunction of the two given constraints. The method takes one or more constraints and concatenates them with a boolean AND.

object
logicalOr(mixed $constraint1)

Performs a logical disjunction of the two given constraints. The method takes one or more constraints and concatenates them with a boolean OR.

object
logicalNot(object $constraint)

Performs a logical negation of the given constraint

object
equals(string $propertyName, mixed $operand, bool $caseSensitive = true)

Returns an equals criterion used for matching objects against a query.

object
like(string $propertyName, string $operand, bool $caseSensitive = true)

Returns a like criterion used for matching objects against a query.

mixed
contains(string $propertyName, mixed $operand)

Returns a "contains" criterion used for matching objects against a query.

mixed
isEmpty(string $propertyName)

Returns an "isEmpty" criterion used for matching objects against a query.

object
in(string $propertyName, mixed $operand)

Returns an "in" criterion used for matching objects against a query. It matches if the property's value is contained in the multivalued operand.

object
lessThan(string $propertyName, mixed $operand)

Returns a less than criterion used for matching objects against a query

object
lessThanOrEqual(string $propertyName, mixed $operand)

Returns a less or equal than criterion used for matching objects against a query

object
greaterThan(string $propertyName, mixed $operand)

Returns a greater than criterion used for matching objects against a query

object
greaterThanOrEqual(string $propertyName, mixed $operand)

Returns a greater than or equal criterion used for matching objects against a query

void
addParameters(array $parameters)

Add parameters to the query

ArrayCollection
getParameters()

Gets all defined query parameters for the query being constructed.

string
getParamNeedle(mixed $operand)

Get a needle for parameter binding.

string
getPropertyNameWithAlias(string $propertyPath)

Adds left join clauses along the given property path to the query, if needed.

array
getSql()

Return the SQL statements representing this Query.

array
__sleep()

We need to drop the query builder, as it contains a PDO instance deep inside.

void
__wakeup()

Recreate query builder and set state again.

__clone()

Cloning the query clones also the internal QueryBuilder, as they are tightly coupled.

QueryBuilder
getQueryBuilder()

No description

Details

__construct(string $entityClassName)

No description

Parameters

string $entityClassName

void injectEntityManager(EntityManagerInterface $entityManager)

No description

Parameters

EntityManagerInterface $entityManager

Return Value

void

void injectSettings(array $settings)

Injects the Flow settings, the persistence part is kept for further use.

Parameters

array $settings

Return Value

void

injectLogger(LoggerInterface $logger)

No description

Parameters

LoggerInterface $logger

string getType()

Returns the type this query cares for.

Return Value

string

QueryResultInterface execute(bool $cacheResult = false)

Executes the query and returns the result.

Parameters

bool $cacheResult

If the result cache should be used

Return Value

QueryResultInterface

The query result

array getResult()

Gets the results of this query as array.

Really executes the query on the database. This should only ever be executed from the QueryResult class.

int count()

Returns the query result count

Return Value

int

The query result count

Exceptions

DatabaseConnectionException

QueryInterface setOrderings(array $orderings)

Sets the property names to order the result by. Expected like this: array( 'foo' => \Neos\Flow\Persistence\QueryInterface::ORDER_ASCENDING, 'bar' => \Neos\Flow\Persistence\QueryInterface::ORDER_DESCENDING )

Parameters

array $orderings

The property names to order by

Return Value

QueryInterface

array getOrderings()

Returns the property names to order the result by, like this: array( 'foo' => \Neos\Flow\Persistence\QueryInterface::ORDER_ASCENDING, 'bar' => \Neos\Flow\Persistence\QueryInterface::ORDER_DESCENDING )

Return Value

array

QueryInterface setLimit(int|null $limit)

Sets the maximum size of the result set to limit. Returns $this to allow for chaining (fluid interface)

Parameters

int|null $limit

Return Value

QueryInterface

int|null getLimit()

Returns the maximum size of the result set to limit.

Return Value

int|null

QueryInterface setDistinct(bool $distinct = true)

Sets the DISTINCT flag for this query.

Parameters

bool $distinct

Return Value

QueryInterface

bool isDistinct()

Returns the DISTINCT flag for this query.

Return Value

bool

QueryInterface setOffset(int|null $offset)

Sets the start offset of the result set to offset. Returns $this to allow for chaining (fluid interface)

Parameters

int|null $offset

Return Value

QueryInterface

int|null getOffset()

Returns the start offset of the result set.

Return Value

int|null

QueryInterface matching(object $constraint)

The constraint used to limit the result set. Returns $this to allow for chaining (fluid interface)

Parameters

object $constraint

Some constraint, depending on the backend

Return Value

QueryInterface

mixed getConstraint()

Gets the constraint for this query.

Return Value

mixed

the constraint, or null if none

object logicalAnd(mixed $constraint1)

Performs a logical conjunction of the two given constraints. The method takes one or more constraints and concatenates them with a boolean AND.

It also accepts a single array of constraints to be concatenated.

Parameters

mixed $constraint1

The first of multiple constraints or an array of constraints.

Return Value

object

object logicalOr(mixed $constraint1)

Performs a logical disjunction of the two given constraints. The method takes one or more constraints and concatenates them with a boolean OR.

It also accepts a single array of constraints to be concatenated.

Parameters

mixed $constraint1

The first of multiple constraints or an array of constraints.

Return Value

object

object logicalNot(object $constraint)

Performs a logical negation of the given constraint

Parameters

object $constraint

Constraint to negate

Return Value

object

object equals(string $propertyName, mixed $operand, bool $caseSensitive = true)

Returns an equals criterion used for matching objects against a query.

It matches if the $operand equals the value of the property named $propertyName. If $operand is NULL a strict check for NULL is done. For strings the comparison can be done with or without case-sensitivity.

Note: case-sensitivity is only possible if the database supports it. E.g. if you are using MySQL with a case-insensitive collation you will not be able to test for case-sensitive equality (the other way around works, because we compare lowercased values).

Parameters

string $propertyName

The name of the property to compare against

mixed $operand

The value to compare with

bool $caseSensitive

Whether the equality test should be done case-sensitive for strings

Return Value

object

object like(string $propertyName, string $operand, bool $caseSensitive = true)

Returns a like criterion used for matching objects against a query.

Matches if the property named $propertyName is like the $operand, using standard SQL wildcards.

Parameters

string $propertyName

The name of the property to compare against

string $operand

The value to compare with

bool $caseSensitive

Whether the matching should be done case-sensitive

Return Value

object

mixed contains(string $propertyName, mixed $operand)

Returns a "contains" criterion used for matching objects against a query.

It matches if the multivalued property contains the given operand.

If NULL is given as $operand, there will never be a match!

Parameters

string $propertyName

The name of the multivalued property to compare against

mixed $operand

The value to compare with

Return Value

mixed

mixed isEmpty(string $propertyName)

Returns an "isEmpty" criterion used for matching objects against a query.

It matches if the multivalued property contains no values or is NULL.

Parameters

string $propertyName

The name of the multivalued property to compare against

Return Value

mixed

object in(string $propertyName, mixed $operand)

Returns an "in" criterion used for matching objects against a query. It matches if the property's value is contained in the multivalued operand.

Parameters

string $propertyName

The name of the property to compare against

mixed $operand

The value to compare with, multivalued

Return Value

object

object lessThan(string $propertyName, mixed $operand)

Returns a less than criterion used for matching objects against a query

Parameters

string $propertyName

The name of the property to compare against

mixed $operand

The value to compare with

Return Value

object

object lessThanOrEqual(string $propertyName, mixed $operand)

Returns a less or equal than criterion used for matching objects against a query

Parameters

string $propertyName

The name of the property to compare against

mixed $operand

The value to compare with

Return Value

object

object greaterThan(string $propertyName, mixed $operand)

Returns a greater than criterion used for matching objects against a query

Parameters

string $propertyName

The name of the property to compare against

mixed $operand

The value to compare with

Return Value

object

object greaterThanOrEqual(string $propertyName, mixed $operand)

Returns a greater than or equal criterion used for matching objects against a query

Parameters

string $propertyName

The name of the property to compare against

mixed $operand

The value to compare with

Return Value

object

void addParameters(array $parameters)

Add parameters to the query

Parameters

array $parameters

Return Value

void

ArrayCollection getParameters()

Gets all defined query parameters for the query being constructed.

Return Value

ArrayCollection

protected string getParamNeedle(mixed $operand)

Get a needle for parameter binding.

Parameters

mixed $operand

Return Value

string

protected string getPropertyNameWithAlias(string $propertyPath)

Adds left join clauses along the given property path to the query, if needed.

This enables us to set conditions on related objects.

Parameters

string $propertyPath

The path to a sub property, e.g. property.subProperty.foo, or a simple property name

Return Value

string

The last part of the property name prefixed by the used join alias, if joins have been added

array getSql()

Return the SQL statements representing this Query.

Return Value

array

array __sleep()

We need to drop the query builder, as it contains a PDO instance deep inside.

Return Value

array

void __wakeup()

Recreate query builder and set state again.

Return Value

void

__clone()

Cloning the query clones also the internal QueryBuilder, as they are tightly coupled.

QueryBuilder getQueryBuilder()

No description

Return Value

QueryBuilder