2024-07-26 02:19:42 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Observers;
|
|
|
|
|
2024-08-22 17:04:07 -04:00
|
|
|
use App\Exceptions\CircularDependencyException;
|
2024-07-26 02:19:42 -04:00
|
|
|
use App\Models\ModDependency;
|
|
|
|
use App\Models\ModVersion;
|
2024-08-22 17:04:07 -04:00
|
|
|
use App\Services\DependencyVersionService;
|
2024-07-26 02:19:42 -04:00
|
|
|
|
|
|
|
class ModDependencyObserver
|
|
|
|
{
|
2024-08-22 17:04:07 -04:00
|
|
|
protected DependencyVersionService $dependencyVersionService;
|
2024-07-26 02:19:42 -04:00
|
|
|
|
2024-08-22 17:04:07 -04:00
|
|
|
public function __construct(DependencyVersionService $dependencyVersionService)
|
2024-07-26 02:19:42 -04:00
|
|
|
{
|
2024-08-22 17:04:07 -04:00
|
|
|
$this->dependencyVersionService = $dependencyVersionService;
|
2024-07-26 02:19:42 -04:00
|
|
|
}
|
|
|
|
|
2024-08-22 17:04:07 -04:00
|
|
|
/**
|
|
|
|
* Handle the ModDependency "saved" event.
|
|
|
|
*
|
|
|
|
* @throws CircularDependencyException
|
|
|
|
*/
|
2024-07-26 02:19:42 -04:00
|
|
|
public function saved(ModDependency $modDependency): void
|
2024-08-22 17:04:07 -04:00
|
|
|
{
|
|
|
|
$this->resolveDependencyVersion($modDependency);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve the ModDependency's dependencies.
|
|
|
|
*
|
|
|
|
* @throws CircularDependencyException
|
|
|
|
*/
|
|
|
|
public function resolveDependencyVersion(ModDependency $modDependency): void
|
2024-07-26 02:19:42 -04:00
|
|
|
{
|
|
|
|
$modVersion = ModVersion::find($modDependency->mod_version_id);
|
|
|
|
if ($modVersion) {
|
2024-08-22 17:04:07 -04:00
|
|
|
$this->dependencyVersionService->resolve($modVersion);
|
2024-07-26 02:19:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-22 17:04:07 -04:00
|
|
|
/**
|
|
|
|
* Handle the ModDependency "deleted" event.
|
|
|
|
*
|
|
|
|
* @throws CircularDependencyException
|
|
|
|
*/
|
2024-07-26 02:19:42 -04:00
|
|
|
public function deleted(ModDependency $modDependency): void
|
|
|
|
{
|
2024-08-22 17:04:07 -04:00
|
|
|
$this->resolveDependencyVersion($modDependency);
|
2024-07-26 02:19:42 -04:00
|
|
|
}
|
|
|
|
}
|