Map-based autoloader across php and phar resources

⌈⌋ ⎇ branch:  Canonic Autoloader


Update of "Canonic_Classmap"

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

Overview

Artifact ID: c3b10ae405a1a7245261fc2b001f5d289a5ecd85
Page Name:Canonic_Classmap
Date: 2014-02-13 17:54:41
Original User: mario
Next f737e8dbb4859ef5adf08f0a9e6dd128aa78ddda
Content

`Canonic_Classmap` implements the php script traversal, tokenization and map building process.

Usually it's run via the static `::update()` method. If run from the default `Canonic_Autoloader`(wiki/Canonic_Autoloader) mechanism, it just cares about the directory tree it resides in.

It can however map multiple source repositories. For instance:

Canonic_Classmap::update( "phar://./shared.phar/autoload.map.php", array(__DIR__, "/usr/share/php") );

Will read in the surrounding tree, but also the global path. An identifier map of both will be stored within the phar.

It's important to understand that only file references from the first directory will be converted into relative paths. The `/usr/share/php/*` filenames will stay absolute.

If such a manual updating procedure is in place, automatic updating via `shared.phar` itself shouldn't be utilized further. It would still just default to handling just the directory tree it's contained in.

### More specific

You can also forgo the static `::update` approach, and handle the details yourself:

$cm = new Canonic_Classmap;

And read in directories yourself:

$cm->process_dir("./vendor"); $cm->process_dir("../includes"); $cm->process_dir("/usr/share/php");

None of the mapped paths will be relative then.

You then have to write the results somewhere yourself in a format that `shared.phar` or its stub can use:

$cm->write("./autoload.map.php");