Map-based autoloader across php and phar resources

⌈⌋ branch:  Canonic Autoloader

Update of "Canonic_Autoloader"

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.


Artifact ID: 243f82d7475b6b34ae3b4a57094391957e56dd91
Page Name:Canonic_Autoloader
Date: 2014-02-13 21:48:06
Original User: mario

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:

    new Canonic_Autoloader(

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.