Версия: 6.x
burger close
Класс ClassLoader

Подробное описание

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 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.

Автор
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
См. также
https://www.php-fig.org/psr/psr-0/
https://www.php-fig.org/psr/psr-4/

Открытые члены

 __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 getRegisteredLoaders ()
 

Конструктор(ы)

__construct (   $vendorDir = null)
Аргументы
?string$vendorDir

Методы

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.

Аргументы
string$prefixThe prefix
string[]|string$paths The PSR-0 root directories
bool$prependWhether to prepend the directories
Возвращает
void
addClassMap ( array  $classMap)
Аргументы
string[]$classMap Class to filename map -param array<string, string> $classMap
Возвращает
void
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.

Аргументы
string$prefixThe prefix/namespace, with trailing '\'
string[]|string$paths The PSR-4 base directories
bool$prependWhether to prepend the directories
Исключения
\InvalidArgumentException
Возвращает
void
findFile (   $class)

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

Аргументы
string$classThe name of the class
Возвращает
string|false The path if found, false otherwise
getApcuPrefix ( )

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

Возвращает
string|null
getClassMap ( )
Возвращает
string[] Array of classname => path -return array<string, string>
getFallbackDirs ( )
Возвращает
array[] -return array<string, string>
getFallbackDirsPsr4 ( )
Возвращает
array[] -return array<string, string>
getPrefixes ( )
Возвращает
string[]
getPrefixesPsr4 ( )
Возвращает
array[] -return array<string, array<int, string>>
static getRegisteredLoaders ( )
static

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

Возвращает
self[]
getUseIncludePath ( )

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

Возвращает
bool
isClassMapAuthoritative ( )

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

Возвращает
bool
loadClass (   $class)

Loads the given class or interface.

Аргументы
string$classThe name of the class
Возвращает
true|null True if loaded, null otherwise
register (   $prepend = false)

Registers this instance as an autoloader.

Аргументы
bool$prependWhether to prepend the autoloader or not
Возвращает
void
set (   $prefix,
  $paths 
)

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

Аргументы
string$prefixThe prefix
string[]|string$paths The PSR-0 base directories
Возвращает
void
setApcuPrefix (   $apcuPrefix)

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

Аргументы
string | null$apcuPrefix
Возвращает
void
setClassMapAuthoritative (   $classMapAuthoritative)

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

Аргументы
bool$classMapAuthoritative
Возвращает
void
setPsr4 (   $prefix,
  $paths 
)

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

Аргументы
string$prefixThe prefix/namespace, with trailing '\'
string[]|string$paths The PSR-4 base directories
Исключения
\InvalidArgumentException
Возвращает
void
setUseIncludePath (   $useIncludePath)

Turns on searching the include path for class files.

Аргументы
bool$useIncludePath
Возвращает
void
unregister ( )

Unregisters this instance as an autoloader.

Возвращает
void