phpvms/app/Addons/AddonRegistry.php
Nabeel Shahzad ab4734e38f
refactor(addons): rename AddonRuntime to AddonBootCache and ManifestData to AddonManifest
- Updated class names across models, services, and related files to improve clarity.
- Adjusted type hints, annotations, and method signatures to reflect the renames.
- Improved code consistency and alignment with updated naming conventions.
2026-06-12 14:58:44 -05:00

64 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Addons;
use App\Addons\Models\AddonBootCache;
use App\Addons\Support\BootCache;
use App\Models\Addon;
use Illuminate\Support\Collection;
/**
* Read API over the boot cache and the addons table.
*
* Stateless and Octane-safe: reads fresh on every call. No mutable instance
* state — another Octane worker may have re-primed the cache between requests.
*/
class AddonRegistry
{
public function __construct(
private readonly BootCache $bootCache,
) {}
/**
* Return enabled addons from the boot cache (DB-free hot path, D-10).
*
* Returns an empty array when the cache is absent.
*
* @return Collection<AddonBootCache>
*/
public function enabled(): Collection
{
return collect(array_values(
array_filter(
$this->bootCache->read(),
fn (AddonBootCache $entry): bool => $entry->enabled,
)
));
}
/**
* Return an Eloquent Collection of every Addon row (enabled and disabled).
*
* @return Collection<AddonBootCache>
*/
public function all(): Collection
{
return collect(array_map(fn (AddonBootCache $record): AddonBootCache => $record, $this->bootCache->read()));
}
/**
* Find an Addon by registry_id or path.
*
* Returns null when no matching row is found.
*/
public function find(string $registryIdOrPath): ?Addon
{
return Addon::query()
->where('registry_id', $registryIdOrPath)
->orWhere('path', $registryIdOrPath)
->first();
}
}