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
= 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
= false
Determine if the manifest needs to be written.
protected
$namespaceAliases
:
array
= []
Namespace alias array.
protected
$registered
:
Closure
|
null
= 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.
Property | Type | Description |
---|---|---|
$files | Winter\Storm\Filesystem\Filesystem |
Winter\Storm\Filesystem\Filesystem
|
$basePath | string |
string
|
$manifestPath | string |
string
|
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.
Property | Type | Description |
---|---|---|
$aliases | array |
array
|
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.
Property | Type | Description |
---|---|---|
$namespaceAliases | array |
array
|
public autoloadPackage (string $namespacePrefix, string $path) : void
Add a namespace prefix to the autoloader
Property | Type | Description |
---|---|---|
$namespacePrefix | string |
string
The namespace prefix for this package |
$path | string |
string
The path to this package, either relative to the base path or absolute |
public build () : void
Build the manifest and write it to disk.
public getAlias (string $class) : string | null
Gets an alias for a class, if available.
Property | Type | Description |
---|---|---|
$class | string |
string
|
public getNamespaceAliases (string $namespace) : array
Gets aliases registered for a namespace, if available.
Property | Type | Description |
---|---|---|
$namespace | string |
string
|
public getReverseAlias (string $class) : string | null
Gets a reverse alias for a class, if available.
Property | Type | Description |
---|---|---|
$class | string |
string
|
public load (string $class) : bool | null
Load the given class file.
Property | Type | Description |
---|---|---|
$class | string |
string
|
public register () : void
Register the given class loader on the auto-loader stack.
public unregister () : void
De-register the given class loader on the auto-loader stack.
protected ensureManifestIsLoaded () : void
Ensure the manifest has been loaded into memory.
protected includeClass (string $class, string $path) : void
Includes a class and adds to the manifest
Property | Type | Description |
---|---|---|
$class | string |
string
|
$path | string |
string
|
protected isRealFilePath (string $path) : bool
Determine if the provided path to a file exists and is real
Property | Type | Description |
---|---|---|
$path | string |
string
|
protected static normalizeClass (string $class) : string
Normalise the class name.
Property | Type | Description |
---|---|---|
$class | string |
string
|
protected resolvePath (string $path) : string
Resolve the provided path, relative or absolute
Property | Type | Description |
---|---|---|
$path | string |
string
|
protected write (array $manifest) : void
Write the given manifest array to disk.
Property | Type | Description |
---|---|---|
$manifest | array |
array
|