Phalcon loader
NOTE
All classes are prefixed with Phalcon
Loader¶
-
Namespace
Phalcon\Autoload
-
Uses
Phalcon\Events\AbstractEventsAware
-
Extends
AbstractEventsAware
-
Implements
This component helps to load your project classes automatically based on some conventions
use Phalcon\Loader;
// Creates the autoloader
$loader = new Loader();
// Register some namespaces
$loader->registerNamespaces(
[
"Example\\Base" => "vendor/example/base/",
"Example\\Adapter" => "vendor/example/adapter/",
"Example" => "vendor/example/",
]
);
// Register autoloader
$loader->register();
// Requiring this class will automatically include file vendor/example/adapter/Some.php
$adapter = new \Example\Adapter\Some();
Properties¶
//
protected $checkedPath;
/**
* @var array
*/
protected $classes;
/**
* @var array
*/
protected $directories;
/**
* @var array
*/
protected $directories;
/**
* @var array
*/
protected $extensions;
/**
* @var string|callable
*/
protected $fileCheckingCallback = 'is_file';
/**
* @var array
*/
protected $files;
/**
* @var bool
*/
protected $foundPath;
/**
* @var array
*/
protected $namespaces;
/**
* @var bool
*/
protected $registered = false;
Methods¶
Autoloads the registered classes Get the path the loader is checking for a path Returns the class-map currently registered in the autoloader Returns the directories currently registered in the autoloader Returns the internal event manager Returns the file extensions registered in the loader Returns the files currently registered in the autoloader Get the path when a class was found Returns the namespaces currently registered in the autoloader Checks if a file exists and then adds the file by doing virtual require Register the autoload method Register classes and their locations Register directories in which "not found" classes could be found Registers files that are "non-classes" hence need a "require". This is very useful for including files that only have functions Register namespaces and their related directories Sets the events manager Sets an array of file extensions that the loader must try in each attempt to locate the file Sets the file check callback.// Default behavior.
$loader->setFileCheckingCallback("is_file");
// Faster than `is_file()`, but implies some issues if
// the file is removed from the filesystem.
$loader->setFileCheckingCallback("stream_resolve_include_path");
// Do not check file existence.
$loader->setFileCheckingCallback(null);
Loader\Exception¶
-
Namespace
Phalcon\Autoload
-
Uses
-
Extends
\Exception
-
Implements Exceptions thrown in Phalcon\Loader will use this class