PHP Class Pheasant\Collection

Inheritance: implements IteratorAggregate, implements Countable, implements ArrayAccess
Mostra file Open project: lox/pheasant

Public Methods

Method Description
__call ( $name, $args ) Magic Method, used for scopes
__construct ( $class, $query, $add = false )
__invoke ( $sql, $params = [] ) Filter function when called as a function
aggregate ( $function, $fields = null ) helpers for common aggregate functions
avg ( $field )
column ( $field ) Reduces a collection down to a single column
count ( ) Counts the number or results in the query
delete ( ) Delete all objects in a collection
filter ( $sql, $params = [] ) Adds a filter to the collection
first ( )
getIterator ( ) Returns an iterator
groupBy ( $columns ) Groups domain objects particular columns, either a single column an array. This method is additive, it won't replace previous groupBy's
hydrate ( $row ) Hydrates a row to a DomainObject
includes ( $rels ) Eager load relationships to avoid the N+1 problem
join ( $rels, $joinType = 'inner' ) Join other related objects into a collection for the purpose of filtering. Relationships is either a flat array of relationships (as defined in the object's schema) or a nested array
last ( )
limit ( $rows, $offset ) Restricts the number of rows to return
lock ( $clause = null ) Adds a locking clause to the query
max ( $field )
min ( $field )
offsetExists ( $offset )
offsetGet ( $offset ) array access
offsetSet ( $offset, $value )
offsetUnset ( $offset )
one ( ) Return one and one only object from a collection
orCreate ( $args ) Creates the passed params as a domain object if there are no results in the collection.
order ( $sql, $params = [] ) Orders the collection
orderBy ( $sql, $params = [] ) Orders the collection
query ( ) Gets the underlying query object
save ( $callback ) Applies a callback to all objects in Collection, saves them if the object has changed
select ( $fields ) Selects only particular fields
sum ( $field )
toArray ( )
unique ( ) Return only unique combinations of the domain object in the collection, e.g such as when you want only the unique objects that are the result of a join on conditions. Only columns from the primary object will be in the result.

Private Methods

Method Description
_queryForWrite ( )

Method Details

__call() public method

Magic Method, used for scopes
public __call ( $name, $args )

__construct() public method

public __construct ( $class, $query, $add = false )
$class string the classname to hydrate
$query Query the query object
$add Closure a closure to call when an object is appended

__invoke() public method

Filter function when called as a function
public __invoke ( $sql, $params = [] )

aggregate() public method

helpers for common aggregate functions
public aggregate ( $function, $fields = null )

avg() public method

public avg ( $field )

column() public method

Reduces a collection down to a single column
public column ( $field )

count() public method

Counts the number or results in the query
public count ( )

delete() public method

Delete all objects in a collection
public delete ( )

filter() public method

Adds a filter to the collection
public filter ( $sql, $params = [] )

first() public method

public first ( )

getIterator() public method

Returns an iterator
public getIterator ( )

groupBy() public method

Groups domain objects particular columns, either a single column an array. This method is additive, it won't replace previous groupBy's
public groupBy ( $columns )

hydrate() public method

Hydrates a row to a DomainObject
public hydrate ( $row )

includes() public method

Eager load relationships to avoid the N+1 problem
public includes ( $rels )

join() public method

Join other related objects into a collection for the purpose of filtering. Relationships is either a flat array of relationships (as defined in the object's schema) or a nested array
public join ( $rels, $joinType = 'inner' )

last() public method

public last ( )

limit() public method

Restricts the number of rows to return
public limit ( $rows, $offset )

lock() public method

Adds a locking clause to the query
public lock ( $clause = null )

max() public method

public max ( $field )

min() public method

public min ( $field )

offsetExists() public method

public offsetExists ( $offset )

offsetGet() public method

array access
public offsetGet ( $offset )

offsetSet() public method

public offsetSet ( $offset, $value )

offsetUnset() public method

public offsetUnset ( $offset )

one() public method

Return one and one only object from a collection
public one ( )

orCreate() public method

Creates the passed params as a domain object if there are no results in the collection.
public orCreate ( $args )
$args array an array to be passed to the constructor via call_user_func_array

order() public method

Orders the collection
Deprecation:
public order ( $sql, $params = [] )

orderBy() public method

Orders the collection
public orderBy ( $sql, $params = [] )

query() public method

Gets the underlying query object
public query ( )

save() public method

Applies a callback to all objects in Collection, saves them if the object has changed
public save ( $callback )

select() public method

Selects only particular fields
public select ( $fields )

sum() public method

public sum ( $field )

toArray() public method

public toArray ( )

unique() public method

Return only unique combinations of the domain object in the collection, e.g such as when you want only the unique objects that are the result of a join on conditions. Only columns from the primary object will be in the result.
public unique ( )