mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-02 13:21:02 +00:00
* refactor: stabilize model identities for domain migration * refactor: extract module platform context * refactor: assign models to domain contexts * refactor: extract ai platform context * refactor: extract storage platform context * refactor: extract mail platform context * refactor: extract pdf platform context * refactor: extract operations platform context * refactor: move installation into operations platform * refactor: extract money domain context * refactor: extract taxation domain context * refactor: extract catalog domain context * refactor: extract metadata domain context * refactor: extract reporting domain context * refactor: extract purchases domain context * refactor: extract receivables domain context * refactor: extract accounts domain context * refactor: complete reporting statement boundary * refactor: extract contacts domain context * refactor: extract sales domain context * refactor: remove legacy application layers * fix: migrate legacy bouncer role identities
65 lines
2.0 KiB
PHP
65 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Platform\Modules\Runtime;
|
|
|
|
class ModuleRuntimeAutoloader
|
|
{
|
|
/** @var array<string, true> */
|
|
private static array $registered = [];
|
|
|
|
/**
|
|
* Register module PSR-4 prefixes before Laravel registers package providers.
|
|
*
|
|
* This intentionally uses native filesystem functions because bootstrap/app.php
|
|
* calls it before the service container and facades exist.
|
|
*/
|
|
public static function registerInstalledModules(?string $modulesPath = null): void
|
|
{
|
|
$modulesPath ??= dirname(__DIR__, 4).'/Modules';
|
|
|
|
if (! is_dir($modulesPath)) {
|
|
return;
|
|
}
|
|
|
|
$directories = glob(rtrim($modulesPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR) ?: [];
|
|
|
|
foreach ($directories as $directory) {
|
|
$name = basename($directory);
|
|
|
|
if (preg_match('/^[A-Z][A-Za-z0-9]*$/', $name) === 1 && is_file($directory.'/module.json')) {
|
|
self::register($name, $modulesPath);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function register(string $name, ?string $modulesPath = null): void
|
|
{
|
|
$modulesPath ??= dirname(__DIR__, 4).'/Modules';
|
|
$prefix = "Modules\\{$name}\\";
|
|
$base = rtrim($modulesPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$name.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR;
|
|
$registration = $prefix.$base;
|
|
|
|
if (isset(self::$registered[$registration])) {
|
|
return;
|
|
}
|
|
|
|
spl_autoload_register(static function (string $class) use ($prefix, $base): void {
|
|
if (! str_starts_with($class, $prefix)) {
|
|
return;
|
|
}
|
|
|
|
$relative = substr($class, strlen($prefix));
|
|
if ($relative === false || str_contains($relative, '..')) {
|
|
return;
|
|
}
|
|
|
|
$path = $base.str_replace('\\', '/', $relative).'.php';
|
|
if (is_file($path)) {
|
|
require_once $path;
|
|
}
|
|
});
|
|
|
|
self::$registered[$registration] = true;
|
|
}
|
|
}
|