PHP Class Pheasant\Collection

Inheritance: implements IteratorAggregate, implements Countable, implements ArrayAccess
Afficher le fichier Open project: lox/pheasant

Méthodes publiques

Méthode 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

Méthode Description
_queryForWrite ( )

Method Details

__call() public méthode

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

__construct() public méthode

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 méthode

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

aggregate() public méthode

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

avg() public méthode

public avg ( $field )

column() public méthode

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

count() public méthode

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

delete() public méthode

Delete all objects in a collection
public delete ( )

filter() public méthode

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

first() public méthode

public first ( )

getIterator() public méthode

Returns an iterator
public getIterator ( )

groupBy() public méthode

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 méthode

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

includes() public méthode

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

join() public méthode

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 méthode

public last ( )

limit() public méthode

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

lock() public méthode

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

max() public méthode

public max ( $field )

min() public méthode

public min ( $field )

offsetExists() public méthode

public offsetExists ( $offset )

offsetGet() public méthode

array access
public offsetGet ( $offset )

offsetSet() public méthode

public offsetSet ( $offset, $value )

offsetUnset() public méthode

public offsetUnset ( $offset )

one() public méthode

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

orCreate() public méthode

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 méthode

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

orderBy() public méthode

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

query() public méthode

Gets the underlying query object
public query ( )

save() public méthode

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

select() public méthode

Selects only particular fields
public select ( $fields )

sum() public méthode

public sum ( $field )

toArray() public méthode

public toArray ( )

unique() public méthode

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 ( )