third_party/vfsstream/vendor/composer/ClassLoader.php
\Composer\Autoload\ClassLoader
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\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
- Author
- Jordi Boggiano
Methods
add
(string $prefix, array | string $paths, bool $prepend = false)
: void
Registers a set of PSR-0 directories for a given prefix, either appending or prepending to the ones previously set for this prefix.
Name | Type | Description |
---|---|---|
$prefix | string |
The prefix |
$paths | array | string |
The PSR-0 root directories |
$prepend | bool |
Whether to prepend the directories |
addClassMap
(array $classMap)
: void
Name | Type | Description |
---|---|---|
$classMap | array |
Class to filename map |
addPsr4
(string $prefix, array | string $paths, bool $prepend = false)
: void
Registers a set of PSR-4 directories for a given namespace, either appending or prepending to the ones previously set for this namespace.
Name | Type | Description |
---|---|---|
$prefix | string |
The prefix/namespace, with trailing '\' |
$paths | array | string |
The PSR-0 base directories |
$prepend | bool |
Whether to prepend the directories |
findFile
(string $class)
: string | false
Finds the path to the file where the class is defined.
Name | Type | Description |
---|---|---|
$class | string |
The name of the class |
Type | Description |
---|---|
string | false | The path if found, false otherwise |
getUseIncludePath
()
: bool
Can be used to check if the autoloader uses the include path to check for classes.
Type | Description |
---|---|
bool |
loadClass
(string $class)
: bool | null
Loads the given class or interface.
Name | Type | Description |
---|---|---|
$class | string |
The name of the class |
Type | Description |
---|---|
bool | null | True if loaded, null otherwise |
register
(bool $prepend = false)
: void
Registers this instance as an autoloader.
Name | Type | Description |
---|---|---|
$prepend | bool |
Whether to prepend the autoloader or not |
set
(string $prefix, array | string $paths)
: void
Registers a set of PSR-0 directories for a given prefix, replacing any others previously set for this prefix.
Name | Type | Description |
---|---|---|
$prefix | string |
The prefix |
$paths | array | string |
The PSR-0 base directories |
setPsr4
(string $prefix, array | string $paths)
: void
Registers a set of PSR-4 directories for a given namespace, replacing any others previously set for this namespace.
Name | Type | Description |
---|---|---|
$prefix | string |
The prefix/namespace, with trailing '\' |
$paths | array | string |
The PSR-4 base directories |
setUseIncludePath
(bool $useIncludePath)
: void
Turns on searching the include path for class files.
Name | Type | Description |
---|---|---|
$useIncludePath | bool |