\Phabstractic\Data\TypesLeaf

Leaf Class

Inherits from Abstract, identity and configuration, this implements the data storage.

CHANGELOG

1.0: Created Module - February 7th, 2014 1.1: Repurposed to Leaf - February 9th, 2014 Documented Leaf - February 21st, 2014 2.0: Incorporated AbstractLeaf into Primus - August 26th, 2015 3.0: reformatted for inclusion in phabstractic - August 1st, 2016

Summary

Methods
Properties
Constants
getLeafIdentifier()
setLeafIdentifier()
__construct()
getLeaves()
addLeaf()
removeLeaf()
isLeaf()
__debugInfo()
configure()
saveSettings()
getSettings()
processSettings()
getData()
getDataReference()
setData()
getLeavesData()
addToLeafIdentityPath()
buildFromArray()
getAsArray()
getFromLeafIdentityPath()
getLeafIdentityPaths()
dataBelongsTo()
No public properties found
No constants found
getNewIdentity()
$identityCounter
$identityPrefix
$leaves
$conf
N/A
No private methods found
$identifier
$data
N/A

Properties

$identityCounter

$identityCounter : mixed

The Global Identity Generator Marker

When the identity is polled, this marker is 'advanced'. It's static to the class, in that way it's unique for each one.

Type

mixed — The current identity

$identityPrefix

$identityPrefix : mixed

The Identity Marker Prefix

Specific to a given class, this is placed with/in front of the identity (context) This is a bit strange to understand why it's not static, but imagine a finer grain of control

Type

mixed — The class's context/marker prefix

$leaves

$leaves : \Phabstractic\Data\Types\Resource\Falcraft\Data\Types\RestrictedList

The collection of leaves this leaf is connected to

This uses the leave's identifiers as keys

Type

\Phabstractic\Data\Types\Resource\Falcraft\Data\Types\RestrictedList — (Falcraft\Data\Types\Tree\LeafInterface)

$conf

$conf : \Phabstractic\Features\Zend\Config\Config

The objects configuration object

Should be an instance of Zend/Config

Type

\Phabstractic\Features\Zend\Config\Config — The object configuration info

$identifier

$identifier : mixed

The leaf's identifier

Type

mixed

$data

$data : mixed

The Leaf's Data Property

Type

mixed

Methods

getLeafIdentifier()

getLeafIdentifier() : string

Get this particular leaf's identifier

Warning: You can create multiple leaves with the same identifier by changing the identifier at a later time.

Returns

string —

The universally unique vertex identifier

setLeafIdentifier()

setLeafIdentifier(  $newIdentifier) : boolean

Set this particular leaf's identifier

Warning: You can create multiple leaves with the same identifier by changing the identifier at a later time.

Parameters

$newIdentifier

Returns

boolean

__construct()

__construct(  $data = null, array  $leaves = array(), array  $options = array()) 

The Leaf Constructor

This accepts an array of leaves (LeafInterface)

Options - prefix: set the identifier prefix for local strict: throw errors

Parameters

$data
array $leaves

A plain array of LeafInterface compatible objects

array $options

An array of options, as keys (see above)

getLeaves()

getLeaves() : array

Get a plain array of the leaves contained by this leaf

Returns

array —

The connected leaves

addLeaf()

addLeaf(\Phabstractic\Data\Types\Resource\Phabstractic\Data\Type\Resource\LeafInterface  $leaf) : string

Add a leaf to the set of leaves this leaf is connected to

Parameters

\Phabstractic\Data\Types\Resource\Phabstractic\Data\Type\Resource\LeafInterface $leaf

The leaf to connect

Returns

string —

The new leaf's local identity

removeLeaf()

removeLeaf(\Phabstractic\Data\Types\Resource\Phabstractic\Data\Type\Resource\LeafInterface  $leaf) : boolean

Remove a leaf

Parameters

\Phabstractic\Data\Types\Resource\Phabstractic\Data\Type\Resource\LeafInterface $leaf

The leaf to remove

Returns

boolean

isLeaf()

isLeaf(\Phabstractic\Data\Types\Resource\Phabstractic\Data\Type\Resource\LeafInterface  $leaf) : string

Does this leaf have the identifier for another leaf?

Parameters

\Phabstractic\Data\Types\Resource\Phabstractic\Data\Type\Resource\LeafInterface $leaf

The leaf to find

Returns

string

__debugInfo()

__debugInfo() 

Debug Info (var_dump)

Display debug info

Requires PHP 5.6+

configure()

configure(array|string|\Phabstractic\Features\Zend\Config\Config  $configuration, string  $format = null, mixed  $context = null) : boolean

Configure An Object

Expects an array for configuration however, you can also pass it a filepath where it will read the information from a file automatically detecting the format using the file extension. You can also pass a Zend/Config object already made.

You can also pass a format specifier (forced format) for use in a if $configuration is a string formatted with such information. E.G. to load from a string in the format ini:

$this->configure($configString, 'ini');

The $context argument is used for any additional reader constructor information, such as the constructor for the 'yaml' format.

NOTE: You can override/extend the classes used for reading formats by identifying an additional array in the property $this->configReaders. This will merge with the standard formats array.

Parameters

array|string|\Phabstractic\Features\Zend\Config\Config $configuration

The objects configuration information.

string $format

The forced format, or format for configuration string

mixed $context

Any additional information for a reader constructor, such as needed for the YAML format.

