TYPO3  7.6
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ClassLoader Class Reference

Public Member Functions

 getPrefixes ()
 
 getPrefixesPsr4 ()
 
 getFallbackDirs ()
 
 getFallbackDirsPsr4 ()
 
 getClassMap ()
 
 addClassMap (array $classMap)
 
 add ($prefix, $paths, $prepend=false)
 
 addPsr4 ($prefix, $paths, $prepend=false)
 
 set ($prefix, $paths)
 
 setPsr4 ($prefix, $paths)
 
 setUseIncludePath ($useIncludePath)
 
 getUseIncludePath ()
 
 setClassMapAuthoritative ($classMapAuthoritative)
 
 isClassMapAuthoritative ()
 
 register ($prepend=false)
 
 unregister ()
 
 loadClass ($class)
 
 findFile ($class)
 

Private Member Functions

 findFileWithExtension ($class, $ext)
 

Private Attributes

 $prefixLengthsPsr4 = array()
 
 $prefixDirsPsr4 = array()
 
 $fallbackDirsPsr4 = array()
 
 $prefixesPsr0 = array()
 
 $fallbackDirsPsr0 = array()
 
 $useIncludePath = false
 
 $classMap = array()
 
 $classMapAuthoritative = false
 

Detailed Description

ClassLoader implements a PSR-0 class loader

See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md

$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 namespace or one of its children (Symfony 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.

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com
Jordi Boggiano j.bog.nosp@m.gian.nosp@m.o@sel.nosp@m.d.be

Definition at line 43 of file ClassLoader.php.

Member Function Documentation

add (   $prefix,
  $paths,
  $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$prefixThe prefix
array | string$pathsThe PSR-0 root directories
bool$prependWhether to prepend the directories

Definition at line 108 of file ClassLoader.php.

addClassMap ( array  $classMap)
Parameters
array$classMapClass to filename map

Definition at line 91 of file ClassLoader.php.

References ClassLoader\$classMap.

addPsr4 (   $prefix,
  $paths,
  $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$prefixThe prefix/namespace, with trailing '\'
array | string$pathsThe PSR-0 base directories
bool$prependWhether to prepend the directories
Exceptions
\InvalidArgumentException

Definition at line 155 of file ClassLoader.php.

References elseif.

findFile (   $class)

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

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

Definition at line 314 of file ClassLoader.php.

References ClassLoader\findFileWithExtension().

Referenced by ClassLoader\loadClass().

findFileWithExtension (   $class,
  $ext 
)
private

Definition at line 344 of file ClassLoader.php.

Referenced by ClassLoader\findFile().

getClassMap ( )

Definition at line 83 of file ClassLoader.php.

References ClassLoader\$classMap.

getFallbackDirs ( )

Definition at line 73 of file ClassLoader.php.

References ClassLoader\$fallbackDirsPsr0.

getFallbackDirsPsr4 ( )

Definition at line 78 of file ClassLoader.php.

References ClassLoader\$fallbackDirsPsr4.

getPrefixes ( )

Definition at line 59 of file ClassLoader.php.

getPrefixesPsr4 ( )

Definition at line 68 of file ClassLoader.php.

References ClassLoader\$prefixDirsPsr4.

getUseIncludePath ( )

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

Returns
bool

Definition at line 248 of file ClassLoader.php.

References ClassLoader\$useIncludePath.

isClassMapAuthoritative ( )

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

Returns
bool

Definition at line 269 of file ClassLoader.php.

References ClassLoader\$classMapAuthoritative.

loadClass (   $class)

Loads the given class or interface.

Parameters
string$classThe name of the class
Returns
bool|null True if loaded, null otherwise

Definition at line 298 of file ClassLoader.php.

References ClassLoader\findFile(), and Composer\Autoload\includeFile().

register (   $prepend = false)

Registers this instance as an autoloader.

Parameters
bool$prependWhether to prepend the autoloader or not

Definition at line 279 of file ClassLoader.php.

set (   $prefix,
  $paths 
)

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

Parameters
string$prefixThe prefix
array | string$pathsThe PSR-0 base directories

Definition at line 200 of file ClassLoader.php.

setClassMapAuthoritative (   $classMapAuthoritative)

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

Parameters
bool$classMapAuthoritative

Definition at line 259 of file ClassLoader.php.

References ClassLoader\$classMapAuthoritative.

setPsr4 (   $prefix,
  $paths 
)

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

Parameters
string$prefixThe prefix/namespace, with trailing '\'
array | string$pathsThe PSR-4 base directories
Exceptions
\InvalidArgumentException

Definition at line 218 of file ClassLoader.php.

setUseIncludePath (   $useIncludePath)

Turns on searching the include path for class files.

Parameters
bool$useIncludePath

Definition at line 237 of file ClassLoader.php.

References ClassLoader\$useIncludePath.

unregister ( )

Unregisters this instance as an autoloader.

Definition at line 287 of file ClassLoader.php.

Member Data Documentation

$classMap = array()
private

Definition at line 55 of file ClassLoader.php.

Referenced by ClassLoader\addClassMap(), and ClassLoader\getClassMap().

$classMapAuthoritative = false
private
$fallbackDirsPsr0 = array()
private

Definition at line 52 of file ClassLoader.php.

Referenced by ClassLoader\getFallbackDirs().

$fallbackDirsPsr4 = array()
private

Definition at line 48 of file ClassLoader.php.

Referenced by ClassLoader\getFallbackDirsPsr4().

$prefixDirsPsr4 = array()
private

Definition at line 47 of file ClassLoader.php.

Referenced by ClassLoader\getPrefixesPsr4().

$prefixesPsr0 = array()
private

Definition at line 51 of file ClassLoader.php.

$prefixLengthsPsr4 = array()
private

Definition at line 46 of file ClassLoader.php.

$useIncludePath = false
private

Definition at line 54 of file ClassLoader.php.

Referenced by ClassLoader\getUseIncludePath(), and ClassLoader\setUseIncludePath().