PHP Класс FOF30\Utils\Collection

Наследование: implements ArrayAcces\ArrayAccess, implements Countabl\Countable, implements IteratorAggregat\IteratorAggregate, implements JsonSerializabl\JsonSerializable
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$items array The items contained in the collection.

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

Метод Описание
__construct ( array $items = [] ) Create a new collection.
__toString ( ) : string Convert the collection to its string representation.
all ( ) : array Get all of the items in the collection.
collapse ( ) : Collection Collapse the collection items into a single array.
count ( ) : integer Count the number of items in the collection.
diff ( Collection | array $items ) : Collection Diff the collection with the given items.
each ( Closure $callback ) : Collection Execute a callback over each item.
fetch ( string $key ) : Collection Fetch a nested element of the collection.
filter ( Closure $callback ) : Collection Run a filter over each of the items.
first ( Closure $callback = null, mixed $default = null ) : mixed | null Get the first item from the collection.
flatten ( ) : array Get a flattened array of the items in the collection.
forget ( mixed $key ) : void Remove an item from the collection by key.
get ( mixed $key, mixed $default = null ) : mixed Get an item from the collection by key.
getCachingIterator ( integer $flags = CachingIterator::CALL_TOSTRING ) : CachingIterator Get a CachingIterator instance.
getIterator ( ) : ArrayIterator Get an iterator for the items.
groupBy ( callable | string $groupBy ) : Collection Group an associative array by a field or Closure value.
has ( mixed $key ) : boolean Determine if an item exists in the collection by key.
implode ( string $value, string $glue = null ) : string Concatenate values of a given key as a string.
intersect ( Collection | array $items ) : Collection Intersect the collection with the given items.
isEmpty ( ) : boolean Determine if the collection is empty or not.
jsonSerialize ( ) : array Convert the object into something JSON serializable.
last ( ) : mixed | null Get the last item from the collection.
lists ( string $value, string $key = null ) : array Get an array with the values of a given key.
make ( mixed $items ) : static Create a new collection instance if the value isn't one already.
map ( Closure $callback ) : Collection Run a map over each of the items.
merge ( Collection | array $items ) : Collection Merge the collection with the given items.
offsetExists ( mixed $key ) : boolean Determine if an item exists at an offset.
offsetGet ( mixed $key ) : mixed Get an item at a given offset.
offsetSet ( mixed $key, mixed $value ) : void Set the item at a given offset.
offsetUnset ( string $key ) : void Unset the item at a given offset.
pop ( ) : mixed | null Get and remove the last item from the collection.
prepend ( mixed $value ) : void Push an item onto the beginning of the collection.
push ( mixed $value ) : void Push an item onto the end of the collection.
put ( mixed $key, mixed $value ) : void Put an item in the collection by key.
random ( integer $amount = 1 ) : mixed Get one or more items randomly from the collection.
reduce ( callable $callback, mixed $initial = null ) : mixed Reduce the collection to a single value.
reset ( ) : Collection Resets the Collection (removes all items)
reverse ( ) : Collection Reverse items order.
shift ( ) : mixed | null Get and remove the first item from the collection.
slice ( integer $offset, integer $length = null, boolean $preserveKeys = false ) : Collection Slice the underlying collection array.
sort ( Closure $callback ) : Collection Sort through each item with a callback.
sortBy ( Closure | string $callback, integer $options = SORT_REGULAR, boolean $descending = false ) : Collection Sort the collection using the given Closure.
sortByDesc ( Closure | string $callback, integer $options = SORT_REGULAR ) : Collection Sort the collection in descending order using the given Closure.
splice ( integer $offset, integer $length, mixed $replacement = [] ) : Collection Splice portion of the underlying collection array.
sum ( Closure | string $callback ) : mixed Get the sum of the given values.
take ( integer $limit = null ) : Collection Take the first or last {$limit} items.
toArray ( ) : array Get the collection of items as a plain array.
toJson ( integer $options ) : string Get the collection of items as JSON.
transform ( callable $callback ) : Collection Transform each item in the collection using a callback.
unique ( ) : Collection Return only unique items from the collection array.
values ( ) : Collection Reset the keys on the underlying array.

Защищенные методы

Метод Описание
valueRetriever ( string $value ) : Closure Get a value retrieving callback.

Приватные методы

Метод Описание
getArrayableItems ( Collection | array $items ) : array Results array of items from Collection.

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

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

Create a new collection.
public __construct ( array $items = [] )
$items array

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

Convert the collection to its string representation.
public __toString ( ) : string
Результат string

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

Get all of the items in the collection.
public all ( ) : array
Результат array

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

Collapse the collection items into a single array.
public collapse ( ) : Collection
Результат Collection

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

Count the number of items in the collection.
public count ( ) : integer
Результат integer

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

Diff the collection with the given items.
public diff ( Collection | array $items ) : Collection
$items Collection | array
Результат Collection

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

Execute a callback over each item.
public each ( Closure $callback ) : Collection
$callback Closure
Результат Collection

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

Fetch a nested element of the collection.
public fetch ( string $key ) : Collection
$key string
Результат Collection

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

Run a filter over each of the items.
public filter ( Closure $callback ) : Collection
$callback Closure
Результат Collection

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

