PHP Class Spot\Query

Author: Vance Lucas ([email protected])
Inheritance: implements Countable, implements IteratorAggregate, implements spot\QueryInterface
Show file Open project: vlucas/spot2 Class Usage Examples

Protected Properties

Property Type Description
$_customMethods array Custom methods added by extensions or plugins
$_data array Storage for eager-loaded relations
$_entityName string
$_mapper Mapper
$_noQuote boolean
$_queryBuilder
$_tableName string
$_whereOperatorObjects array Already instantiated operator objects
$_whereOperators array
$with array Storage for query properties

Public Methods

Method Description
__call ( string $method, array $args ) : mixed Run user-added callback
__construct ( Mapper $mapper ) Constructor Method
addMethod ( string $method, callable $callback ) Add a custom user method via closure or PHP callback
addWhereOperator ( string $operator, callable | string $action ) Adds a custom type to the type map.
andWhere ( array $where, string $type = 'AND' ) WHERE AND conditions
builder ( ) : Doctrine\DBAL\Query\QueryBuilder Get current Doctrine DBAL query builder object
count ( ) : integer SPL Countable function Called automatically when attribute is used in a 'count()' function call
delete ( ) Delete (passthrough to DBAL QueryBuilder)
entityName ( ) : string Get current entity name query is to be performed on
escape ( string $string ) : string Escape/quote direct user input
escapeIdentifier ( string | array $identifier ) : string | array Escape/quote identifier
execute ( ) : mixed Execute and return query as a collection
expr ( ) : Doctrine\DBAL\Query\Expression\ExpressionBuilder Return DBAL Query builder expression
fieldWithAlias ( string $field, boolean $escaped = true ) : string Get field name with table alias appended
first ( ) : mixed Return the first entity matched by the query
from ( ) From (passthrough to DBAL QueryBuilder)
getIterator ( ) : Collection SPL IteratorAggregate function Called automatically when attribute is used in a 'foreach' loop
getParameters ( ) : mixed Get all bound query parameters (passthrough to DBAL QueryBuilder)
group ( array $fields = [] ) GROUP BY clause
having ( array $having, string $type = 'AND' ) Having clause to filter results by a calculated value
jsonSerialize ( ) JsonSerializable
limit ( integer $limit, integer $offset = null ) Limit executed query to specified amount of records Implemented at adapter-level for databases that support it
mapper ( ) : Mapper Get current adapter object
noQuote ( boolean $noQuote = true ) Set field and value quoting on/off - maily used for testing output SQL since quoting is different per platform
offset ( integer $offset ) Offset executed query to skip specified amount of records Implemented at adapter-level for databases that support it
offsetExists ( $key ) SPL - ArrayAccess
offsetGet ( $key ) SPL - ArrayAccess
offsetSet ( $key, $value ) SPL - ArrayAccess
offsetUnset ( $key ) SPL - ArrayAccess
orWhere ( array $where, string $type = 'AND' ) WHERE OR conditions
order ( array $order ) ORDER BY columns
search ( mixed $fields, string $query, array $options = [] ) Search criteria (FULLTEXT, LIKE, or REGEX, depending on storage engine and driver)
select ( ) Select (passthrough to DBAL QueryBuilder)
setParameters ( ) Set query parameters (passthrough to DBAL QueryBuilder)
toArray ( string | null $keyColumn = null, string | null $valueColumn = null ) : array Convenience function passthrough for Collection
toSql ( ) : string Get raw SQL string from built query
unescapeIdentifier ( string $identifier ) : string Removes escape/quote character
where ( array $where, string $type = 'AND' ) WHERE conditions
whereFieldSql ( string $field, string $sql, array $params = [] ) WHERE field + raw SQL
whereSql ( string $sql ) WHERE conditions
with ( mixed | null $relations = null ) Relations to be eager-loaded

Private Methods

Method Description
getWhereOperatorCallable ( string $operator ) : callable | false
parseWhereToSQLFragments ( array $where, boolean $useAlias = true ) : array Parse array-syntax WHERE conditions and translate them to DBAL QueryBuilder syntax

Method Details

__call() public method

Run user-added callback
public __call ( string $method, array $args ) : mixed
$method string Method name called
$args array Array of arguments used in missing method call
return mixed

__construct() public method

Constructor Method
public __construct ( Mapper $mapper )
$mapper Mapper

addMethod() public static method

Add a custom user method via closure or PHP callback
public static addMethod ( string $method, callable $callback )
$method string Method name to add
$callback callable Callback or closure that will be executed when missing method call matching $method is made

addWhereOperator() public static method

Adds a custom type to the type map.
public static addWhereOperator ( string $operator, callable | string $action )
$operator string
$action callable | string

andWhere() public method

WHERE AND conditions
public andWhere ( array $where, string $type = 'AND' )
$where array Array of conditions for this clause
$type string Keyword that will separate each condition - "AND", "OR"

builder() public method

Get current Doctrine DBAL query builder object
public builder ( ) : Doctrine\DBAL\Query\QueryBuilder
return Doctrine\DBAL\Query\QueryBuilder

count() public method

