decodelabs/wellspring

PHP autoload management tools

v0.1.1 2024-03-04 17:24 UTC

This package is auto-updated.

Last update: 2024-04-29 09:09:10 UTC


README

PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

PHP autoload management tools

Wellspring provides simple tools to manage and configure autoloaders in PHP.

Get news and updates on the DecodeLabs blog.

Installation

Install via Composer:

composer require decodelabs/wellspring

Usage

Use Wellspring to register autoloaders with a Priority level - the higher the priority, the earlier the autoloader will be called.

The library automatically remaps loaders on the fly when necessary (even when spl_autoload_register() and spl_autoload_unregister() are used directly), ensuring edge-case functionality does not interfere with the intended load order.

Any loaders registered without a priority default to Priority::Medium, and any with matching priorities will be called in the order they were registered.

use DecodeLabs\Wellspring;
use DecodeLabs\Wellspring\Priority;

Wellspring::register(function(string $class) {
    // This will get called last
}, Priority::Low);

Wellspring::register(function(string $class) {
    // This will get called first
}, Priority::High);

spl_autoload_register(function(string $class) {
    // This will get called second
});

spl_autoload_call('test');

Licensing

Wellspring is licensed under the MIT License. See LICENSE for the full license text.