Properties

$objectCache

$objectCache : array<mixed,\Charcoal\Model\ModelInterface>

A store of cached objects.

Type

array<mixed,\Charcoal\Model\ModelInterface>

Methods

resetHierarchy()

resetHierarchy() : \Charcoal\Object\HierarchicalInterface

Reset this object's hierarchy.

The object's hierarchy can be rebuilt with \self::hierarchy().

Returns

\Charcoal\Object\HierarchicalInterface

Chainable

setMaster()

setMaster(mixed  $master) : \Charcoal\Object\HierarchicalInterface

Set this object's immediate parent.

Parameters

mixed $master

The object's parent (or master).

Throws

\UnexpectedValueException

The current object cannot be its own parent.

Returns

\Charcoal\Object\HierarchicalInterface

Chainable

hasMaster()

hasMaster() : boolean

Determine if this object has a direct parent.

Returns

boolean

isTopLevel()

isTopLevel() : boolean

Determine if this object is the head (top-level) of its hierarchy.

Top-level objects do not have a parent (master).

Returns

boolean

isLastLevel()

isLastLevel() : boolean

Determine if this object is the tail (last-level) of its hierarchy.

Last-level objects do not have a children.

Returns

boolean

hierarchyLevel()

hierarchyLevel() : integer

Retrieve this object's position (level) in its hierarchy.

Starts at "1" (top-level).

The level is calculated by loading all ancestors with \self::hierarchy().

Returns

integer

hasParents()

hasParents() : boolean

Determine if this object has any ancestors.

Returns

boolean

hierarchy()

hierarchy() : array

Retrieve this object's ancestors (from immediate parent to top-level).

Returns

array

invertedHierarchy()

invertedHierarchy() : array

Retrieve this object's ancestors, inverted from top-level to immediate.

Returns

array

isMasterOf()

isMasterOf(mixed  $child) : boolean

Determine if the object is the parent of the given object.

Parameters

mixed $child

The child (or ID) to match against.

Returns

boolean

recursiveIsMasterOf()

recursiveIsMasterOf(mixed  $child) : boolean

Determine if the object is a parent/ancestor of the given object.

Parameters

mixed $child

The child (or ID) to match against.

Returns

boolean

hasChildren()

hasChildren() : boolean

Get wether the object has any children at all

Returns

boolean

numChildren()

numChildren() : integer

Get the number of children directly under this object.

Returns

integer

recursiveNumChildren()

recursiveNumChildren() : integer

Get the total number of children in the entire hierarchy.

This method counts all children and sub-children, unlike numChildren() which only count 1 level.

Returns

integer

setChildren()

setChildren(array  $children) : \Charcoal\Object\HierarchicalInterface

Parameters

array $children

The children to set.

Returns

\Charcoal\Object\HierarchicalInterface

Chainable

addChild()

addChild(mixed  $child) : \Charcoal\Object\HierarchicalInterface

Parameters

mixed $child

The child object (or ident) to add.

Throws

\UnexpectedValueException

The current object cannot be its own child.

Returns

\Charcoal\Object\HierarchicalInterface

Chainable

children()

children() : array

Get the children directly under this object.

Returns

array

loadChildren()

loadChildren() : array

Returns

array

isChildOf()

isChildOf(mixed  $master) : boolean

Parameters

mixed $master

The master object (or ident) to check against.

Returns

boolean

recursiveIsChildOf()

recursiveIsChildOf(mixed  $master) : boolean

Parameters

mixed $master

The master object (or ident) to check against.

Returns

boolean

hasSiblings()

hasSiblings() : boolean

Returns

boolean

numSiblings()

numSiblings() : integer

Returns

integer

siblings()

siblings() : array

Get all the objects on the same level as this one.

Returns

array

isSiblingOf()

isSiblingOf(mixed  $sibling) : boolean

Parameters

mixed $sibling

The sibling to check.

Returns

boolean

modelFactory()

modelFactory() : \Charcoal\Factory\FactoryInterface

Retrieve the object model factory.

Returns

\Charcoal\Factory\FactoryInterface

objFromIdent()

objFromIdent(mixed  $ident) : \Charcoal\Object\HierarchicalInterface|null

Parameters

mixed $ident

The ident.

Throws

\InvalidArgumentException

If the identifier is not a scalar value.

Returns

\Charcoal\Object\HierarchicalInterface|null

loadObjectFromSource()

loadObjectFromSource(mixed  $id) : null|\Charcoal\Model\ModelInterface

Retrieve an object from the storage source by its ID.

Parameters

mixed $id

The object id.

Returns

null|\Charcoal\Model\ModelInterface

loadObjectFromCache()

loadObjectFromCache(mixed  $id) : null|\Charcoal\Model\ModelInterface

Retrieve an object from the cache store by its ID.

Parameters

mixed $id

The object id.

Returns

null|\Charcoal\Model\ModelInterface

addObjectToCache()

addObjectToCache(\Charcoal\Model\ModelInterface  $obj) : \Charcoal\Object\HierarchicalInterface

Add an object to the cache store.

Parameters

\Charcoal\Model\ModelInterface $obj

The object to store.

Returns

\Charcoal\Object\HierarchicalInterface

Chainable