PHP Класс Collection

phynx is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. phynx is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . 2007 - 2012, Rainer Furtmeier - [email protected]
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$filters

Защищенные свойства (Protected)

Свойство Тип Описание
$pagination

Открытые методы

Метод Описание
__call ( $key, $arguments )
__debuginfo ( ) : array Improved var_dump() output
__get ( $key )
__set ( $key, $value )
__toString ( ) : string Makes it possible to echo the entire object
append ( string $key, mixed $object ) : Collection Appends an element to the data array
chunk ( integer $size ) : object Creates chunks of the same size The last chunk may be smaller
count ( ) : integer Counts all elements in the array
extractValue ( mixed $item, string $field ) : mixed Makes sure to provide a valid value for each filter method no matter if an object or an array is given
filter ( func $callback ) : Collection Filter the elements in the array by a callback function
filterBy ( ) : Collection Filters the current collection by a field, operator and search value
findBy ( string $key, mixed $value ) : mixed Find a single item by a key and value pair
first ( ) : mixed Returns the first element from the array
flip ( ) : Collection Returns the array in reverse order
get ( $key, $default = null )
group ( callable $callback ) : object Groups the collection by a given callback
groupBy ( string $field, $i = true ) : object Groups the collection by a given field
has ( string $key ) : boolean Checks if an element is in the collection by key.
indexOf ( mixed $needle ) : mixed Tries to find the index number for the given element
keyOf ( mixed $needle ) : mixed Tries to find the key for the given element
keys ( ) : array Returns an array of all keys in the collection
last ( ) : mixed Returns the last element from the array
limit ( integer $limit ) : Collection Returns a new collection with a limited number of elements
map ( function $callback ) : Collection Map a function to each item in the collection
merge ( $collection2 ) : Collection Returns a new combined collection
not ( ) : Collection Returns a new collection without the given element(s)
nth ( $n ) : mixed Returns the nth element from the array
offset ( integer $offset ) : Collection Returns a new collection starting from the given offset
paginate ( integer $limit, array $options = [] ) : object Add pagination
pagination ( ) : object Get the previously added pagination object
pluck ( string $field, $split = null, $unique = false ) : array Extracts all values for a single field into a new array
prepend ( string $key, mixed $object ) : Collection Prepends an element to the data array
set ( $key, $value )
shuffle ( ) : object Shuffle all elements in the array
slice ( integer $offset = null, integer $limit = null ) : Collection Returns a slice of the collection
sortBy ( ) : Collection Sorts the collection by any number of fields
toArray ( $callback = null ) : array Converts the current object into an array
toJson ( ) : string Converts the current object into a json string
without ( ) : Collection Returns a new collection without the given element(s)

Описание методов

__call() публичный Метод

public __call ( $key, $arguments )

__debuginfo() публичный Метод

Improved var_dump() output
public __debuginfo ( ) : array
Результат array

__get() публичный Метод

public __get ( $key )

__set() публичный Метод

public __set ( $key, $value )

__toString() публичный Метод

Makes it possible to echo the entire object
public __toString ( ) : string
Результат string

append() публичный Метод

Appends an element to the data array
public append ( string $key, mixed $object ) : Collection
$key string
$object mixed
Результат Collection

chunk() публичный Метод

Creates chunks of the same size The last chunk may be smaller
public chunk ( integer $size ) : object
$size integer Number of items per chunk
Результат object A new collection with an item for each chunk and a subcollection in each chunk

count() публичный Метод

Counts all elements in the array
public count ( ) : integer
Результат integer

extractValue() публичный статический Метод

Makes sure to provide a valid value for each filter method no matter if an object or an array is given
public static extractValue ( mixed $item, string $field ) : mixed
$item mixed
$field string
Результат mixed

filter() публичный Метод

Filter the elements in the array by a callback function
public filter ( func $callback ) : Collection
$callback func the callback function
Результат Collection

filterBy() публичный Метод

Filters the current collection by a field, operator and search value
public filterBy ( ) : Collection
Результат Collection

findBy() публичный Метод

Find a single item by a key and value pair
public findBy ( string $key, mixed $value ) : mixed
$key string
$value mixed
Результат mixed

first() публичный Метод

Returns the first element from the array
public first ( ) : mixed
Результат mixed

flip() публичный Метод

Returns the array in reverse order
public flip ( ) : Collection
Результат Collection

get() публичный Метод

public get ( $key, $default = null )

group() публичный Метод

Groups the collection by a given callback
public group ( callable $callback ) : object
$callback callable
Результат object A new collection with an item for each group and a subcollection in each group

groupBy() публичный Метод

Groups the collection by a given field
public groupBy ( string $field, $i = true ) : object
$field string
Результат object A new collection with an item for each group and a subcollection in each group

has() публичный Метод

Checks if an element is in the collection by key.
public has ( string $key ) : boolean
$key string
Результат boolean

indexOf() публичный Метод

Tries to find the index number for the given element
public indexOf ( mixed $needle ) : mixed
$needle mixed the element to search for
Результат mixed the name of the key or false

keyOf() публичный Метод

Tries to find the key for the given element
public keyOf ( mixed $needle ) : mixed
$needle mixed the element to search for
Результат mixed the name of the key or false

keys() публичный Метод

Returns an array of all keys in the collection
public keys ( ) : array
Результат array

last() публичный Метод

Returns the last element from the array
public last ( ) : mixed
Результат mixed

limit() публичный Метод

Returns a new collection with a limited number of elements
public limit ( integer $limit ) : Collection
$limit integer The number of elements to return
Результат Collection

map() публичный Метод

Map a function to each item in the collection
public map ( function $callback ) : Collection
$callback function
Результат Collection

merge() публичный Метод

Returns a new combined collection
public merge ( $collection2 ) : Collection
Результат Collection

not() публичный Метод

Returns a new collection without the given element(s)
public not ( ) : Collection
Результат Collection

nth() публичный Метод

Returns the nth element from the array
public nth ( $n ) : mixed
Результат mixed

offset() публичный Метод

Returns a new collection starting from the given offset
public offset ( integer $offset ) : Collection
$offset integer The index to start from
Результат Collection

paginate() публичный Метод

Add pagination
public paginate ( integer $limit, array $options = [] ) : object
$limit integer the number of items per page
$options array and optional array with options for the pagination class
Результат object a sliced set of data

pagination() публичный Метод

Get the previously added pagination object
public pagination ( ) : object
Результат object

pluck() публичный Метод

Extracts all values for a single field into a new array
public pluck ( string $field, $split = null, $unique = false ) : array
$field string
Результат array

prepend() публичный Метод

Prepends an element to the data array
public prepend ( string $key, mixed $object ) : Collection
$key string
$object mixed
Результат Collection

set() публичный Метод

public set ( $key, $value )

shuffle() публичный Метод

Shuffle all elements in the array
public shuffle ( ) : object
Результат object a new shuffled collection

slice() публичный Метод

Returns a slice of the collection
public slice ( integer $offset = null, integer $limit = null ) : Collection
$offset integer The optional index to start the slice from
$limit integer The optional number of elements to return
Результат Collection

sortBy() публичный Метод

Sorts the collection by any number of fields
public sortBy ( ) : Collection
Результат Collection

toArray() публичный Метод

Converts the current object into an array
public toArray ( $callback = null ) : array
Результат array

toJson() публичный Метод

Converts the current object into a json string
public toJson ( ) : string
Результат string

without() публичный Метод

Returns a new collection without the given element(s)
public without ( ) : Collection
Результат Collection

Описание свойств

$filters публичное статическое свойство

public static $filters

$pagination защищенное свойство

protected $pagination