Menu

## ClassLoader
in package

ClassLoader.php : 43

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.

##### Tags

author

  Fabien Potencier fabien@symfony.com

author

  Jordi Boggiano j.boggiano@seld.be

see
  http://www.php-fig.org/psr/psr-0/
see
  http://www.php-fig.org/psr/psr-4/

### Table of Contents

$apcuPrefix : mixed
$classMap : mixed
$classMapAuthoritative : mixed
$fallbackDirsPsr0 : mixed
$fallbackDirsPsr4 : mixed
$missingClasses : mixed
$prefixDirsPsr4 : mixed
$prefixesPsr0 : mixed
$prefixLengthsPsr4 : mixed
$useIncludePath : mixed
add() : mixed
  Registers a set of PSR-0 directories for a given prefix, either appending or prepending to the ones previously set for this prefix.
addClassMap() : mixed
addPsr4() : mixed
  Registers a set of PSR-4 directories for a given namespace, either appending or prepending to the ones previously set for this namespace.
findFile() : string|false
  Finds the path to the file where the class is defined.
getApcuPrefix() : string|null
  The APCu prefix in use, or null if APCu caching is not enabled.
getClassMap() : mixed
getFallbackDirs() : mixed
getFallbackDirsPsr4() : mixed
getPrefixes() : mixed
getPrefixesPsr4() : mixed
getUseIncludePath() : bool
  Can be used to check if the autoloader uses the include path to check for classes.
isClassMapAuthoritative() : bool
  Should class lookup fail if not found in the current class map?
loadClass() : bool|null
  Loads the given class or interface.
register() : mixed
  Registers this instance as an autoloader.
set() : mixed
  Registers a set of PSR-0 directories for a given prefix, replacing any others previously set for this prefix.
setApcuPrefix() : mixed
  APCu prefix to use to cache found/not-found classes, if the extension is enabled.
setClassMapAuthoritative() : mixed
  Turns off searching the prefix and fallback directories for classes that have not been registered with the class map.
setPsr4() : mixed
  Registers a set of PSR-4 directories for a given namespace, replacing any others previously set for this namespace.
setUseIncludePath() : mixed
  Turns on searching the include path for class files.
unregister() : mixed
  Unregisters this instance as an autoloader.
findFileWithExtension() : mixed

### Properties

#### $apcuPrefix

ClassLoader.php : 58
`private mixed $apcuPrefix`

#### $classMap

ClassLoader.php : 55
`private mixed $classMap = array()`

#### $classMapAuthoritative

ClassLoader.php : 56
`private mixed $classMapAuthoritative = false`

#### $fallbackDirsPsr0

ClassLoader.php : 52
`private mixed $fallbackDirsPsr0 = array()`

#### $fallbackDirsPsr4

ClassLoader.php : 48
`private mixed $fallbackDirsPsr4 = array()`

#### $missingClasses

ClassLoader.php : 57
`private mixed $missingClasses = array()`

#### $prefixDirsPsr4

ClassLoader.php : 47
`private mixed $prefixDirsPsr4 = array()`

#### $prefixesPsr0

ClassLoader.php : 51
`private mixed $prefixesPsr0 = array()`

#### $prefixLengthsPsr4

ClassLoader.php : 46
`private mixed $prefixLengthsPsr4 = array()`

#### $useIncludePath

ClassLoader.php : 54
`private mixed $useIncludePath = false`

### Methods

#### add()

ClassLoader.php : 109

Registers a set of PSR-0 directories for a given prefix, either appending or prepending to the ones previously set for this prefix.

`public add(string $prefix, array<string|int, mixed>|string $paths[, bool $prepend = false ]) : mixed`

##### Parameters

$prefix : string

  The prefix

$paths : array<string|int, mixed>|string

  The PSR-0 root directories

$prepend : bool = false

  Whether to prepend the directories

##### Return values

mixed —

#### addClassMap()

ClassLoader.php : 92
`public addClassMap(array<string|int, mixed> $classMap) : mixed`

##### Parameters

$classMap : array<string|int, mixed>

  Class to filename map

