Elgg  Version master
Public Member Functions | Protected Attributes | List of all members
Elgg\ClassLoader Class Reference

A class/interface/trait autoloader for PHP. More...

Public Member Functions

 __construct (protected Config $config)
 Constructor. More...
 
 getClassMap ()
 Get the class map. More...
 
 getNamespaces ()
 Gets the configured namespaces. More...
 
 getPrefixes ()
 Gets the configured class prefixes. More...
 
 registerNamespaces (array $namespaces)
 Registers an array of namespaces. More...
 
 registerNamespace ($namespace, $paths)
 Registers a namespace. More...
 
 registerPrefixes (array $classes)
 Registers an array of classes using the PEAR naming convention. More...
 
 registerPrefix ($prefix, $paths)
 Registers a set of classes using the PEAR naming convention. More...
 
 addFallback ($path)
 Add a directory to search if no registered directory is found. More...
 
 register ()
 Registers this instance as an autoloader. More...
 
 loadClass ($class)
 Loads the given class or interface, possibly updating the class map. More...
 
 findFile ($class)
 Finds the path to the file where the class is defined. More...
 

Protected Attributes

array $namespaces = []
 
array $prefixes = []
 
array $fallbacks = []
 
 $map
 
array $missing = []
 

Detailed Description

A class/interface/trait autoloader for PHP.

It is able to load classes that use either:

Classes from a sub-namespace or a sub-hierarchy of PEAR classes can be looked for in a list of locations to ease the vendoring of a sub-set of classes for large projects.

All discovered files are stored in the internal class map and the map is queried before attempting to find a file.

Contains code from Symfony2's UniversalClassLoader.

Copyright (c) 2004-2013 Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition at line 48 of file ClassLoader.php.

Constructor & Destructor Documentation

Elgg\ClassLoader::__construct ( protected Config  $config)

Constructor.

Parameters
\Elgg\Config$configSite config

Definition at line 71 of file ClassLoader.php.

Member Function Documentation

Elgg\ClassLoader::addFallback (   $path)

Add a directory to search if no registered directory is found.

Parameters
string$pathThe directory
Returns
void

Definition at line 161 of file ClassLoader.php.

Elgg\ClassLoader::findFile (   $class)

Finds the path to the file where the class is defined.

Parameters
string$classThe name of the class
Returns
string|null The path, if found

Definition at line 211 of file ClassLoader.php.

Elgg\ClassLoader::getClassMap ( )

Get the class map.

Returns

Definition at line 82 of file ClassLoader.php.

Elgg\ClassLoader::getNamespaces ( )

Gets the configured namespaces.

Returns
array A hash with namespaces as keys and directories as values

Definition at line 91 of file ClassLoader.php.

Elgg\ClassLoader::getPrefixes ( )

Gets the configured class prefixes.

Returns
array A hash with class prefixes as keys and directories as values

Definition at line 100 of file ClassLoader.php.

Elgg\ClassLoader::loadClass (   $class)

Loads the given class or interface, possibly updating the class map.

Parameters
string$classThe name of the class
Returns
void

Definition at line 181 of file ClassLoader.php.

Elgg\ClassLoader::register ( )

Registers this instance as an autoloader.

Returns
void

Definition at line 170 of file ClassLoader.php.

Elgg\ClassLoader::registerNamespace (   $namespace,
  $paths 
)

Registers a namespace.

Parameters
string$namespaceThe namespace
array | string$pathsThe location(s) of the namespace
Returns
void

Definition at line 125 of file ClassLoader.php.

Elgg\ClassLoader::registerNamespaces ( array  $namespaces)

Registers an array of namespaces.

Parameters
array$namespacesAn array of namespaces (namespaces as keys and locations as values)
Returns
void

Definition at line 111 of file ClassLoader.php.

Elgg\ClassLoader::registerPrefix (   $prefix,
  $paths 
)

Registers a set of classes using the PEAR naming convention.

Parameters
string$prefixThe classes prefix
array | string$pathsThe location(s) of the classes
Returns
void

Definition at line 150 of file ClassLoader.php.

Elgg\ClassLoader::registerPrefixes ( array  $classes)

Registers an array of classes using the PEAR naming convention.

Parameters
array$classesAn array of classes (prefixes as keys and locations as values)
Returns
void

Definition at line 136 of file ClassLoader.php.

Member Data Documentation

array Elgg\ClassLoader::$fallbacks = []
protected

Definition at line 54 of file ClassLoader.php.

Elgg\ClassLoader::$map
protected

Definition at line 59 of file ClassLoader.php.

array Elgg\ClassLoader::$missing = []
protected

Definition at line 64 of file ClassLoader.php.

array Elgg\ClassLoader::$namespaces = []
protected

Definition at line 50 of file ClassLoader.php.

array Elgg\ClassLoader::$prefixes = []
protected

Definition at line 52 of file ClassLoader.php.


The documentation for this class was generated from the following file: