Files
rspade_system/app/RSpade/Core/Kernels/ManifestKernel.php
root 29c657f7a7 Exclude tests directory from framework publish
Add 100+ automated unit tests from .expect file specifications
Add session system test
Add rsx:constants:regenerate command test
Add rsx:logrotate command test
Add rsx:clean command test
Add rsx:manifest:stats command test
Add model enum system test
Add model mass assignment prevention test
Add rsx:check command test
Add migrate:status command test

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-25 03:59:58 +00:00

106 lines
2.4 KiB
PHP

<?php
namespace App\RSpade\Core\Kernels;
use InvalidArgumentException;
use App\RSpade\Core\Manifest\ManifestModule_Abstract;
/**
* Kernel that manages manifest processing modules
*/
#[Instantiatable]
class ManifestKernel
{
/**
* Registered modules
*/
protected array $modules = [];
/**
* Sorted modules cache
*/
protected ?array $sorted_modules = null;
/**
* Register a module
*/
public function register(string $module_class): void
{
if (!is_subclass_of($module_class, ManifestModule_Abstract::class)) {
throw new InvalidArgumentException(
"Module {$module_class} must extend " . ManifestModule_Abstract::class
);
}
$this->modules[] = $module_class;
$this->sorted_modules = null; // Clear cache
}
/**
* Process a file through all applicable modules
*/
public function process(string $file_path, array $metadata): array
{
$extension = $this->get_file_extension($file_path);
foreach ($this->get_sorted_modules() as $module) {
if (in_array($extension, $module->handles())) {
$metadata = $module->process($file_path, $metadata);
}
}
return $metadata;
}
/**
* Get modules sorted by priority
*/
public function get_sorted_modules(): array
{
if ($this->sorted_modules === null) {
$instances = array_map(
fn ($class) => app($class),
$this->modules
);
usort($instances, fn ($a, $b) => $a->priority() <=> $b->priority());
$this->sorted_modules = $instances;
}
return $this->sorted_modules;
}
/**
* Get file extension, handling double extensions like blade.php
*/
protected function get_file_extension(string $file_path): string
{
$filename = basename($file_path);
// Check for double extensions
if (preg_match('/\.blade\.php$/', $filename)) {
return 'blade.php';
}
return pathinfo($filename, PATHINFO_EXTENSION);
}
/**
* Clear all registered modules
*/
public function clear(): void
{
$this->modules = [];
$this->sorted_modules = null;
}
/**
* Get count of registered modules
*/
public function count(): int
{
return count($this->modules);
}
}