Returns

boolean —

True if instantiated

saveSettings()

saveSettings(string  $file, \Phabstractic\Features\Zend\Config\Writer\WriterInterface  $writer = null, boolean  $exclusive = true, mixed  $context = null) 

Save an Object's Configuration to a File

Takes an objects $conf property and writes the information contained therein to a file with a format automatically specified by the filename.

It is possible to retrieve a string of a particular format from this method by specifying the filename '#string' with an extension indicating the desired format, such as '#string.json'.

The $context argument is used for any additional reader constructor information, such as the constructor for the 'yaml' format.

NOTE: You can override/extend the classes used for writing formats by identifying an additional array in the property $this->configWriters. This will merge with the standard formats array.

Parameters

string $file

The file path to write to, or '#string.ext'

\Phabstractic\Features\Zend\Config\Writer\WriterInterface $writer

The optional writer object supplied to use (such as a MySQL writer)

boolean $exclusive

Argument provided to toFile(), file exclusive lock when writing

mixed $context

Any additionla writer constructor information (YAML)

getSettings()

getSettings(string  $format,   $context = null) : string|boolean

Retrieve an Object's Configuration Information As String

This is a shortcut to ::saveSettings() which specifies a format and forces the return of a string, using the #string.ext filename -see documentation for ::saveSettings()-

Parameters

string $format

The format to return, must be supported by ::saveSettings(), use $this->configWriters to support additional formats.

$context

Returns

string|boolean —

The formatted string, or false otherwise

processSettings()

processSettings(\Phabstractic\Features\Zend\Config\Processor\ProcessorInterface  $processor) 

Process an Object's Configuration

This uses a Zend\Config\Processor implementation to process the configuration information, such as constants. The processor must be supplied and implement ProcessorInterface

NOTE: Edits the $conf object in place.

Parameters

\Phabstractic\Features\Zend\Config\Processor\ProcessorInterface $processor

The given processor object

getData()

getData() : mixed

Get the data associated with the leaf

Returns

mixed —

The data

getDataReference()

getDataReference() : \Phabstractic\Data\Types\&mixed

Get data as reference

Returns

\Phabstractic\Data\Types\&mixed —

The data reference

setData()

setData(mixed  $data = null) 

Set the data to be associated with the leaf

Parameters

mixed $data

The data

getLeavesData()

getLeavesData() : array

Get leaves data

Returns

array

addToLeafIdentityPath()

addToLeafIdentityPath(\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractLeaf  $root, string  $path, \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LeafInterface  $newLeaf,   $delimiter = '/') 

Take a root leaf, parse the path, and add the given leaf

Takes a root leaf, calls getFromLeafIdentityPath, and then adds the new leaf to the resulting leaf.

Parameters

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractLeaf $root
string $path
\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LeafInterface $newLeaf
$delimiter

buildFromArray()

buildFromArray(array  $build = array()) 

Take an array of Leaves, and create the Tree

Each array will have a data element for the data and then a leaves element whose entries are other data. An empty array ends the sequence

Very recursive

Parameters

array $build

Not an array of leaves, but as above

getAsArray()

getAsArray(\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractLeaf  $root) : array

Return Leaf structure from root as array

See above, does the reverse. This is a good way to see how the above is formatted.

Parameters

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractLeaf $root

The root to start at

Returns

array

getFromLeafIdentityPath()

getFromLeafIdentityPath(\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractLeaf  $root, string  $path,   $delimiter = '/') : \Phabstractic\Data\Types\Phabstractic\Data\Type\Resource\LeafInterface|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Retrieve a Leaf using a path and a root

This starts at a given root Leaf, and then parses the path (delimited by '/'s) until it reaches the intended Leaf. The path refers to identifiers as stored in the identifier array of the actual Leaf

Parameters

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractLeaf $root

The Leaf to begin at

string $path

The path to the desired Folder (this/is/a/path)

$delimiter

Returns

\Phabstractic\Data\Types\Phabstractic\Data\Type\Resource\LeafInterface|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

A reference, none on failure

getLeafIdentityPaths()

getLeafIdentityPaths(\Phabstractic\Data\Types\Phabstractic\Types\Resource\AbstractLeaf  $root,   $path = '',   $delimiter = '/') 

Get Leaf Identifier Paths

This returns a list of all terminating paths

Ex:

[] Leaf7/Leaf8/TestPrefix9 [] Leaf12/Leaf1 [] Leaf19/TestPrefix10/AnotherPrefix4/Leaf76

Parameters

\Phabstractic\Data\Types\Phabstractic\Types\Resource\AbstractLeaf $root

The leaf to start at

$path

A recursive function argument, don't use

$delimiter

dataBelongsTo()

dataBelongsTo(  $data, \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractLeaf  $root, \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractLeaf  $recurseLeaf = null,   $delimiter = '/') 

Returns a leaf path that contains the data

NOTE: Only returns the first instance it finds

Okay, this returns a leaf path to the leaf that contains the associated data

Parameters

$data

The data to find

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractLeaf $root

The root of the tree

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractLeaf $recurseLeaf

Recursive function argument, don't use

$delimiter

getNewIdentity()

getNewIdentity() : mixed

Poll for New Identity

Overridable in a using class so that anything could be used as an identity, but by default it's an integer attached to a prefix. As new identities are polled, the integer increases.

Returns

mixed —

The new identity