Map-based autoloader across php and phar resources

⌈⌋ ⎇ branch:  Canonic Autoloader


Artifact [c4276723f1]

Artifact c4276723f11db215a3c94fa025fd3a4c1664794c:

Wiki page [Canonic_Classmap] by mario 2014-02-15 02:20:18.
D 2014-02-15T02:20:18.152
L Canonic_Classmap
N text/x-markdown
P be62957bf6f4ad7f16fa403db0d38c5ad3cd4e52
U mario
W 1549
`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](wiki/classmap) 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 only 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");

Or update it also within the phar://
Z b3701b789ef6e655fb552096b955772e