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: c4276723f11db215a3c94fa025fd3a4c1664794c
Page Name:Canonic_Classmap
Date: 2014-02-15 02:20:18
Original User: mario
Mimetype:text/x-markdown
Parent: be62957bf6f4ad7f16fa403db0d38c5ad3cd4e52 (diff)
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 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 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://