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.
Methods | ||
---|---|---|
public
|
__construct(string|null $vendorDir = null)
|
# |
public
|
getPrefixes(): array<string, list<string>>
|
# |
public
|
getPrefixesPsr4(): array<string, list<string>>
|
# |
public
|
getFallbackDirs(): list<string>
|
# |
public
|
getFallbackDirsPsr4(): list<string>
|
# |
public
|
getClassMap(): array<string, string>
|
# |
public
|
addClassMap(array<string, string> $classMap): void
|
# |
public
|
add(string $prefix, list<string>|string $paths, bool $prepend = false): void
|
# |
public
|
addPsr4(string $prefix, list<string>|string $paths, bool $prepend = false): void
|
# |
public
|
set(string $prefix, list<string>|string $paths): void
|
# |
public
|
setPsr4(string $prefix, list<string>|string $paths): void
|
# |
public
|
setUseIncludePath(bool $useIncludePath): void
|
# |
public
|
getUseIncludePath(): bool
|
# |
public
|
setClassMapAuthoritative(bool $classMapAuthoritative): void
|
# |
public
|
isClassMapAuthoritative(): bool
|
# |
public
|
setApcuPrefix(string|null $apcuPrefix): void
|
# |
public
|
getApcuPrefix(): string|null
|
# |
public
|
register(bool $prepend = false): void
|
# |
public
|
unregister(): void
|
# |
public
|
loadClass(string $class): true|null
|
# |
public
|
findFile(string $class): string|false
|
# |
public
static
|
getRegisteredLoaders(): array<string, self>
|
# |