Get the first item from the collection.
public first ( Closure $callback = null, mixed $default = null ) : mixed | null
$callback Closure
$default mixed
Результат mixed | null

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

Get a flattened array of the items in the collection.
public flatten ( ) : array
Результат array

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

Remove an item from the collection by key.
public forget ( mixed $key ) : void
$key mixed
Результат void

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

Get an item from the collection by key.
public get ( mixed $key, mixed $default = null ) : mixed
$key mixed
$default mixed
Результат mixed

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

Get a CachingIterator instance.
public getCachingIterator ( integer $flags = CachingIterator::CALL_TOSTRING ) : CachingIterator
$flags integer Caching iterator flags
Результат CachingIterator

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

Get an iterator for the items.
public getIterator ( ) : ArrayIterator
Результат ArrayIterator

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

Group an associative array by a field or Closure value.
public groupBy ( callable | string $groupBy ) : Collection
$groupBy callable | string
Результат Collection

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

Determine if an item exists in the collection by key.
public has ( mixed $key ) : boolean
$key mixed
Результат boolean

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

Concatenate values of a given key as a string.
public implode ( string $value, string $glue = null ) : string
$value string
$glue string
Результат string

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

Intersect the collection with the given items.
public intersect ( Collection | array $items ) : Collection
$items Collection | array
Результат Collection

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

Determine if the collection is empty or not.
public isEmpty ( ) : boolean
Результат boolean

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

Convert the object into something JSON serializable.
public jsonSerialize ( ) : array
Результат array

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

Get the last item from the collection.
public last ( ) : mixed | null
Результат mixed | null

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

Get an array with the values of a given key.
public lists ( string $value, string $key = null ) : array
$value string
$key string
Результат array

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

Create a new collection instance if the value isn't one already.
public static make ( mixed $items ) : static
$items mixed
Результат static

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

Run a map over each of the items.
public map ( Closure $callback ) : Collection
$callback Closure
Результат Collection

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

Merge the collection with the given items.
public merge ( Collection | array $items ) : Collection
$items Collection | array
Результат Collection

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

Determine if an item exists at an offset.
public offsetExists ( mixed $key ) : boolean
$key mixed
Результат boolean

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

Get an item at a given offset.
public offsetGet ( mixed $key ) : mixed
$key mixed
Результат mixed

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

Set the item at a given offset.
public offsetSet ( mixed $key, mixed $value ) : void
$key mixed
$value mixed
Результат void

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

Unset the item at a given offset.
public offsetUnset ( string $key ) : void
$key string
Результат void

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

Get and remove the last item from the collection.
public pop ( ) : mixed | null
Результат mixed | null

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

Push an item onto the beginning of the collection.
public prepend ( mixed $value ) : void
$value mixed
Результат void

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

Push an item onto the end of the collection.
public push ( mixed $value ) : void
$value mixed
Результат void

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

Put an item in the collection by key.
public put ( mixed $key, mixed $value ) : void
$key mixed
$value mixed
Результат void

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

Get one or more items randomly from the collection.
public random ( integer $amount = 1 ) : mixed
$amount integer
Результат mixed

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

Reduce the collection to a single value.
public reduce ( callable $callback, mixed $initial = null ) : mixed
$callback callable
$initial mixed
Результат mixed

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

Resets the Collection (removes all items)
public reset ( ) : Collection
Результат Collection

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

Reverse items order.
public reverse ( ) : Collection
Результат Collection

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

Get and remove the first item from the collection.
public shift ( ) : mixed | null
Результат mixed | null

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

Slice the underlying collection array.
public slice ( integer $offset, integer $length = null, boolean $preserveKeys = false ) : Collection
$offset integer
$length integer
$preserveKeys boolean
Результат Collection

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

Sort through each item with a callback.
public sort ( Closure $callback ) : Collection
$callback Closure
Результат Collection

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

Sort the collection using the given Closure.
public sortBy ( Closure | string $callback, integer $options = SORT_REGULAR, boolean $descending = false ) : Collection
$callback Closure | string
$options integer
$descending boolean
Результат Collection

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

Sort the collection in descending order using the given Closure.
public sortByDesc ( Closure | string $callback, integer $options = SORT_REGULAR ) : Collection
$callback Closure | string
$options integer
Результат Collection

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

Splice portion of the underlying collection array.
public splice ( integer $offset, integer $length, mixed $replacement = [] ) : Collection
$offset integer
$length integer
$replacement mixed
Результат Collection

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

Get the sum of the given values.
public sum ( Closure | string $callback ) : mixed
$callback Closure | string
Результат mixed

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

Take the first or last {$limit} items.
public take ( integer $limit = null ) : Collection
$limit integer
Результат Collection

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

Get the collection of items as a plain array.
public toArray ( ) : array
Результат array

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

Get the collection of items as JSON.
public toJson ( integer $options ) : string
$options integer
Результат string

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

Transform each item in the collection using a callback.
public transform ( callable $callback ) : Collection
$callback callable
Результат Collection

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

Return only unique items from the collection array.
public unique ( ) : Collection
Результат Collection

valueRetriever() защищенный Метод

Get a value retrieving callback.
protected valueRetriever ( string $value ) : Closure
$value string
Результат Closure

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

Reset the keys on the underlying array.
public values ( ) : Collection
Результат Collection

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

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

The items contained in the collection.
protected array $items
Результат array