| Fully Qualified Name: | CodeIgniter\Autoloader\Autoloader |
CodeIgniter Autoloader
An autoloader that uses both PSR4 autoloading, and traditional classmaps.
Given a foo-bar package of classes in the file system at the following paths:
/path/to/packages/foo-bar/
/src
Baz.php # Foo\Bar\Baz
Qux/
Quux.php # Foo\Bar\Qux\Quux
you can add the path to the configuration array that is passed in the constructor. The Config array consists of 2 primary keys, both of which are associative arrays: 'psr4', and 'classmap'.
$Config = [
'psr4' => [
'Foo\Bar' => '/path/to/packages/foo-bar'
],
'classmap' => [
'MyClass' => '/path/to/class/file.php'
]
];
Example:
<?php
// our configuration array
$Config = [ ... ];
$loader = new \CodeIgniter\Autoloader\Autoloader($Config);
// register the autoloader
$loader->register();
| Name | Description | Defined By |
|---|---|---|
| addNamespace() | Registers namespaces with the autoloader. | Autoloader |
| getNamespace() | Get namespaces with prefixes as keys and paths as values. | Autoloader |
| initialize() | Reads in the configuration array (described above) and stores the valid parts that we'll need. | Autoloader |
| loadClass() | Loads the class file for a given class name. | Autoloader |
| register() | Register the loader with the SPL autoloader stack. | Autoloader |
| removeNamespace() | Removes a single namespace from the psr4 settings. | Autoloader |
| sanitizeFilename() | Sanitizes a filename, replacing spaces with dashes. | Autoloader |
Registers namespaces with the autoloader.
| Parameter Name | Type | Description |
|---|---|---|
| $namespace | array|string | |
| $path | string |
Returns: \Autoloader
Get namespaces with prefixes as keys and paths as values.
If a prefix param is set, returns only paths to the given prefix.
| Parameter Name | Type | Description |
|---|---|---|
| $prefix |
Returns: array
Reads in the configuration array (described above) and stores the valid parts that we'll need.
| Parameter Name | Type | Description |
|---|---|---|
| $config | \Config\Autoload | |
| $moduleConfig | \Config\Modules |
Returns: $this
Loads the class file for a given class name.
| Parameter Name | Type | Description |
|---|---|---|
| $class | string | The |
Returns: string|bool The mapped file on success, or boolean false on failure.
Register the loader with the SPL autoloader stack.
Returns:
Removes a single namespace from the psr4 settings.
| Parameter Name | Type | Description |
|---|---|---|
| $namespace | string |
Returns: \Autoloader
Sanitizes a filename, replacing spaces with dashes.
Removes special characters that are illegal in filenames on certain operating systems and special characters requiring special escaping to manipulate at the command line. Replaces spaces and consecutive dashes with a single dash. Trim period, dash and underscore from beginning and end of filename.
| Parameter Name | Type | Description |
|---|---|---|
| $filename | string |
Returns: string The sanitized filename