class ClassLoader

Class loader

A simple autoloader used by Winter, it expects the folder names to be lower case and the file name to be capitalized as per the class name.

Properties

Filesystem $files

The filesystem instance.

string $basePath

The base path.

string|null $manifestPath

The manifest path.

array $manifest

The loaded manifest array.

protected array $directories

The registered directories.

protected bool $registered

Indicates if a loader has been registered.

protected bool $manifestIsDirty

Determine if the manifest needs to be written.

protected array $aliases

Class alias array.

protected array $namespaceAliases

Namespace alias array.

protected array $loadedAliases

Aliases that have been explicitly loaded.

protected array $reversedClasses

Reversed classes to ignore for alias checks.

Methods

__construct(Filesystem $files, $basePath, $manifestPath)

No description

void
register()

Register loader with SPL autoloader stack.

void
unregister()

De-register the given class loader on the auto-loader stack.

void
build()

Build the manifest and write it to disk.

bool|null
load(string $class)

Load the given class file.

array
getDirectories()

Gets all the directories registered with the loader.

void
addDirectories(string|array $directories)

Add directories to the class loader.

void
removeDirectories(string|array $directories = null)

Remove directories from the class loader.

void
addAliases(array $aliases)

Adds alias to the class loader.

void
addNamespaceAliases(array $namespaceAliases)

Adds namespace aliases to the class loader.

string|null
getAlias(string $class)

Gets an alias for a class, if available.

array
getNamespaceAliases(string $namespace)

Gets aliases registered for a namespace, if available.

string|null
getReverseAlias(string $class)

Gets a reverse alias for a class, if available.

static string
normalizeClass(string $class)

Normalise the class name.

static array
getPathsForClass(string $class)

Get the possible paths for a class.

bool|string
loadMappedClass(string $class)

Load the mapped class for a directory prefix and relative class.

bool
isRealFilePath(string $path)

Determine if a relative path to a file exists and is real

void
includeClass(string $class, string $path)

Includes a class and adds to the manifest

void
ensureManifestIsLoaded()

Ensure the manifest has been loaded into memory.

void
write(array $manifest)

Write the manifest array to filesystem.

Details

at line 87
__construct(Filesystem $files, $basePath, $manifestPath)

No description

Parameters

Filesystem $files
$basePath
$manifestPath

at line 98
void register()

Register loader with SPL autoloader stack.

Return Value

void

at line 114
void unregister()

De-register the given class loader on the auto-loader stack.

Return Value

void

at line 129
void build()

Build the manifest and write it to disk.

Return Value

void

at line 144
bool|null load(string $class)

Load the given class file.

Parameters

string $class

Return Value

bool|null

at line 208
array getDirectories()

Gets all the directories registered with the loader.

Return Value

array

at line 220
void addDirectories(string|array $directories)

Add directories to the class loader.

Parameters

string|array $directories

Return Value

void

at line 234
void removeDirectories(string|array $directories = null)

Remove directories from the class loader.

Parameters

string|array $directories

Return Value

void

at line 257
void addAliases(array $aliases)

Adds alias to the class loader.

Aliases are first-come, first-served. If a real class already exists with the same name as an alias, the real class is used over the alias.

Parameters

array $aliases

Return Value

void

at line 277
void addNamespaceAliases(array $namespaceAliases)

Adds namespace aliases to the class loader.

Similar to the "addAliases" method, but applies across an entire namespace.

Aliases are first-come, first-served. If a real class already exists with the same name as an alias, the real class is used over the alias.

Parameters

array $namespaceAliases

Return Value

void

at line 294
string|null getAlias(string $class)

Gets an alias for a class, if available.

Parameters

string $class

Return Value

string|null

at line 313
array getNamespaceAliases(string $namespace)

Gets aliases registered for a namespace, if available.

Parameters

string $namespace

Return Value

array

at line 331
string|null getReverseAlias(string $class)

Gets a reverse alias for a class, if available.

Parameters

string $class

Return Value

string|null

at line 354
static protected string normalizeClass(string $class)

Normalise the class name.

Parameters

string $class

Return Value

string

at line 374
static protected array getPathsForClass(string $class)

Get the possible paths for a class.

Parameters

string $class

Return Value

array

at line 401
protected bool|string loadMappedClass(string $class)

Load the mapped class for a directory prefix and relative class.

Parameters

string $class

The class name.

Return Value

bool|string

bool false if no mapped file can be load ed, or the name of the mapped file that was loaded.

at line 432
protected bool isRealFilePath(string $path)

Determine if a relative path to a file exists and is real

Parameters

string $path

Return Value

bool

at line 444
protected void includeClass(string $class, string $path)

Includes a class and adds to the manifest

Parameters

string $class
string $path

Return Value

void

at line 458
protected void ensureManifestIsLoaded()

Ensure the manifest has been loaded into memory.

Return Value

void

at line 489
protected void write(array $manifest)

Write the manifest array to filesystem.

Parameters

array $manifest

Return Value

void

Exceptions

Exception