API - XOOPS 2.5.11 Beta 2
By monxoops.fr
ClassLoader Class Reference

Public Member Functions

 __construct ($vendorDir=null)
 
 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 ()
 
 setApcuPrefix ($apcuPrefix)
 
 getApcuPrefix ()
 
 register ($prepend=false)
 
 unregister ()
 
 loadClass ($class)
 
 findFile ($class)
 

Static Public Member Functions

static getRegisteredLoaders ()
 

Detailed Description

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.

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
See also
https://www.php-fig.org/psr/psr-0/
https://www.php-fig.org/psr/psr-4/

Constructor & Destructor Documentation

◆ __construct()

__construct (   $vendorDir = null)
Parameters
?string$vendorDir

Member Function Documentation

◆ add()

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
string[] | string$pathsThe PSR-0 root directories
bool$prependWhether to prepend the directories
Returns
void

◆ addClassMap()

addClassMap ( array  $classMap)
Parameters
string[]$classMapClass to filename map @psalm-param array<string, string> $classMap
Returns
void

◆ addPsr4()

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 '\'
string[] | string$pathsThe PSR-4 base directories
bool$prependWhether to prepend the directories
Exceptions

InvalidArgumentException

Returns
void

◆ findFile()

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
Here is the caller graph for this function:

◆ getApcuPrefix()

getApcuPrefix ( )

The APCu prefix in use, or null if APCu caching is not enabled.

Returns
string|null

◆ getClassMap()

getClassMap ( )
Returns
string[] Array of classname => path @psalm-return array<string, string>

◆ getFallbackDirs()

getFallbackDirs ( )
Returns
array[] @psalm-return array<string, string>

◆ getFallbackDirsPsr4()

getFallbackDirsPsr4 ( )
Returns
array[] @psalm-return array<string, string>

◆ getPrefixes()

getPrefixes ( )
Returns
string[]

◆ getPrefixesPsr4()

getPrefixesPsr4 ( )
Returns
array[] @psalm-return array<string, array<int, string>>

◆ getRegisteredLoaders()

static getRegisteredLoaders ( )
static

Returns the currently registered loaders indexed by their corresponding vendor directories.

Returns
self[]

◆ getUseIncludePath()

getUseIncludePath ( )

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

Returns
bool

◆ isClassMapAuthoritative()

isClassMapAuthoritative ( )

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

Returns
bool

◆ loadClass()

loadClass (   $class)

Loads the given class or interface.

Parameters
string$classThe name of the class
Returns
true|null True if loaded, null otherwise
Here is the call graph for this function:

◆ register()

register (   $prepend = false)

Registers this instance as an autoloader.

Parameters
bool$prependWhether to prepend the autoloader or not
Returns
void

◆ set()

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
string[] | string$pathsThe PSR-0 base directories
Returns
void

◆ setApcuPrefix()

setApcuPrefix (   $apcuPrefix)

APCu prefix to use to cache found/not-found classes, if the extension is enabled.

Parameters
string | null$apcuPrefix
Returns
void

◆ setClassMapAuthoritative()

setClassMapAuthoritative (   $classMapAuthoritative)

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

Parameters
bool$classMapAuthoritative
Returns
void

◆ setPsr4()

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 '\'
string[] | string$pathsThe PSR-4 base directories
Exceptions

InvalidArgumentException

Returns
void

◆ setUseIncludePath()

setUseIncludePath (   $useIncludePath)

Turns on searching the include path for class files.

Parameters
bool$useIncludePath
Returns
void

◆ unregister()

unregister ( )

Unregisters this instance as an autoloader.

Returns
void

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