Map-based autoloader across php and phar resources

⌈⌋ ⎇ branch:  Canonic Autoloader


AUTOLOADER_UPDATE

automatic classmap updating

The disadvantage of map-based autoloaders is the rebuilding step, at least for development.

While the update is undeniably easy, it's also redundant with the built-in automatic updating on missed identifier lookups.

You can declare a locally-installed shared.phar autoloader to update itself on undefined and unlocalizable classes (= newly added code).

.htaccess

With

SetEnv AUTOLOADER_UPDATE 1

in your .htaccess you can trigger the auto update run.

In code

Or just override it prior inclusion of the autoloader:

$_SERVER["AUTOLOADER_UPDATE"] = TRUE;
include_once("./vendor/shared.phar");

Adapt the stub

Some installations may wish to update the shared.phars stub itself.

It contains a setting:

    // Try to rebuild map on missing identifiers.
    public $auto_update = 0;

Which could be predeclared to 1 obviously.

This requires unpacking and repacking the phar or its stub just once.

Global vs. local install

The global /usr/share/php/shared.phar will not typically auto-update (non-writable). While an alongside activated local ./vendor/shared.phar may.

You may then wish to instantiate the local loader last however; else the rebuilding attempt will trigger on each invocation where globally-installed classes are requested first.

Deployment

If you upload shared.phar together with the class repository beneath it, the contained map with its relative paths will continue to work. Unless the phar is writable (e.g. suexec setups) the automatic updates won't run.