Map-based autoloader across php and phar resources

⌈⌋ ⎇ branch:  Canonic Autoloader


Artifact [c3b10ae405]

Artifact c3b10ae405a1a7245261fc2b001f5d289a5ecd85:

Wiki page [Canonic_Classmap] by mario 2014-02-13 17:54:41.
D 2014-02-13T17:54:41.678
L Canonic_Classmap
U mario
W 1496
`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");


Z 55ffcfc70c235f511d4c2c48766baf43