class ClassMapManager

Keep package class replacements separate from the application's Composer map.

Allows packages to replace classes at the autoloader level, so the replacement file is loaded instead of the original. Already-loaded targets can only be registered again from the same source.

Properties

static protected array<class-string, string> $entries
static protected ClassLoader|null $loader
static protected bool $sealed

Methods

static void
add(array $map)

Add class map entries and apply them to the Composer autoloader.

static void
seal()

Close class map registration after application proxy generation.

static void
unseal()

Reopen class map registration while retaining the registered overrides.

static void
applyProxies(array $proxies)

Publish generated replacements with the lifetime of their source overrides.

static bool
hasEntries()

Determine if any class map entries have been registered.

static array
getEntries()

Get all registered class map entries.

static void
flushState()

Flush all static state.

Details

at line 43
static void add(array $map)

Add class map entries and apply them to the Composer autoloader.

Each entry maps an original class name to the path of its replacement file. Fails if a target is already loaded from a different source.

Class-map overrides mutate the worker's Composer autoloader and must be registered before application proxy generation and target loading.

Parameters

array $map

Return Value

void

at line 87
static void seal()

Close class map registration after application proxy generation.

Later registrations in this worker are rejected.

Return Value

void

at line 99
static void unseal()

Reopen class map registration while retaining the registered overrides.

This permits worker-wide autoloader changes for a new application bootstrap; already-loaded classes cannot be replaced.

Return Value

void

at line 112
static void applyProxies(array $proxies)

Publish generated replacements with the lifetime of their source overrides.

These autoload entries affect every request in the worker.

Parameters

array $proxies

Return Value

void

at line 121
static bool hasEntries()

Determine if any class map entries have been registered.

Return Value

bool

at line 131
static array getEntries()

Get all registered class map entries.

Return Value

array

at line 139
static void flushState()

Flush all static state.

Return Value

void