\Composer\AutoloadClassLoader

ClassLoader implements a PSR-0, PSR-4 and classmap class loader.

$loader = new \Composer\Autoload\ClassLoader();

// register classes with namespaces
$loader->add('Symfony\Component', __DIR__.'/component');
$loader->add('Symfony',           __DIR__.'/framework');

// activate the autoloader
$loader->register();

// to enable searching the include path (eg. for PEAR packages)
$loader->setUseIncludePath(true);

In this example, if you try to use a class in the Symfony\Component namespace or one of its children (Symfony\Component\Console for instance), the autoloader will first look for the class under the component/ directory, and it will then fallback to the framework/ directory if not found before giving up.

This class is loosely based on the Symfony UniversalClassLoader.

Summary

Methods
Properties
Constants
getPrefixes()
getPrefixesPsr4()
getFallbackDirs()
getFallbackDirsPsr4()
getClassMap()
addClassMap()
add()
addPsr4()
set()
setPsr4()
setUseIncludePath()
getUseIncludePath()
setClassMapAuthoritative()
isClassMapAuthoritative()
register()
unregister()
loadClass()
findFile()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
findFileWithExtension()
$prefixLengthsPsr4
$prefixDirsPsr4
$fallbackDirsPsr4
$prefixesPsr0
$fallbackDirsPsr0
$useIncludePath
$classMap
$classMapAuthoritative
$missingClasses
N/A

Properties

$prefixLengthsPsr4

$prefixLengthsPsr4 : 

Type

$prefixDirsPsr4

$prefixDirsPsr4 : 

Type

$fallbackDirsPsr4

$fallbackDirsPsr4 : 

Type

$prefixesPsr0

$prefixesPsr0 : 

Type

$fallbackDirsPsr0

$fallbackDirsPsr0 : 

Type

$useIncludePath

$useIncludePath : 

Type

$classMap

$classMap : 

Type

$classMapAuthoritative

$classMapAuthoritative : 

Type

$missingClasses

$missingClasses : 

Type

Methods

getPrefixes()

getPrefixes() 

getPrefixesPsr4()

getPrefixesPsr4() 

getFallbackDirs()

getFallbackDirs() 

getFallbackDirsPsr4()

getFallbackDirsPsr4() 

getClassMap()

getClassMap() 

addClassMap()

addClassMap(array  $classMap) 

Parameters

array $classMap

Class to filename map

add()

add(string  $prefix, array|string  $paths, boolean  $prepend = false) 

Registers a set of PSR-0 directories for a given prefix, either appending or prepending to the ones previously set for this prefix.

Parameters

string $prefix

The prefix

array|string $paths

The PSR-0 root directories

boolean $prepend

Whether to prepend the directories

addPsr4()

addPsr4(string  $prefix, array|string  $paths, boolean  $prepend = false) 

Registers a set of PSR-4 directories for a given namespace, either appending or prepending to the ones previously set for this namespace.

Parameters

string $prefix

The prefix/namespace, with trailing '\'

array|string $paths

The PSR-4 base directories

boolean $prepend

Whether to prepend the directories

Throws

\InvalidArgumentException

set()

set(string  $prefix, array|string  $paths) 

Registers a set of PSR-0 directories for a given prefix, replacing any others previously set for this prefix.

Parameters

string $prefix

The prefix

array|string $paths

The PSR-0 base directories

setPsr4()

setPsr4(string  $prefix, array|string  $paths) 

Registers a set of PSR-4 directories for a given namespace, replacing any others previously set for this namespace.

Parameters

string $prefix

The prefix/namespace, with trailing '\'

array|string $paths

The PSR-4 base directories

Throws

\InvalidArgumentException

setUseIncludePath()

setUseIncludePath(boolean  $useIncludePath) 

Turns on searching the include path for class files.

Parameters

boolean $useIncludePath

getUseIncludePath()

getUseIncludePath() : boolean

Can be used to check if the autoloader uses the include path to check for classes.

Returns

boolean

setClassMapAuthoritative()

setClassMapAuthoritative(boolean  $classMapAuthoritative) 

Turns off searching the prefix and fallback directories for classes that have not been registered with the class map.

Parameters

boolean $classMapAuthoritative

isClassMapAuthoritative()

isClassMapAuthoritative() : boolean

Should class lookup fail if not found in the current class map?

Returns

boolean

register()

register(boolean  $prepend = false) 

Registers this instance as an autoloader.

Parameters

boolean $prepend

Whether to prepend the autoloader or not

unregister()

unregister() 

Unregisters this instance as an autoloader.

loadClass()

loadClass(string  $class) : boolean|null

Loads the given class or interface.

Parameters

string $class

The name of the class

Returns

boolean|null —

True if loaded, null otherwise

findFile()

findFile(string  $class) : string|false

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

Parameters

string $class

The name of the class

Returns

string|false —

The path if found, false otherwise

findFileWithExtension()

findFileWithExtension(  $class,   $ext) 

Parameters

$class
$ext