forked from fa/breadcrumb-the-shire
Completes the generic module platform that enables modules to contribute
UI elements, runtime JS components, and search resources without any
core hardcoding.
New generic UI slot types:
- topbar.right_item: module-contributed topbar buttons
- layout.body_end_template: module-contributed dialog/overlay templates
- layout.head_style: module-contributed global CSS
- runtime.component: declarative JS component registration with phase ordering
New infrastructure:
- ModuleAutoloader: PSR-4 autoloading for module-local PHP classes
- ModuleRuntimePageBuilder: symlinks module pages into runtime directory
- ModuleRuntimeAssetPublisher: publishes module CSS/JS to web/modules/
- ModulePermissionSynchronizer: syncs module permissions to DB
- CLI scripts: module-runtime-sync, module-build, module-migrate,
module-permissions-sync, module-assets-sync
- {{userId}} placeholder in SearchDataService for user-scoped search queries
- Component runtime with phased initialization (early/default/late)
- AppContainer.protectExistingBindings() to prevent module→core overwrites
- Architecture tests: ModuleStructureContractTest, CoreTemplateIsolationTest,
FrontendComponentRuntimeContractTest, AppContainerIsolationContractTest
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\App\Module;
|
|
|
|
/**
|
|
* Runtime autoloader for module-local PHP classes.
|
|
*
|
|
* Modules can place PHP code under modules/<id>/lib and use the same
|
|
* MintyPHP namespace root as core classes.
|
|
*/
|
|
final class ModuleAutoloader
|
|
{
|
|
/** @var list<string> */
|
|
private static array $moduleLibDirs = [];
|
|
|
|
private static bool $registered = false;
|
|
|
|
/**
|
|
* @param list<ModuleManifest> $manifests
|
|
*/
|
|
public static function register(array $manifests): void
|
|
{
|
|
$dirs = self::$moduleLibDirs;
|
|
foreach ($manifests as $manifest) {
|
|
$libDir = rtrim($manifest->basePath, '/') . '/lib';
|
|
if (is_dir($libDir)) {
|
|
$dirs[] = $libDir;
|
|
}
|
|
}
|
|
self::$moduleLibDirs = array_values(array_unique($dirs));
|
|
|
|
if (self::$registered) {
|
|
return;
|
|
}
|
|
|
|
spl_autoload_register([self::class, 'autoload'], true, true);
|
|
self::$registered = true;
|
|
}
|
|
|
|
private static function autoload(string $class): void
|
|
{
|
|
$prefix = 'MintyPHP\\';
|
|
if (!str_starts_with($class, $prefix)) {
|
|
return;
|
|
}
|
|
|
|
$relativePath = str_replace('\\', '/', substr($class, strlen($prefix))) . '.php';
|
|
foreach (self::$moduleLibDirs as $libDir) {
|
|
$candidate = $libDir . '/' . $relativePath;
|
|
if (is_file($candidate)) {
|
|
require_once $candidate;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|