\Phabstractic\LoaderModule

Module Class

The Module class is a leaf structure that contains a path (or path identifier). Each path represented might be relative or absolute, or something entirely different.

Technically it's a string strung up as a tree.

Each Module has it's own path, and it's own directory of other Modules.

The idea is that we can map a namespace item (\Item1\Item2\Item3) to a path so that separate namespace elements have different paths, useful in PSR-4

CHANGELOG

1.0: Created Module - February 21st, 2014 1.1: Refactored Module to CDirectory.php - February 27th, 2014 1.2: Wrapped Module around CDirectory.php - February 27th, 2014 2.0: Refactored and integrated with Primus 2 - October 20th, 2015 3.0: eliminated isPath method reformatted for inclusion in phabstractic - August 2nd, 2016

Summary

Methods
Properties
Constants
getData()
getDataReference()
setData()
getLeavesData()
getLeafIdentifier()
setLeafIdentifier()
__construct()
__debugInfo()
addToLeafIdentityPath()
buildFromArray()
getAsArray()
getFromLeafIdentityPath()
getLeafIdentityPaths()
dataBelongsTo()
getLeaves()
addLeaf()
removeLeaf()
isLeaf()
configure()
saveSettings()
getSettings()
processSettings()
getModuleIdentifier()
setModuleIdentifier()
getPath()
setPath()
getModules()
getModuleByIdentifier()
getModuleByIdentifierReference()
addModule()
removeModule()
removeModuleByIdentifier()
isSubModule()
isSubModuleByIdentifier()
getFromModuleIdentityPath()
addToModuleIdentityPath()
getModulesAsArray()
getModuleIdentityPaths()
pathBelongsTo()
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

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

getLeafIdentifier()

getLeafIdentifier() : string

Override default leaf identifier behavior

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(  $path = null,   $identifier = null, array  $modules = array(), array  $options = array()) 

The Module Constructor

This accepts an array of modules (ModuleInterface)

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

Parameters

$path
$identifier
array $modules

A plain array of ModuleInterface compatible objects

array $options

An array of options, as keys (see above)

__debugInfo()

__debugInfo() 

Debug Info (var_dump)

Display debug info

Requires PHP 5.6+

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

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

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

getModuleIdentifier()

getModuleIdentifier() : string

Get this particular module's identifier

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

Returns

string —

The module identifier

setModuleIdentifier()

setModuleIdentifier(  $newIdentifier) : boolean

Set this particular module's identifier

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

Parameters

$newIdentifier

Returns

boolean

getPath()

getPath() : \Phabstractic\Loader\Phabstractic\Data\Components\Path

GetPath - Get the associated path

Like getData

Returns

\Phabstractic\Loader\Phabstractic\Data\Components\Path

setPath()

setPath(\Phabstractic\Loader\Phabstractic\Data\Components\Path  $path) 

Set the associated path

Like setData

Parameters

\Phabstractic\Loader\Phabstractic\Data\Components\Path $path

getModules()

getModules() : array

GetModules - Wrapper

A wrapper function for underlying abstract leaf functionality

Returns

array —

The Modules

getModuleByIdentifier()

getModuleByIdentifier(  $identifier) : \Phabstractic\Loader\Phabstractic\Loader\Resource\ModuleInterface

Get Module by Identifier

Parameters

$identifier

Returns

\Phabstractic\Loader\Phabstractic\Loader\Resource\ModuleInterface

getModuleByIdentifierReference()

getModuleByIdentifierReference(  $identifier) : \Phabstractic\Loader\&Phabstractic\Loader\Resource\ModuleInterface

Get Module by Identifier

Parameters

$identifier

Returns

\Phabstractic\Loader\&Phabstractic\Loader\Resource\ModuleInterface

addModule()

addModule(\Phabstractic\Loader\Falcraft\Loader\Resource\ModuleInterface  $module) : mixed

Add Module - Wrapper

A wrapper function for underlying abstract leaf functionality

Parameters

\Phabstractic\Loader\Falcraft\Loader\Resource\ModuleInterface $module

The actual module to add

Returns

mixed —

What addleaf returns

removeModule()

removeModule(\Phabstractic\Loader\Phabstractic\Loader\Resource\ModuleInterface  $module) : mixed

Remove Module - Wrapper

A wrapper function for underlying abstract leaf functionality

Parameters

\Phabstractic\Loader\Phabstractic\Loader\Resource\ModuleInterface $module

The local module

Returns

mixed —

What removeleaf returns

removeModuleByIdentifier()

removeModuleByIdentifier(string|integer  $moduleName) : mixed

Remove Module By Identifier - Wrapper

A wrapper function for underlying abstract leaf functionality

Parameters

string|integer $moduleName

The local module identifier

Returns

mixed —

What removeleaf returns

isSubModule()

isSubModule(\Phabstractic\Loader\Phabstractic\Loader\Resource\ModuleInterface  $module) : boolean

Is Sub Module - Wrapper

A wrapper function for underlying abtract leaf functionality

Parameters

\Phabstractic\Loader\Phabstractic\Loader\Resource\ModuleInterface $module

the module

Returns

boolean —

Are we in the module's 'directory'?

isSubModuleByIdentifier()

isSubModuleByIdentifier(string  $moduleName) : boolean

Is Sub Module - Wrapper

A wrapper function for underlying abtract leaf functionality

Parameters

string $moduleName

the module identifier

Returns

boolean —

Are we in the module's 'directory'?

getFromModuleIdentityPath()

getFromModuleIdentityPath(string  $path) : \Phabstractic\Loader\Falcraft\Loader\Module|\Phabstractic\Loader\Falcraft\Data\Types\None

Retrieve a Module using a path from this module

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

Parameters

string $path

The path to the desired Module (this\is\a\path)

Returns

\Phabstractic\Loader\Falcraft\Loader\Module|\Phabstractic\Loader\Falcraft\Data\Types\None —

A reference, none on failure

addToModuleIdentityPath()

addToModuleIdentityPath(string  $path, \Phabstractic\Loader\Falcraft\Loader\Resource\ModuleInterface  $newModule) 

Take this Module, parse the path, and add the given Module

Takes this Module, calls getFromModulePath, and then adds the newModule to the resulting Module.

Parameters

string $path
\Phabstractic\Loader\Falcraft\Loader\Resource\ModuleInterface $newModule

getModulesAsArray()

getModulesAsArray() : array

Return Modules structure from root as array

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

Returns

array

getModuleIdentityPaths()

getModuleIdentityPaths() 

Get Module Paths

This returns a list of all terminating paths

Ex:

[] Module1\Module2\Module3 [] Module1\Module4 [] Module1\Module5\Module6\Module7

pathBelongsTo()

pathBelongsTo(  $path) 

Returns a Module path that contains the path

Okay, this returns a Module path to the Module that contains the associated path

Parameters

$path

The path to find (NOT Modulepath)

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