class ModelAliasAutoloader

Lets tinker users reference Eloquent models by their short name — e.g.

`User::find(1)` instead of `Flarum\User\User::find(1)`. Registered as a fallback autoloader, so it only runs when PHP fails to resolve a class by its given (short) name. On the first miss it indexes every registered PSR-4 root (core, extensions, and other Composer packages) by short name; when a bare name is requested it aliases the matching Eloquent model into the global namespace. This means third-party extension models are covered automatically, with no hardcoded list. The index is built once and cached for the lifetime of the shell.

Properties

protected array<string,list<class-string>>|null $index Short name => list of fully-qualified model class names.
protected array<string,true> $aliased Short names we have already aliased, so we don't do the work twice.
protected array<string,string> $facadeHints Laravel facades that don't exist in Flarum, mapped to the hint we show when someone reaches for them out of habit. Flarum doesn't register Laravel's facades, so these resolve to nothing without a nudge.

Methods

__construct(ClassLoader $loader, Closure $writeln)

No description

static ModelAliasAutoloader|null
register(Closure $writeln)

No description

void
unregister()

Remove this autoloader. Safe to call more than once.

void
load(string $class)

No description

array
buildIndex()

No description

void
scanDirectory(string $prefix, string $dir)

No description

static ClassLoader|null
findComposerLoader()

No description

Details

__construct(ClassLoader $loader, Closure $writeln)

Parameters

ClassLoader $loader
Closure $writeln

static ModelAliasAutoloader|null register(Closure $writeln)

Parameters

Closure $writeln

Return Value

ModelAliasAutoloader|null

void unregister()

Remove this autoloader. Safe to call more than once.

Return Value

void

void load(string $class)

Parameters

string $class

Return Value

void

protected array buildIndex()

Return Value

array

protected void scanDirectory(string $prefix, string $dir)

Parameters

string $prefix
string $dir

Return Value

void

static protected ClassLoader|null findComposerLoader()

Return Value

ClassLoader|null