ClassLoader

Class loader

 class Winter\Storm\Support\ClassLoader

A simple autoloader used by Winter. Packages to be autoloaded are registered via App::make(ClassLoader::class)->autoloadPackage("Namespace\Prefix", "path/to/namespace"). It supports both the original October approach of all lowercase folder names with proper cased filenames and the PSR-4 approach of proper cased folder and filenames.

Properties

public $basePath : string

The base path.

public $files : Winter\Storm\Filesystem\Filesystem

The filesystem instance.

public $manifest : array | null

The loaded manifest array.

public $manifestPath : string | null

The manifest path.

protected $aliases : array

Class alias array.

protected $autoloadedPackages : array

The registered packages to autoload for

protected $loadedAliases : array

Aliases that have been explicitly loaded.

protected $manifestDirty : bool

Determine if the manifest needs to be written.

protected $namespaceAliases : array

Namespace alias array.

protected $registered : Closure | null

The registered callback for loading plugins.

protected $reversedClasses : array

Reversed classes to ignore for alias checks.

Methods

public __construct (Winter\Storm\Filesystem\Filesystem $files, string $basePath, string $manifestPath)

Create a new package manifest instance.

Parameters
Property Description
$files
Winter\Storm\Filesystem\Filesystem
$basePath
string
$manifestPath
string
Returns
mixed

public addAliases (array $aliases) : void

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
Property Description
$aliases
array
Returns
void

public addNamespaceAliases (array $namespaceAliases) : void

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
Property Description
$namespaceAliases
array
Returns
void

public autoloadPackage (string $namespacePrefix, string $path) : void

Add a namespace prefix to the autoloader

Parameters
Property Description
$namespacePrefix
string

The namespace prefix for this package

$path
string

The path to this package, either relative to the base path or absolute

Returns
void

public build () : void

Build the manifest and write it to disk.

Returns
void

public getAlias (string $class) : string | null

Gets an alias for a class, if available.

Parameters
Property Description
$class
string
Returns
string | null

public getNamespaceAliases (string $namespace) : array

Gets aliases registered for a namespace, if available.

Parameters
Property Description
$namespace
string
Returns
array

public getReverseAlias (string $class) : string | null

Gets a reverse alias for a class, if available.

Parameters
Property Description
$class
string
Returns
string | null

public load (string $class) : bool | null

Load the given class file.

Parameters
Property Description
$class
string
Returns
bool | null

public register () : void

Register the given class loader on the auto-loader stack.

Returns
void

public unregister () : void

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

Returns
void

protected ensureManifestIsLoaded () : void

Ensure the manifest has been loaded into memory.

Returns
void

protected includeClass (string $class, string $path) : void

Includes a class and adds to the manifest

Parameters
Property Description
$class
string
$path
string
Returns
void

protected isRealFilePath (string $path) : bool

Determine if the provided path to a file exists and is real

Parameters
Property Description
$path
string
Returns
bool

protected static normalizeClass (string $class) : string

Normalise the class name.

Parameters
Property Description
$class
string
Returns
string

protected resolvePath (string $path) : string

Resolve the provided path, relative or absolute

Parameters
Property Description
$path
string
Returns
string

protected write (array $manifest) : void

Write the given manifest array to disk.

Parameters
Property Description
$manifest
array
Returns
void
Copyright © 2024 Winter CMS