Map-based autoloader across php and phar resources

⌈⌋ branch:  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:

    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.