Canonic_Autoloader
The Canonic_Autoloader
class in the phar stub implements the autoloader callback.
It's itself not a whole lot of code.
- The constructor just receives an
array
to populate the internal classmap from. - It looks for an identifier (class / func / const) declaration.
- Turning relative paths or phar:// references into absolute ones is the bulkiest part.
- And it contains some logic for autoupdating setups.
The vast remainder in the stub is a lot of setup and relocatability code:
- The static
::hookup()
just registers the autoloader, and is automatically run on including the phar. - With
::update()
the map gets recreated. - And
::pharBase()
just helps with figuring out if the stub is contained in a phar, or everything split up into separate scripts.
Manual instantiation
If you rip out the automatic hookup
code, then you can still easily register the autoloader. For a separated setup you'd use:
spl_autoload_register(
new Canonic_Autoloader(
include("./vendor/autoload.map.php"),
"./vendor/autoload.php"
)
);
The first argument being the array result from the map file. The second parameter refers to the base location of the autoloader/map script (just the base directory is actually required).
For manual updating see Canonic_Classmap
.