Class Guzzle\Common\Collection

InheritanceGuzzle\Common\Collection
ImplementsArrayAccess, Countable, Guzzle\Common\ToArrayInterface, IteratorAggregate
SubclassesGuzzle\Http\QueryString, Guzzle\Service\Command\AbstractCommand, Guzzle\Service\Command\ClosureCommand, Guzzle\Service\Command\OperationCommand, Guzzle\Service\Resource\Model

Key value pair collection object

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$data array Data associated with the object. Guzzle\Common\Collection

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() Guzzle\Common\Collection
add() Add a value to a key. If a key of the same name has already been added, the key value will be converted into an array and the new value will be pushed to the end of the array. Guzzle\Common\Collection
clear() Removes all key value pairs Guzzle\Common\Collection
count() Guzzle\Common\Collection
filter() Iterates over each key value pair in the collection passing them to the Closure. If the Closure function returns true, the current value from input is returned into the result Collection. The Closure must accept three parameters: (string) $key, (string) $value and return Boolean TRUE or FALSE for each value. Guzzle\Common\Collection
fromConfig() Create a new collection from an array, validate the keys, and add default values where missing Guzzle\Common\Collection
get() Get a specific key value. Guzzle\Common\Collection
getAll() Get all or a subset of matching key value pairs Guzzle\Common\Collection
getIterator() Guzzle\Common\Collection
getKeys() Get all keys in the collection Guzzle\Common\Collection
getPath() Gets a value from the collection using an array path (e.g. foo/baz/bar would retrieve bar from two nested arrays) Allows for wildcard searches which recursively combine matches up to the level at which the wildcard occurs. This can be useful for accepting any key of a sub-array and combining matching keys from each diverging path. Guzzle\Common\Collection
hasKey() Returns whether or not the specified key is present. Guzzle\Common\Collection
hasValue() Checks if any keys contains a certain value Guzzle\Common\Collection
inject() Inject configuration settings into an input string Guzzle\Common\Collection
keySearch() Case insensitive search the keys in the collection Guzzle\Common\Collection
map() Returns a Collection containing all the elements of the collection after applying the callback function to each one. The Closure should accept three parameters: (string) $key, (string) $value, (array) $context and return a modified value Guzzle\Common\Collection
merge() Add and merge in a Collection or array of key value pair data. Guzzle\Common\Collection
offsetExists() Guzzle\Common\Collection
offsetGet() Guzzle\Common\Collection
offsetSet() Guzzle\Common\Collection
offsetUnset() Guzzle\Common\Collection
overwriteWith() Over write key value pairs in this collection with all of the data from an array or collection. Guzzle\Common\Collection
remove() Remove a specific key value pair Guzzle\Common\Collection
replace() Replace the data of the object with the value of an array Guzzle\Common\Collection
set() Set a key value pair Guzzle\Common\Collection
setPath() Set a value into a nested array key. Keys will be created as needed to set the value. Guzzle\Common\Collection
toArray() Guzzle\Common\Collection

Property Details

$data protected property

Data associated with the object.

protected array $data null

Method Details

__construct() public method

public void __construct ( array $data = [] )
$data array

Associative array of data to set

add() public method

Add a value to a key. If a key of the same name has already been added, the key value will be converted into an array and the new value will be pushed to the end of the array.

public Guzzle\Common\Collection add ( $key, $value )
$key string

Key to add

$value mixed

Value to add to the key

return Guzzle\Common\Collection

Returns a reference to the object.

clear() public method

Removes all key value pairs

public Guzzle\Common\Collection clear ( )
count() public method

public void count ( )
filter() public method

Iterates over each key value pair in the collection passing them to the Closure. If the Closure function returns true, the current value from input is returned into the result Collection. The Closure must accept three parameters: (string) $key, (string) $value and return Boolean TRUE or FALSE for each value.

public Guzzle\Common\Collection filter ( Closure $closure, $static true )
$closure Closure

Closure evaluation function

