Composer\Autoload\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\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 <fabien@symfony.com>
Synopsis
class ClassLoader
{
- // members
- private array $prefixLengthsPsr4 = ;
- private array $prefixDirsPsr4 = ;
- private array $fallbackDirsPsr4 = ;
- private array $prefixesPsr0 = ;
- private array $fallbackDirsPsr0 = ;
- private boolean $useIncludePath = false;
- private array $classMap = ;
- private boolean $classMapAuthoritative = false;
- private array $missingClasses = ;
- private $apcuPrefix;
- // methods
- public void getPrefixes()
- public void getPrefixesPsr4()
- public void getFallbackDirs()
- public void getFallbackDirsPsr4()
- public void getClassMap()
- public void addClassMap()
- public void add()
- public void addPsr4()
- public void set()
- public void setPsr4()
- public void setUseIncludePath()
- public bool getUseIncludePath()
- public void setClassMapAuthoritative()
- public bool isClassMapAuthoritative()
- public void setApcuPrefix()
- public string|null getApcuPrefix()
- public void register()
- public void unregister()
- public bool|null loadClass()
- public string|false findFile()
- private void findFileWithExtension()
Members
private
- $apcuPrefix
- $classMap
- $classMapAuthoritative
- $fallbackDirsPsr0
- $fallbackDirsPsr4
- $missingClasses
- $prefixDirsPsr4
- $prefixLengthsPsr4
- $prefixesPsr0
- $useIncludePath
Methods
private
public
- add() — Registers a set of PSR-0 directories for a given prefix, either appending or prepending to the ones previously set for this prefix.
- addClassMap()
- addPsr4() — Registers a set of PSR-4 directories for a given namespace, either appending or prepending to the ones previously set for this namespace.
- findFile() — Finds the path to the file where the class is defined.
- getApcuPrefix() — The APCu prefix in use, or null if APCu caching is not enabled.
- getClassMap()
- getFallbackDirs()
- getFallbackDirsPsr4()
- getPrefixes()
- getPrefixesPsr4()
- getUseIncludePath() — Can be used to check if the autoloader uses the include path to check for classes.
- isClassMapAuthoritative() — Should class lookup fail if not found in the current class map?
- loadClass() — Loads the given class or interface.
- register() — Registers this instance as an autoloader.
- set() — Registers a set of PSR-0 directories for a given prefix, replacing any others previously set for this prefix.
- setApcuPrefix() — APCu prefix to use to cache found/not-found classes, if the extension is enabled.
- setClassMapAuthoritative() — Turns off searching the prefix and fallback directories for classes that have not been registered with the class map.
- setPsr4() — Registers a set of PSR-4 directories for a given namespace, replacing any others previously set for this namespace.
- setUseIncludePath() — Turns on searching the include path for class files.
- unregister() — Unregisters this instance as an autoloader.