trait CollectionTrait

Access Deeply nested manager items through magic methods

MUST be used with ManagesItemsTrait

Traits

Properties

static $RETURN_ARRAY
static $RETURN_COLLECTION
static $MODIFY_MANIFEST
bool $useCollections Configuration: do we want to return Collections from get() and getAll()?

Methods

$this
initManager(array $items = null)

Initializes a new manager instance.

$this
hydrate($data, bool $append = false)

Hydrate with external data, optionally append

$this
add(string $alias, mixed $item = null)

Adds a single item.

$this
set(string $alias, null $item = null)

Updates an item

int
push(string $alias, mixed $value, null|mixed $other = null)

Push a value or values onto the end of an array inside manager

mixed
get(string $alias, string $fallback = '_michaels_no_fallback')

Get a single item

NoItemFoundMessage
getIfExists($alias)

Return an item if it exist

NoItemFoundMessage
getIfHas($alias)

Return an item if it exist Alias of getIfExists()

array
getAll()

Return all items as array

array
all()

Return all items as array Alias of getAll()

bool
exists($alias)

Confirm or deny that an item exists

bool
has($alias)

Confirm or deny that an item exists Alias of exists()

boolean
isEmpty()

Confirm that manager has no items

$this
remove($alias)

Deletes an item

$this
clear()

Clear the manager

mixed
reset(array $items)

Reset the manager with an array of items Alias of initManager()

string
toJson(int $options)

Get the collection of items as JSON.

string
__toString()

When manager instance is used as a string, return json of items

ArrayImitator
toCollection($value)

Converts an array to a collection if value is arrayable and config is set

bool
wantsCollections()

Does this instance want collections returned from get() and getAll()?

mixed
__call(string $method, array $arguments)

Invokes when calling a method on the Collection API

Details

in DependsOnManagesItemsTrait at line line 15
abstract $this initManager(array $items = null)

Initializes a new manager instance.

This is useful for implementations that have their own __construct method This is an alias for reset()

Parameters

array $items

Return Value

$this

in DependsOnManagesItemsTrait at line line 24
abstract $this hydrate($data, bool $append = false)

Hydrate with external data, optionally append

Parameters

$data string The data to be hydrated into the manager
bool $append When true, data will be appended to the current set

Return Value

$this

in DependsOnManagesItemsTrait at line line 35
abstract $this add(string $alias, mixed $item = null)

Adds a single item.

Allow for dot notation (one.two.three) and item nesting.

Parameters

string $alias Key to be stored
mixed $item Value to be stored

Return Value

$this

in DependsOnManagesItemsTrait at line line 45
abstract $this set(string $alias, null $item = null)

Updates an item

Parameters

string $alias
null $item

Return Value

$this

in DependsOnManagesItemsTrait at line line 55
abstract int push(string $alias, mixed $value, null|mixed $other = null)

Push a value or values onto the end of an array inside manager

Parameters

string $alias The level of nested data
mixed $value The first value to append
null|mixed $other Optional other values to apend

Return Value

int Number of items pushed

Exceptions

ItemNotFoundException If pushing to unset array

in DependsOnManagesItemsTrait at line line 65
abstract mixed get(string $alias, string $fallback = '_michaels_no_fallback')

Get a single item

Parameters

string $alias
string $fallback Defaults to 'michaelsno_fallback' so null can be a fallback

Return Value

mixed

Exceptions

ItemNotFoundException If item not found

in DependsOnManagesItemsTrait at line line 72
abstract NoItemFoundMessage getIfExists($alias)

Return an item if it exist

Parameters

$alias

Return Value

NoItemFoundMessage

in DependsOnManagesItemsTrait at line line 81
abstract NoItemFoundMessage getIfHas($alias)

Return an item if it exist Alias of getIfExists()

Parameters

$alias

Return Value

NoItemFoundMessage

in DependsOnManagesItemsTrait at line line 88
abstract array getAll()

Return all items as array

Return Value

array

in DependsOnManagesItemsTrait at line line 95
abstract array all()

Return all items as array Alias of getAll()

Return Value

array

in DependsOnManagesItemsTrait at line line 103
abstract bool exists($alias)

Confirm or deny that an item exists

Parameters

$alias

Return Value

bool

in DependsOnManagesItemsTrait at line line 112
abstract bool has($alias)

Confirm or deny that an item exists Alias of exists()

Parameters

$alias

Return Value

bool

in DependsOnManagesItemsTrait at line line 118
abstract boolean isEmpty()

Confirm that manager has no items

Return Value

boolean

in DependsOnManagesItemsTrait at line line 126
abstract $this remove($alias)

Deletes an item

Parameters

$alias

Return Value

$this

in DependsOnManagesItemsTrait at line line 132
abstract $this clear()

Clear the manager

Return Value

$this

in DependsOnManagesItemsTrait at line line 141
abstract mixed reset(array $items)

Reset the manager with an array of items Alias of initManager()

Parameters

array $items

Return Value

mixed

in DependsOnManagesItemsTrait at line line 149
abstract string toJson(int $options)

Get the collection of items as JSON.

Parameters

int $options

Return Value

string

in DependsOnManagesItemsTrait at line line 155
abstract string __toString()

When manager instance is used as a string, return json of items

Return Value

string

at line line 36
ArrayImitator toCollection($value)

Converts an array to a collection if value is arrayable and config is set

Parameters

$value

Return Value

ArrayImitator

at line line 49
bool wantsCollections()

Does this instance want collections returned from get() and getAll()?

Return Value

bool

at line line 69
mixed __call(string $method, array $arguments)

Invokes when calling a method on the Collection API

This method simply decides how to handle the method call. 1. The class is using the ChainsNestedItemsTrait and Collection API does NOT contain the method Let ChainsNestedItemsTrait do its thing 2. The Collection API DOES contain the method Pass the method call along to the third party Collection API 3. The method does not exist on the class or in the Collection API Throw an Exception

Parameters

string $method Name of the method
array $arguments Arguments passed along

Return Value

mixed

Exceptions

BadMethodCallException