- \Somnambulist\Components\Collection\Behaviours\Query\RemoveEmpty
- \Somnambulist\Components\Collection\Behaviours\Query\FilterValues
- \Somnambulist\Components\Collection\Behaviours\Query\Extract
- \Somnambulist\Components\Collection\Behaviours\Query\Keys
- \Somnambulist\Components\Collection\Behaviours\Query\Values
- \Somnambulist\Components\Collection\Behaviours\Query\GetValue
- \Somnambulist\Components\Collection\Behaviours\Query\All
- \Somnambulist\Components\Collection\Behaviours\Query\Unique
- \Somnambulist\Components\Collection\Behaviours\Query\HasKey
- \Somnambulist\Components\Collection\Behaviours\Query\Value
- \Somnambulist\Components\Collection\Behaviours\Query\GetValueWithDotNotation
- \Somnambulist\Components\Collection\Behaviours\Query\Find
- \Somnambulist\Components\Collection\Behaviours\Query\FilterByKey
- \Somnambulist\Components\Collection\Behaviours\Query\Sort
- \Somnambulist\Components\Collection\Behaviours\Query\RandomValue
- \Somnambulist\Components\Collection\Behaviours\Query\Last
- \Somnambulist\Components\Collection\Behaviours\Query\HasKeyWithDotNotation
- \Somnambulist\Components\Collection\Behaviours\Query\Contains
- \Somnambulist\Components\Collection\Behaviours\Query\First
- \Somnambulist\Components\Collection\Behaviours\Query\RemoveNulls
Trait RemoveEmpty
Visibility | Function |
---|---|
public | removeEmpty(array $empty=array()) : \Somnambulist\Components\Collection\Collection/static Removes values that are matched as empty through an equivalence check |
Trait FilterValues
Visibility | Function |
---|---|
public | filter(\null $criteria=null, \mixed $test=null) : \Somnambulist\Components\Collection\Collection/static Filters the collection using the callback The callback receives both the value and the key. If a key name and value are given, will filter all items at that key with the value provided. Key can be an object method, property or array key. |
public | matching(\callable $criteria) : \Somnambulist\Components\Collection\Collection/static Alias of filter but requires the callable |
public | notMatching(\callable $criteria) : \Somnambulist\Components\Collection\Collection/static Returns items that do NOT pass the test callable The callable is wrapped and checked if it returns false. For example: your callable is a closure that return Str::contains($value->name(), 'bob'); , then notMatching will return all items that do not match that criteria. |
public | reject(\callable $criteria) : \Somnambulist\Components\Collection\Collection/static Alias of notMatching |
Trait Extract
Visibility | Function |
---|---|
public | extract(\string $element, \string $withKey=null) : \Somnambulist\Components\Collection\Collection/static Extract the values for all items with an element named $element, optionally indexed by $withKey |
Trait Keys
Visibility | Function |
---|---|
public | keys(\mixed $value=null) : \Somnambulist\Components\Collection\Collection/static Returns a new collection containing just the keys as values If a value is provided, then all keys with this value will be returned. Searching is always by strict match. |
Trait Values
Visibility | Function |
---|---|
public | values() : \Somnambulist\Components\Collection\Collection/static Returns a new collection containing just the values without the previous keys |
Trait GetValue
Visibility | Function |
---|---|
public | get(int/string/\int $key, \mixed $default=null) : mixed Get the value at the specified key, if the KEY does NOT exist, return the default Note: if the key is null or false, the value will be returned. If you must have a non falsey value, use {@link value()} instead. |
Trait All
Visibility | Function |
---|---|
public | all() : array Returns the underlying collection array |
Trait Unique
Visibility | Function |
---|---|
public | unique(\int $type=2) : \Somnambulist\Components\Collection\Collection/static Creates a new Collection containing only unique values |
Trait HasKey
Visibility | Function |
---|---|
public | has(mixed $key) : bool Returns true if the key(s) all exist in the collection |
public | hasValueFor(int/string/\int $key) : boolean Returns true if the specified key exists in the Collection and is not empty Empty in this case is not an empty string, null, zero or false. It should not be used to check for null or boolean values. |
Trait Value
Visibility | Function |
---|---|
public | value(int/string/\int $key, \mixed $default=null) : mixed Returns the value for the specified key or if there is no value, returns the default Default can be a callable (closure) that will be executed. This method differs to |
Trait GetValueWithDotNotation
Visibility | Function |
---|---|
public | get(int/string/\int $key, \mixed $default=null) : mixed Get the value at the specified key using dot notation This trait replaces the standard CanGetKey with one that can cascade into the collection items e.g. user.*.town would look for a user key first, then any elements with a town property / key. The item(s) would then be returned. If the key is not found, then default will be returned that can be a closure. Note: if the key exists it's VALUE is returned! This means it could be null / false. If you need to ensure a particular value, use {@link value()} instead. |
Trait Find
Visibility | Function |
---|---|
public | find(callable/mixed/\string $criteria) : mixed Finds the first item matching the criteria |
public | findLast(callable/mixed/\string $criteria) : mixed Finds the last item matching the criteria |
Trait FilterByKey
Visibility | Function |
---|---|
public | except(mixed $ignore) : \Somnambulist\Components\Collection\Collection/static Alias of without() |
public | hasAnyOf(mixed $key) : bool Returns true if any of the keys are present in the collection |
public | hasNoneOf(mixed $key) : bool Returns true if NONE of the keys are present in the collection |
public | keysMatching(string/callable/\string $criteria) : \Somnambulist\Components\Collection\Collection/static Find keys matching the criteria, returning a new collection of the keys |
public | only(mixed $keys) : \Somnambulist\Components\Collection\Collection/static Alias of with() |
public | with(mixed $keys) : \Somnambulist\Components\Collection\Collection/static Returns a new collection with only the specified keys |
public | without(mixed $keys) : \Somnambulist\Components\Collection\Collection/static Returns a new collection WITHOUT the specified keys |
Trait Sort
Visibility | Function |
---|---|
public | sort(string/callable/\string $callable) : \Somnambulist\Components\Collection\Collection/static Sort the Collection by a user defined function, preserves key association |
public | sortBy(\string $type, \string $dir='asc' , \int $comparison=2) : \Somnambulist\Components\Collection\Collection/staticSort the collection by value or key ordered asc (A-Z) or desc (Z-A) |
Trait RandomValue
Visibility | Function |
---|---|
public | random() : mixed Shuffles the collection and picks the first element from it |
Trait Last
Visibility | Function |
---|---|
public | last() : mixed Returns the last element of the Collection or null if empty |
Trait HasKeyWithDotNotation
Visibility | Function |
---|---|
public | has(mixed $key) : bool Return true if the key(s) exist using dot notation This trait replaces the standard HasKey with one that can cascade into the collection items e.g. user.*.town would look for a user key first, then any elements with a town property / key. If any element has that key, true is returned. If no items match, then false is returned. Note: will return true for null/false key checks and properties. |
public | hasValueFor(int/string/\int $key) : boolean Returns true if the specified key exists in the Collection and is not empty Empty in this case is not an empty string, null, zero or false. It should not be used to check for null or boolean values. |
Trait Contains
Visibility | Function |
---|---|
public | contains(\mixed $value) : bool Returns true if value is in the collection |
public | doesNotContain(mixed $value) : void |
public | doesNotInclude(\mixed $value) : bool Alias of doesNotContain |
public | includes(\mixed $value) : bool Alias of contains |
Trait First
Visibility | Function |
---|---|
public | first() : mixed Returns the first element from the collection; or null if empty |
Trait RemoveNulls
Visibility | Function |
---|---|
public | removeNulls() : \Somnambulist\Components\Collection\Collection/static Removes any null items from the Collection, returning a new collection |