trait ManagesItemsTrait

Manages complex, nested data

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, array $options = 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

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

Get a single item

getIfExists($alias)

Return an item if it exist

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()

$this
protect($item)

Guard an alias from being modified

$this
loadDefaults(array $defaults)

Merge a set of defaults with the current items

string
getItemsName()

Returns the name of the property that holds data items

$this
setItemsName($nameOfItemsRepository)

Sets the name of the property that holds data items

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

Details

at line line 44
$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

at line line 72
$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

at line line 93
$this add(string $alias, mixed $item = null, array $options = 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
array $options THIS IS NOT USED HERE

Return Value

$this

at line line 155
$this set(string $alias, null $item = null)

Updates an item

Parameters

string $alias
null $item

Return Value

$this

at line line 168
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

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

Get a single item

Note: When editing, update ManagesIocTrait::getRaw()

Parameters

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

Return Value

mixed

Exceptions

ItemNotFoundException If item not found

at line line 214
mixed getRaw(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

at line line 235
NoItemFoundMessage getIfExists($alias)

Return an item if it exist

Parameters

$alias

Return Value

NoItemFoundMessage

at line line 256
NoItemFoundMessage getIfHas($alias)

Return an item if it exist Alias of getIfExists()

Parameters

$alias

Return Value

NoItemFoundMessage

at line line 266
array getAll()

Return all items as array

Return Value

array

at line line 277
array all()

Return all items as array Alias of getAll()

Return Value

array

at line line 288
bool exists($alias)

Confirm or deny that an item exists

Parameters

$alias

Return Value

bool

at line line 309
bool has($alias)

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

Parameters

$alias

Return Value

bool

at line line 319
boolean isEmpty()

Confirm that manager has no items

Return Value

boolean

at line line 331
$this remove($alias)

Deletes an item

Parameters

$alias

Return Value

$this

at line line 352
$this clear()

Clear the manager

Return Value

$this

at line line 366
mixed reset(array $items)

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

Parameters

array $items

Return Value

mixed

at line line 376
$this protect($item)

Guard an alias from being modified

Parameters

$item

Return Value

$this

at line line 387
$this loadDefaults(array $defaults)

Merge a set of defaults with the current items

Parameters

array $defaults

Return Value

$this

at line line 397
string getItemsName()

Returns the name of the property that holds data items

Return Value

string

at line line 407
$this setItemsName($nameOfItemsRepository)

Sets the name of the property that holds data items

Parameters

$nameOfItemsRepository

Return Value

$this

at line line 419
string toJson(int $options)

Get the collection of items as JSON.

Parameters

int $options

Return Value

string

at line line 428
string __toString()

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

Return Value

string