$static bool

Set to TRUE to use the same class as the return rather than returning a Collection

fromConfig() public static method

Create a new collection from an array, validate the keys, and add default values where missing

public static self fromConfig ( array $config = [], array $defaults = [], array $required = [] )
$config array

Configuration values to apply.

$defaults array

Default parameters

$required array

Required parameter names

throws Guzzle\Common\Exception\InvalidArgumentException

if a parameter is missing

get() public method

Get a specific key value.

public mixed|null get ( $key )
$key string

Key to retrieve.

return mixed|null

Value of the key or NULL

getAll() public method

Get all or a subset of matching key value pairs

public array getAll ( array $keys null )
$keys array

Pass an array of keys to retrieve only a subset of key value pairs

return array

Returns an array of all matching key value pairs

getIterator() public method

public void getIterator ( )
getKeys() public method

Get all keys in the collection

public array getKeys ( )
getPath() public method

Gets a value from the collection using an array path (e.g. foo/baz/bar would retrieve bar from two nested arrays) Allows for wildcard searches which recursively combine matches up to the level at which the wildcard occurs. This can be useful for accepting any key of a sub-array and combining matching keys from each diverging path.

public mixed|null getPath ( $path, $separator '/', $data null )
$path string

Path to traverse and retrieve a value from

$separator string

Character used to add depth to the search

$data mixed

Optional data to descend into (used when wildcards are encountered)

hasKey() public method

Returns whether or not the specified key is present.

public bool hasKey ( $key )
$key string

The key for which to check the existence.

hasValue() public method

Checks if any keys contains a certain value

public mixed hasValue ( $value )
$value string

Value to search for

return mixed

Returns the key if the value was found FALSE if the value was not found.

inject() public method

Inject configuration settings into an input string

public string inject ( $input )
$input string

Input to inject

keySearch() public method

Case insensitive search the keys in the collection

public bool|string keySearch ( $key )
$key string

Key to search for

return bool|string

Returns false if not found, otherwise returns the key

map() public method

Returns a Collection containing all the elements of the collection after applying the callback function to each one. The Closure should accept three parameters: (string) $key, (string) $value, (array) $context and return a modified value

public Guzzle\Common\Collection map ( Closure $closure, array $context = [], $static true )
$closure Closure

Closure to apply

$context array

Context to pass to the closure

$static bool

Set to TRUE to use the same class as the return rather than returning a Collection

merge() public method

Add and merge in a Collection or array of key value pair data.

public Guzzle\Common\Collection merge ( $data )
$data Guzzle\Common\Collection|array

Associative array of key value pair data

return Guzzle\Common\Collection

Returns a reference to the object.

offsetExists() public method

public void offsetExists ( $offset )
$offset
offsetGet() public method

public void offsetGet ( $offset )
$offset
offsetSet() public method

public void offsetSet ( $offset, $value )
$offset
$value
offsetUnset() public method

public void offsetUnset ( $offset )
$offset
overwriteWith() public method

Over write key value pairs in this collection with all of the data from an array or collection.

public self overwriteWith ( $data )
$data array|Traversable

Values to override over this config

remove() public method

Remove a specific key value pair

public Guzzle\Common\Collection remove ( $key )
$key string

A key to remove

replace() public method

Replace the data of the object with the value of an array

public Guzzle\Common\Collection replace ( array $data )
$data array

Associative array of data

return Guzzle\Common\Collection

Returns a reference to the object

set() public method

Set a key value pair

public Guzzle\Common\Collection set ( $key, $value )
$key string

Key to set

$value mixed

Value to set

return Guzzle\Common\Collection

Returns a reference to the object

setPath() public method

Set a value into a nested array key. Keys will be created as needed to set the value.

public self setPath ( $path, $value )
$path string

Path to set

$value mixed

Value to set at the key

throws Guzzle\Common\Exception\RuntimeException

when trying to setPath using a nested path that travels through a scalar value

toArray() public method

public void toArray ( )