\Phabstractic\Loader\ResourceLoaderInterface

The Generic Autoloader Interface

This interface establishes a common lexicon for different autoloader objects/strategies.

It creates functions all autoloading strategies have: registering, adding and removing paths, and autoloading

It also gives the developer an opportunity to employ prefixes and Modules through given functions.

CHANGELOG

1.0 Created Generic Interface - December 20th, 2013 1.1 Revamped Generic Interface for better compatibility with current and past practices - January 29th, 2014 1.2 Finalized - February 21st, 2014 2.0 Refactored and Integrated with Primus 2 - October 20th, 2015 3.0: eliminated default path reformatted for inclusion in phabstractic - August 3rd, 2016

Summary

Methods
Constants
autoload()
register()
deregister()
getPaths()
addPath()
isPath()
removePath()
addPrefix()
isPrefix()
getPrefixes()
removePrefix()
getNamespaces()
addNamespace()
isNamespace()
removeNamespace()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

autoload()

autoload(string  $class) : boolean

Autoload a particular class from a given string

This is the string provided by the PHP autoloading mechanisms

Parameters

string $class

The string referencing the class (namespaced)

Returns

boolean —

True on success

register()

register() 

Register the autoloader with spl_autoload registry

deregister()

deregister() 

Un-register the autoloader with the spl_autoload registry

getPaths()

getPaths() : array

Return all the paths in an array

actual paths, string of arrays

Returns

array

addPath()

addPath(string  $newPath) : boolean

Register a path with the autoloader

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

Is a given path present in the autoloader?

Parameters

string $path

The given path to test, or identifier

Returns

boolean —

false on failure

removePath()

removePath(string  $path) : boolean

Remove a path with the autoloader

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 —

Successfully removed (was present?)

addPrefix()

addPrefix(string  $path, string  $prefix) 

Register a prefix with the autoloader

This function can be used in multiple ways depending on the autoloader. It is mean to be used as a modifier to file loading associated with a particular path

Parameters

string $path

The path to associate the prefix to

string $prefix

The prefix identifier/content

isPrefix()

isPrefix(string  $prefix) : array

Search for the existence of a specific prefix

Parameters

string $prefix

The prefix identifier/content

Returns

array —

Paths the prefix is associated with, empty on failure

getPrefixes()

getPrefixes(string  $path) : array

Retrieve all prefixes associated with a path

The path can be an existing path

Parameters

string $path

The path

Returns

array

removePrefix()

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

Remove a registered prefix from the autoloader

Automatically de-couples the prefix from all assigned paths

Parameters

string $path

The path associated

string $prefix

The prefix Identifier/content

Returns

boolean —

True if found and removed

getNamespaces()

getNamespaces() : array

Retrieve list of 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