Phalcon Class Autoloader
Loader is a class found under Phalcon\Loader directory. This class consists of some pre-defined rules according to rules it loads class automatically. It also handles error such as if a class does not exist but it is called in any part of program then special handler is called for handling.
In Loader if a class is added according to its need in program, performance is increased as only specific file is included. This technique is known as lazy initialization.
Phalcon\Loader have 4 methods to implement auto load classes:
This method is invoked when our code is organized using namespace or external libraries.
It takes an associative array, where keys are namespace prefix and their values are directories of their class location. Now, when the loader tries to find the class namespace separator is replaced by their directory separator.
Note: Always add trailing slash at end of the paths.
In this method, classes are under the register directories. This process is not performance effective as file stats increases for computing.
This method is used when project is placed in folder convention become ineffective for accessing files using class and path. It is the fastest method of auto loading but not recommended as maintenance cost is high.
This method is used for registering files that are non-classes. To register files we uses require. This method is very useful when files only have functions.