forge/app/Observers/SptVersionObserver.php
Refringe db578071e4
SPT Semvar & Automatic Resolution
This update gives mod versions a supported SPT version field that accepts a semantic version. The latest supported SPT version will be automatically resolved based on the semvar.

Next up: I need to update the ModVersion to SptVersion relationship to be a many-to-many and expand the resolution to resolve multiple versions.
2024-08-22 17:04:07 -04:00

45 lines
889 B
PHP

<?php
namespace App\Observers;
use App\Models\ModVersion;
use App\Services\SptVersionService;
class SptVersionObserver
{
protected SptVersionService $sptVersionService;
public function __construct(SptVersionService $sptVersionService)
{
$this->sptVersionService = $sptVersionService;
}
/**
* Handle the SptVersion "saved" event.
*/
public function saved(): void
{
$this->resolveSptVersion();
}
/**
* Resolve the SptVersion's dependencies.
*/
private function resolveSptVersion(): void
{
$modVersions = ModVersion::all();
foreach ($modVersions as $modVersion) {
$this->sptVersionService->resolve($modVersion);
}
}
/**
* Handle the SptVersion "deleted" event.
*/
public function deleted(): void
{
$this->resolveSptVersion();
}
}