PHP Class FOF30\Utils\Collection

Inheritance: implements ArrayAcces\ArrayAccess, implements Countabl\Countable, implements IteratorAggregat\IteratorAggregate, implements JsonSerializabl\JsonSerializable
Afficher le fichier Open project: akeeba/fof Class Usage Examples

Protected Properties

Свойство Type Description
$items array The items contained in the collection.

Méthodes publiques

Méthode Description
__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.

Méthodes protégées

Méthode Description
valueRetriever ( string $value ) : Closure Get a value retrieving callback.

Private Methods

Méthode Description
getArrayableItems ( Collection | array $items ) : array Results array of items from Collection.

Method Details

__construct() public méthode

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

__toString() public méthode

Convert the collection to its string representation.
public __toString ( ) : string
Résultat string

all() public méthode

Get all of the items in the collection.
public all ( ) : array
Résultat array

collapse() public méthode

Collapse the collection items into a single array.
public collapse ( ) : Collection
Résultat Collection

count() public méthode

Count the number of items in the collection.
public count ( ) : integer
Résultat integer

diff() public méthode

Diff the collection with the given items.
public diff ( Collection | array $items ) : Collection
$items Collection | array
Résultat Collection

each() public méthode

Execute a callback over each item.
public each ( Closure $callback ) : Collection
$callback Closure
Résultat Collection

fetch() public méthode

Fetch a nested element of the collection.
public fetch ( string $key ) : Collection
$key string
Résultat Collection

filter() public méthode

Run a filter over each of the items.
public filter ( Closure $callback ) : Collection
$callback Closure
Résultat Collection

first() public méthode

Get the first item from the collection.
public first ( Closure $callback = null, mixed $default = null ) : mixed | null
$callback Closure
$default mixed
Résultat mixed | null

flatten() public méthode

Get a flattened array of the items in the collection.
public flatten ( ) : array
Résultat array

forget() public méthode

Remove an item from the collection by key.
public forget ( mixed $key ) : void
$key mixed
Résultat void

get() public méthode

Get an item from the collection by key.
public get ( mixed $key, mixed $default = null ) : mixed
$key mixed
$default mixed
Résultat mixed

getCachingIterator() public méthode

Get a CachingIterator instance.
public getCachingIterator ( integer $flags = CachingIterator::CALL_TOSTRING ) : CachingIterator
$flags integer Caching iterator flags
Résultat CachingIterator

getIterator() public méthode

Get an iterator for the items.
public getIterator ( ) : ArrayIterator
Résultat ArrayIterator

groupBy() public méthode

Group an associative array by a field or Closure value.
public groupBy ( callable | string $groupBy ) : Collection
$groupBy callable | string
Résultat Collection

has() public méthode

Determine if an item exists in the collection by key.
public has ( mixed $key ) : boolean
$key mixed
Résultat boolean

implode() public méthode

Concatenate values of a given key as a string.
public implode ( string $value, string $glue = null ) : string
$value string
$glue string
Résultat string

intersect() public méthode

Intersect the collection with the given items.
public intersect ( Collection | array $items ) : Collection
$items Collection | array
Résultat Collection

isEmpty() public méthode

Determine if the collection is empty or not.
public isEmpty ( ) : boolean
Résultat boolean

jsonSerialize() public méthode

Convert the object into something JSON serializable.
public jsonSerialize ( ) : array
Résultat array

last() public méthode

Get the last item from the collection.
public last ( ) : mixed | null
Résultat mixed | null

lists() public méthode

Get an array with the values of a given key.
public lists ( string $value, string $key = null ) : array
$value string
$key string
Résultat array

make() public static méthode

Create a new collection instance if the value isn't one already.
public static make ( mixed $items ) : static
$items mixed
Résultat static

map() public méthode

Run a map over each of the items.
public map ( Closure $callback ) : Collection
$callback Closure
Résultat Collection

merge() public méthode

Merge the collection with the given items.
public merge ( Collection | array $items ) : Collection
$items Collection | array
Résultat Collection

offsetExists() public méthode

Determine if an item exists at an offset.
public offsetExists ( mixed $key ) : boolean
$key mixed
Résultat boolean

offsetGet() public méthode

Get an item at a given offset.
public offsetGet ( mixed $key ) : mixed
$key mixed
Résultat mixed

offsetSet() public méthode

Set the item at a given offset.
public offsetSet ( mixed $key, mixed $value ) : void
$key mixed
$value mixed
Résultat void

offsetUnset() public méthode

Unset the item at a given offset.
public offsetUnset ( string $key ) : void
$key string
Résultat void

pop() public méthode

Get and remove the last item from the collection.
public pop ( ) : mixed | null
Résultat mixed | null

prepend() public méthode

Push an item onto the beginning of the collection.
public prepend ( mixed $value ) : void
$value mixed
Résultat void

push() public méthode

Push an item onto the end of the collection.
public push ( mixed $value ) : void
$value mixed
Résultat void

put() public méthode

Put an item in the collection by key.
public put ( mixed $key, mixed $value ) : void
$key mixed
$value mixed
Résultat void

random() public méthode

Get one or more items randomly from the collection.
public random ( integer $amount = 1 ) : mixed
$amount integer
Résultat mixed

reduce() public méthode

Reduce the collection to a single value.
public reduce ( callable $callback, mixed $initial = null ) : mixed
$callback callable
$initial mixed
Résultat mixed

reset() public méthode

Resets the Collection (removes all items)
public reset ( ) : Collection
Résultat Collection

reverse() public méthode

Reverse items order.
public reverse ( ) : Collection
Résultat Collection

shift() public méthode

Get and remove the first item from the collection.
public shift ( ) : mixed | null
Résultat mixed | null

slice() public méthode

Slice the underlying collection array.
public slice ( integer $offset, integer $length = null, boolean $preserveKeys = false ) : Collection
$offset integer
$length integer
$preserveKeys boolean
Résultat Collection

sort() public méthode

Sort through each item with a callback.
public sort ( Closure $callback ) : Collection
$callback Closure
Résultat Collection

sortBy() public méthode

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
Résultat Collection

sortByDesc() public méthode

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
Résultat Collection

splice() public méthode

Splice portion of the underlying collection array.
public splice ( integer $offset, integer $length, mixed $replacement = [] ) : Collection
$offset integer
$length integer
$replacement mixed
Résultat Collection

sum() public méthode

Get the sum of the given values.
public sum ( Closure | string $callback ) : mixed
$callback Closure | string
Résultat mixed

take() public méthode

Take the first or last {$limit} items.
public take ( integer $limit = null ) : Collection
$limit integer
Résultat Collection

toArray() public méthode

Get the collection of items as a plain array.
public toArray ( ) : array
Résultat array

toJson() public méthode

Get the collection of items as JSON.
public toJson ( integer $options ) : string
$options integer
Résultat string

transform() public méthode

Transform each item in the collection using a callback.
public transform ( callable $callback ) : Collection
$callback callable
Résultat Collection

unique() public méthode

Return only unique items from the collection array.
public unique ( ) : Collection
Résultat Collection

valueRetriever() protected méthode

Get a value retrieving callback.
protected valueRetriever ( string $value ) : Closure
$value string
Résultat Closure

values() public méthode

Reset the keys on the underlying array.
public values ( ) : Collection
Résultat Collection

Property Details

$items protected_oe property

The items contained in the collection.
protected array $items
Résultat array