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]
파일 보기 프로젝트 열기: getkirby/toolkit 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$filters

보호된 프로퍼티들

프로퍼티 타입 설명
$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