Autoloader Class
The Autoloader class contains Fuel's autoloader function. It also supplies methods to interact with the autoloading process.
add_namespace($namespace, $path, $psr = false)
The add_namespace method adds a namespace and path.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$namespace |
required |
the namespace |
$path |
required |
path to the namespace |
$psr |
false
|
set to true to indicate that this is a PSR-0 compliant namespace. |
|
Returns |
Void |
Example |
Autoloader::add_namespace('Mynamespace', PKGPATH.'mynamespace/');
// With nested namespaces note the double backslash
Autoloader::add_namespace('Nested\\Namespace', PKGPATH.'nested/');
|
add_namespaces($namespace, $prepend = false)
The add_namespaces method adds an array of namespaces.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$namespace |
required |
an array of namespaces |
$prepend |
false |
set to true if you want to prepend. |
|
Returns |
Void |
Example |
Autoloader::add_namespaces(array(
'Mynamespace' => PKGPATH.'mynamespace/',
'Othernamespace' => PKGPATH.'othernamespace/',
));
|
namespace_path($namespace)
The namespace_path method retrieves the path to a namespace.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$namespace |
required |
the namespace |
|
Returns |
path to the namespace or false when it doesn't exist |
Example |
// /path/to/mynamespace/
$path = Autoloader::namespace_path('Mynamespace');
// false
$path = Autoloader::namespace_path('Unknown\\Namespace');
|
add_class($class, $path)
The add_class method adds a class path.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$class |
required |
the class name |
$path |
required |
the path to the class file |
|
Returns |
Void |
Example |
Autoloader::add_class('Namespace\\Class', PKGPATH.'namespace/classes/class.php');
|
add_classes($classes)
The add_class method adds an array of classes.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$classes |
required |
the array of classes |
|
Returns |
Void |
Example |
Autoloader::add_classes(array(
'Namespace\\Class' => PKGPATH.'namespace/classes/class.php',
'Namespace\\Other' => PKGPATH.'namespace/classes/other.php',
));
|
alias_to_namespace($class, $namespace = '')
The alias_to_namespace method aliases a class to a namespace, the root by default.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$class |
required |
the class name |
$namespace |
'' |
the namespace to alias to |
|
Returns |
Void |
Example |
Autoloader::alias_to_namespace('Mynamespace\\Myclass');
// Alias it to a namespace
Autoloader::alias_to_namespace('Mynamespace\\Myclass', 'Other\\Namespace\\');
|
add_core_namespace($namespace, $prefix = false)
The add_core_namespace method adds a namespace for which classes may be used without the namespace prefix and
will be auto-aliased to the global namespace. Prefixing the classes will overwrite core classes and previously added namespaces.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$namespace |
required |
the namespace |
$prefix |
false |
set to true to prefix the namespace |
|
Returns |
Void |
Example |
Autoloader::add_core_namespace('Mynamespace');
|
load($class)
The load method tries to find the class, load it, and fire its _init function if exists.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$class |
required |
the class name |
|
Returns |
Void |
Example |
Autoloader::load('Model_Users');
|
Procedural helpers
import($path, $folder = 'classes')
The import function imports a php file inside COREPATH.
Parameters |
Param |
Type |
Default |
Description |
$path |
string |
required |
the path to the file |
$folder |
string |
'classes'
|
the folder to prefix the path, relative to COREPATH |
|
Returns |
string |
Example |
// import Spyc
import('spyc/spyc', 'vendor');
|