Plugins base (#613)

* wip

* wip

* cleanup

* notification channels

* phpstan

* services

* remove server types

* refactoring

* refactoring
This commit is contained in:
Saeed Vaziry
2025-06-14 14:35:18 +02:00
committed by GitHub
parent adc0653d15
commit 131b828807
311 changed files with 3976 additions and 2660 deletions

View File

@ -8,9 +8,10 @@
use App\Exceptions\FailedToDestroyGitHook;
use App\Exceptions\SourceControlIsNotConnected;
use App\Exceptions\SSHError;
use App\Services\PHP\PHP;
use App\Services\Webserver\Webserver;
use App\SiteFeatures\ActionInterface;
use App\SiteTypes\SiteType;
use App\SSH\Services\PHP\PHP;
use App\SSH\Services\Webserver\Webserver;
use App\Traits\HasProjectThroughServer;
use Database\Factories\SiteFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@ -20,6 +21,7 @@
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use RuntimeException;
/**
* @property int $server_id
@ -237,12 +239,15 @@ public function getAliasesString(): string
public function type(): SiteType
{
$typeClass = config('core.site_types_class.'.$this->type);
$handlerClass = config('site.types.'.$this->type.'.handler');
if (! class_exists($handlerClass)) {
throw new RuntimeException("Site type handler class {$handlerClass} does not exist.");
}
/** @var SiteType $type */
$type = new $typeClass($this);
/** @var SiteType $handler */
$handler = new $handlerClass($this);
return $type;
return $handler;
}
public function php(): ?Service
@ -352,11 +357,6 @@ public function getSshKeyName(): string
return str('site_'.$this->id)->toString();
}
public function hasFeature(string $feature): bool
{
return in_array($feature, $this->type()->supportedFeatures());
}
public function getEnv(): string
{
try {
@ -438,4 +438,25 @@ public function activeRedirects(): HasMany
{
return $this->redirects()->whereIn('status', [RedirectStatus::CREATING, RedirectStatus::READY]);
}
/**
* @return array<string, mixed>
*/
public function features(): array
{
$features = config('site.types.'.$this->type.'.features', []);
foreach ($features as $featureKey => $feature) {
foreach ($feature['actions'] ?? [] as $actionKey => $action) {
$handlerClass = $action['handler'] ?? null;
if ($handlerClass && class_exists($handlerClass)) {
/** @var ActionInterface $handler */
$handler = new $handlerClass($this);
$action['active'] = $handler->active();
}
$features[$featureKey]['actions'][$actionKey] = $action;
}
}
return $features;
}
}