Executes separate query with COUNT(*), and drops and ordering (not important for counting)
public count ( ) : integer
return integer

delete() public method

Delete (passthrough to DBAL QueryBuilder)
public delete ( )

entityName() public method

Get current entity name query is to be performed on
public entityName ( ) : string
return string

escape() public method

Escape/quote direct user input
public escape ( string $string ) : string
$string string
return string

escapeIdentifier() public method

Escape/quote identifier
public escapeIdentifier ( string | array $identifier ) : string | array
$identifier string | array
return string | array

execute() public method

Execute and return query as a collection
public execute ( ) : mixed
return mixed Collection object on success, boolean false on failure

expr() public method

Return DBAL Query builder expression
public expr ( ) : Doctrine\DBAL\Query\Expression\ExpressionBuilder
return Doctrine\DBAL\Query\Expression\ExpressionBuilder

fieldWithAlias() public method

Get field name with table alias appended
public fieldWithAlias ( string $field, boolean $escaped = true ) : string
$field string
$escaped boolean
return string

first() public method

Return the first entity matched by the query
public first ( ) : mixed
return mixed Spot_Entity on success, boolean false on failure

from() public method

From (passthrough to DBAL QueryBuilder)
public from ( )

getIterator() public method

SPL IteratorAggregate function Called automatically when attribute is used in a 'foreach' loop
public getIterator ( ) : Collection
return Spot\Entity\Collection

getParameters() public method

Get all bound query parameters (passthrough to DBAL QueryBuilder)
public getParameters ( ) : mixed
return mixed

group() public method

GROUP BY clause
public group ( array $fields = [] )
$fields array Array of field names to use for grouping

having() public method

Having clause to filter results by a calculated value
public having ( array $having, string $type = 'AND' )
$having array Array (like where) for HAVING statement for filter records by
$type string

jsonSerialize() public method

JsonSerializable
public jsonSerialize ( )

limit() public method

Limit executed query to specified amount of records Implemented at adapter-level for databases that support it
public limit ( integer $limit, integer $offset = null )
$limit integer Number of records to return
$offset integer Record to start at for limited result set

mapper() public method

Get current adapter object
public mapper ( ) : Mapper
return Mapper

noQuote() public method

Set field and value quoting on/off - maily used for testing output SQL since quoting is different per platform
public noQuote ( boolean $noQuote = true )
$noQuote boolean

offset() public method

Offset executed query to skip specified amount of records Implemented at adapter-level for databases that support it
public offset ( integer $offset )
$offset integer Record to start at for limited result set

offsetExists() public method

SPL - ArrayAccess
public offsetExists ( $key )

offsetGet() public method

SPL - ArrayAccess
public offsetGet ( $key )

offsetSet() public method

SPL - ArrayAccess
public offsetSet ( $key, $value )

offsetUnset() public method

SPL - ArrayAccess
public offsetUnset ( $key )

orWhere() public method

WHERE OR conditions
public orWhere ( array $where, string $type = 'AND' )
$where array Array of conditions for this clause
$type string Keyword that will separate each condition - "AND", "OR"

order() public method

ORDER BY columns
public order ( array $order )
$order array Array of field names to use for sorting

select() public method

Select (passthrough to DBAL QueryBuilder)
public select ( )

setParameters() public method

Set query parameters (passthrough to DBAL QueryBuilder)
public setParameters ( )

toArray() public method

Convenience function passthrough for Collection
public toArray ( string | null $keyColumn = null, string | null $valueColumn = null ) : array
$keyColumn string | null
$valueColumn string | null
return array

toSql() public method

Get raw SQL string from built query
public toSql ( ) : string
return string

unescapeIdentifier() public method

Removes escape/quote character
public unescapeIdentifier ( string $identifier ) : string
$identifier string
return string

where() public method

WHERE conditions
public where ( array $where, string $type = 'AND' )
$where array Array of conditions for this clause
$type string Keyword that will separate each condition - "AND", "OR"

whereFieldSql() public method

WHERE field + raw SQL
public whereFieldSql ( string $field, string $sql, array $params = [] )
$field string Field name for SQL statement (will be quoted)
$sql string SQL string to put in WHERE clause
$params array

whereSql() public method

WHERE conditions
public whereSql ( string $sql )
$sql string SQL string to put in WHERE clause

with() public method

Relations to be eager-loaded
public with ( mixed | null $relations = null )
$relations mixed | null Array/string of relation(s) to be loaded.

Property Details

$_customMethods protected static property

Custom methods added by extensions or plugins
protected static array $_customMethods
return array

$_data protected property

Storage for eager-loaded relations
protected array $_data
return array

$_entityName protected property

protected string $_entityName
return string

$_mapper protected property

protected Mapper,Spot $_mapper
return Mapper

$_noQuote protected property

protected bool $_noQuote
return boolean

$_queryBuilder protected property

protected $_queryBuilder

$_tableName protected property

protected string $_tableName
return string

$_whereOperatorObjects protected static property

Already instantiated operator objects
protected static array $_whereOperatorObjects
return array

$_whereOperators protected static property

protected static array $_whereOperators
return array

$with protected property

Storage for query properties
protected array $with
return array