mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-08 17:32:35 +00:00
Plugins base (#613)
* wip * wip * cleanup * notification channels * phpstan * services * remove server types * refactoring * refactoring
This commit is contained in:
54
app/Plugins/RegisterSiteFeature.php
Normal file
54
app/Plugins/RegisterSiteFeature.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user