\Phabstractic\LoaderAutoLoader

AutoLoader Class - Defines standard autoloader for Phabstractic libraries

This class inherits path, module, prefix, and library tracking from Resource/AbstractLoader. The job of this class is to provide a concrete means of determining how classes are loaded.

This class is inheritable if a different autoloading mechanism or logic must be employed

CHANGELOG

1.0: Documented AutoLoader - May 5th, 2013 2.0: Refactored and integrated with Primus 2 - October 20th, 2015 3.0: removed default path in realbase reformatted for inclusion in phabstractic - August 3rd, 2016

Summary

Methods
Properties
Constants
autoload()
__construct()
register()
deregister()
getPaths()
addPath()
isPath()
removePath()
getPathObject()
getPathObjectReference()
addPrefix()
hasPrefix()
isPrefix()
getPrefixes()
removePrefix()
getNamespaces()
addNamespace()
isNamespace()
removeNamespace()
getNamespacePath()
getNamespaceModule()
getNamespaceModulesAsArray()
configure()
saveSettings()
getSettings()
processSettings()
defaultDelimiters()
getDelimiters()
addDelimiter()
removeDelimiter()
__debugInfo()
No public properties found
No constants found
No protected methods found
$paths
$prefixes
$libraries
$conf
$delimiters
N/A
explodeDelimiters()
No private properties found
N/A

Properties

$paths

$paths : array

The list of path objects

Keys are identifiers, values are path objects

Type

array

$prefixes

$prefixes : array

A multi-dimensional array of prefixes tied to paths

Keys are path identifiers, values are array of prefixes

Type

array

$libraries

$libraries : \Phabstractic\Loader\Resource\Falcraft\Data\Components\File\Module

The root Module for the libraries

This is the beginning of the tree for Module objects

Type

\Phabstractic\Loader\Resource\Falcraft\Data\Components\File\Module

$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

$delimiters

$delimiters : array

Delimiters to also separate apart when parsing out a class

Use for example '_' to comply with PSR-0

This defaults to '\' (the namespace delimiter)

Type

array

Methods

autoload()

autoload(string  $class) : boolean

Autoload a Class

This is the meat of the whole operation. Everything up until now (AbstractLoader, GenericInterface, Module, Path, etc.) has been constructed for this function to occur.

This function first establishes a base path either from a predefined constant (presumably from the bootstrap), or, in the case that these are not specified, two folders up ( /library/ ).

Then it parses the class string with the appropriate delimiters.

It moves on to parse through the modules, constructing a path, by concatenating relative paths and replacing with absolute paths.

If path remnants are left over, it constructs a NEW path (losing extensions but not prefixes). This is important, if you want extensions the path object must be in the terminating module.

It then checks file existence with prefixes, and then it processes through independent paths (like an include path string)

NOTE: This function uses require_once

Parameters

string $class

The fully qualified class name to load

Returns

boolean —

True on success

__construct()

__construct(array  $paths = array(), array  $options = array(), array  $delimiters = array()) 

AutoLoader Constructor

This takes in the paths, options, and delimiters

Because this takes delimiters we deal with that in this constructor

Parameters

array $paths

The paths passed to AbstractLoader

array $options

The options passed to AbstractLoader

array $delimiters

Additional delimiters such as underscore to split the class names up (each delimiter is an array entry)

register()

register() 

Register the autoloader with the SPL

deregister()

deregister() 

De (un) register the autoloader withthe SPL

getPaths()

getPaths() : array

Return all the paths in an array

actual paths, string of arrays

Returns

array

addPath()

addPath(string  $newPath) : boolean

Add a path to the path pool

This function can be used in multiple ways depending on the autoloader. It is meant to be used as sort of an additional include path.

Parameters

string $newPath

The include path

Returns

boolean —

false on failure

isPath()

isPath(string  $path) : boolean

Does this path exist in the object's list?

Parameters

string $path

The given path to test, or identifier

Returns

boolean

removePath()

removePath(string  $path) : boolean

Removes a path from the path pool, but only if it's not tied to a Module

This function servers the opposite functionality of the addPath function. If a path doesn't exist, it does nothing

Parameters

string $path

The path to exclude/remove

Returns