##### Return values

mixed —

#### addPsr4()

ClassLoader.php : 156

Registers a set of PSR-4 directories for a given namespace, either appending or prepending to the ones previously set for this namespace.

`public addPsr4(string $prefix, array<string|int, mixed>|string $paths[, bool $prepend = false ]) : mixed`

##### Parameters

$prefix : string

  The prefix/namespace, with trailing '\'

$paths : array<string|int, mixed>|string

  The PSR-4 base directories

$prepend : bool = false

  Whether to prepend the directories

##### Tags

throws
  InvalidArgumentException

##### Return values

mixed —

#### findFile()

ClassLoader.php : 335

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

`public findFile(string $class) : string|false`

##### Parameters

$class : string

  The name of the class

##### Return values

string|false —

The path if found, false otherwise

#### getApcuPrefix()

ClassLoader.php : 290

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

`public getApcuPrefix() : string|null`

##### Return values

string|null —

#### getClassMap()

ClassLoader.php : 84
`public getClassMap() : mixed`

##### Return values

mixed —

#### getFallbackDirs()

ClassLoader.php : 74
`public getFallbackDirs() : mixed`

##### Return values

mixed —

#### getFallbackDirsPsr4()

ClassLoader.php : 79
`public getFallbackDirsPsr4() : mixed`

##### Return values

mixed —

#### getPrefixes()

ClassLoader.php : 60
`public getPrefixes() : mixed`

##### Return values

mixed —

#### getPrefixesPsr4()

ClassLoader.php : 69
`public getPrefixesPsr4() : mixed`

##### Return values

mixed —

#### getUseIncludePath()

ClassLoader.php : 249

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

`public getUseIncludePath() : bool`

##### Return values

bool —

#### isClassMapAuthoritative()

ClassLoader.php : 270

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

`public isClassMapAuthoritative() : bool`

##### Return values

bool —

#### loadClass()

ClassLoader.php : 319

Loads the given class or interface.

`public loadClass(string $class) : bool|null`

##### Parameters

$class : string

  The name of the class

##### Return values

bool|null —

True if loaded, null otherwise

#### register()

ClassLoader.php : 300

Registers this instance as an autoloader.

`public register([bool $prepend = false ]) : mixed`

##### Parameters

$prepend : bool = false

  Whether to prepend the autoloader or not

##### Return values

mixed —

#### set()

ClassLoader.php : 201

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

`public set(string $prefix, array<string|int, mixed>|string $paths) : mixed`

##### Parameters

$prefix : string

  The prefix

$paths : array<string|int, mixed>|string

  The PSR-0 base directories

##### Return values

mixed —

#### setApcuPrefix()

ClassLoader.php : 280

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

`public setApcuPrefix(string|null $apcuPrefix) : mixed`

##### Parameters

$apcuPrefix : string|null

##### Return values

mixed —

#### setClassMapAuthoritative()

ClassLoader.php : 260

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

`public setClassMapAuthoritative(bool $classMapAuthoritative) : mixed`

##### Parameters

$classMapAuthoritative : bool

##### Return values

mixed —

#### setPsr4()

ClassLoader.php : 219

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

`public setPsr4(string $prefix, array<string|int, mixed>|string $paths) : mixed`

##### Parameters

$prefix : string

  The prefix/namespace, with trailing '\'

$paths : array<string|int, mixed>|string

  The PSR-4 base directories

##### Tags

throws
  InvalidArgumentException

##### Return values

mixed —

#### setUseIncludePath()

ClassLoader.php : 238

Turns on searching the include path for class files.

`public setUseIncludePath(bool $useIncludePath) : mixed`

##### Parameters

$useIncludePath : bool

##### Return values

mixed —

#### unregister()

ClassLoader.php : 308

Unregisters this instance as an autoloader.

`public unregister() : mixed`

##### Return values

mixed —

#### findFileWithExtension()

ClassLoader.php : 370
`private findFileWithExtension(mixed $class, mixed $ext) : mixed`

##### Parameters

$class : mixed
$ext : mixed

##### Return values

mixed —

## Search results