mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-08 01:12:34 +00:00
* wip * wip * cleanup * notification channels * phpstan * services * remove server types * refactoring * refactoring
55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Plugins;
|
|
|
|
use RuntimeException;
|
|
|
|
class RegisterSiteFeature
|
|
{
|
|
public function __construct(
|
|
public string $type,
|
|
public string $name,
|
|
public string $label = '',
|
|
public string $description = ''
|
|
) {}
|
|
|
|
public static function make(string $type, string $name): self
|
|
{
|
|
return new self($type, $name);
|
|
}
|
|
|
|
public function label(string $label): self
|
|
{
|
|
$this->label = $label;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function description(string $description): self
|
|
{
|
|
$this->description = $description;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function register(): void
|
|
{
|
|
if (! config()->has('site.types.'.$this->type)) {
|
|
throw new RuntimeException('Site types not found');
|
|
}
|
|
|
|
$features = config('site.types.'.$this->type.'.features') ?? [];
|
|
|
|
if (isset($features[$this->name])) {
|
|
throw new RuntimeException("Feature '{$this->name}' already exists for type '{$this->type}'");
|
|
}
|
|
|
|
$features[$this->name] = [
|
|
'label' => $this->label,
|
|
'description' => $this->description,
|
|
];
|
|
|
|
config(['site.types.'.$this->type.'.features' => $features]);
|
|
}
|
|
}
|