boolean —

On success or failure

getPathObject()

getPathObject(string  $searchPath) : \Phabstractic\Loader\Resource\Phabstractic\Data\Components\Path

Retrieve a path object by path

Parameters

string $searchPath

The path we're looking for

Returns

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

getPathObjectReference()

getPathObjectReference(string  $searchPath) : \Phabstractic\Loader\Resource\Phabstractic\Data\Components\Path

Retrieve a reference to path object by path

Parameters

string $searchPath

The path we're looking for

Returns

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

addPrefix()

addPrefix(string  $path, string  $prefix) : boolean

Add a prefix to a particular path

The autoloader keeps track of its own prefixes as attached to paths

Parameters

string $path

The path

string $prefix

(include any characters like an underscore: WP_)

Returns

boolean —

Pretty much true

hasPrefix()

hasPrefix(  $path) : boolean

Does this path have prefixes?

(Any prefix)

Does not add path to list

Parameters

$path

Returns

boolean —

true on success, false on failure

isPrefix()

isPrefix(string  $prefix) : boolean

This tests if there is a prefix associated with a path

If there is no path given, it tests if a prefix exists with any path in the autoloader

Parameters

string $prefix

The prefix we're looking for

Returns

boolean —

true on success, false on failure

getPrefixes()

getPrefixes(string|\Phabstractic\Loader\Resource\id  $path) : array

Retrieve all prefixes associated with a path

The path can be an existing path, or an identifier

Preferably an identifier

Parameters

string|\Phabstractic\Loader\Resource\id $path

The path or identifier

Returns

array

removePrefix()

removePrefix(string|integer  $path, string  $prefix) : boolean

Remove a prefix from a path

Automatically de-couples the prefix from all assigned paths

Parameters

string|integer $path

The path to remove the prefix from

string $prefix

The given prefix

Returns

boolean —

true on success, or false on failure

getNamespaces()

getNamespaces() : array

Retrieve the endpoints of all namespaces

Returns

array

addNamespace()

addNamespace(string  $namespace, string  $path) : boolean

Register namespace with the autoloader

This function can be used in multiple ways depending on the autoloader. It is meant to be use as a sort of an additional include path linked to a given library/vendor name

Parameters

string $namespace

The base namespace

string $path

The include path

Returns

boolean —

True on success

isNamespace()

isNamespace(string  $namespace) : boolean

Is this namespace registered with this autoloader?

Parameters

string $namespace

The namespace of the library

Returns

boolean —

True if present

removeNamespace()

removeNamespace(string  $namespace) : boolean

Unregister a namespace with the autoloader

Performs the opposite functionality of the addLibrary method

Returns false if Module is not present in autoloader

Parameters

string $namespace

The library path/identifier

Returns

boolean —

True on successful removal

getNamespacePath()

getNamespacePath(string  $namespace) : string

Retrieve path associated with namespace

Parameters

string $namespace

The library namespace

Returns

string

getNamespaceModule()

getNamespaceModule(  $namespace) : \Phabstractic\Loader\Resource\&Phabstractic\Loader\Resource\ModuleInterface

Retrieve the module reference associated with namespace

Pre-pend the namespace with a '\'!

Parameters

$namespace

Returns

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

getNamespaceModulesAsArray()

getNamespaceModulesAsArray() : array

Retrieve the modules as an array

Returns

array

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

defaultDelimiters()

defaultDelimiters() 

Establish the autoloaders defaultDelimiters

In essence resetting the delimiters to only accept namespace delimiters

getDelimiters()

getDelimiters() : array

Retrieve all the delimiters in an array

Returns

array

addDelimiter()

addDelimiter(string  $delimiter) 

Add a delimiter to the autoloader

Parameters

string $delimiter

To add

removeDelimiter()

removeDelimiter(string  $delimiter) 

Remove a delimiter from the autoloader

Pass the actual delimiter such as an underscore

Parameters

string $delimiter

The delimiter to remove

__debugInfo()

__debugInfo() 

Debug Info (var_dump)

Display debug info

Requires PHP 5.6+

explodeDelimiters()

explodeDelimiters(string  $input) : array

Separate multiple delimiters

Parameters

string $input

Returns

array