mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-08 01:12:34 +00:00
Plugins base (#613)
* wip * wip * cleanup * notification channels * phpstan * services * remove server types * refactoring * refactoring
This commit is contained in:
61
app/Plugins/RegisterNotificationChannel.php
Normal file
61
app/Plugins/RegisterNotificationChannel.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins;
|
||||
|
||||
use App\DTOs\DynamicForm;
|
||||
|
||||
class RegisterNotificationChannel
|
||||
{
|
||||
public function __construct(
|
||||
private string $name,
|
||||
private string $label = '',
|
||||
private string $handler = '',
|
||||
private ?DynamicForm $form = null,
|
||||
) {}
|
||||
|
||||
public static function make(string $name): self
|
||||
{
|
||||
return new self($name);
|
||||
}
|
||||
|
||||
public function name(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function label(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function handler(string $handler): self
|
||||
{
|
||||
$this->handler = $handler;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function form(DynamicForm $form): self
|
||||
{
|
||||
$this->form = $form;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
$providers = config('notification-channel.providers');
|
||||
|
||||
$providers[$this->name] = [
|
||||
'label' => $this->label,
|
||||
'handler' => $this->handler,
|
||||
'form' => $this->form ? $this->form->toArray() : [],
|
||||
];
|
||||
|
||||
config(['notification-channel.providers' => $providers]);
|
||||
}
|
||||
}
|
70
app/Plugins/RegisterServerProvider.php
Normal file
70
app/Plugins/RegisterServerProvider.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins;
|
||||
|
||||
use App\DTOs\DynamicForm;
|
||||
|
||||
class RegisterServerProvider
|
||||
{
|
||||
public function __construct(
|
||||
private string $name,
|
||||
private string $label = '',
|
||||
private string $handler = '',
|
||||
private ?DynamicForm $form = null,
|
||||
private string $defaultUser = '',
|
||||
) {}
|
||||
|
||||
public static function make(string $name): self
|
||||
{
|
||||
return new self($name);
|
||||
}
|
||||
|
||||
public function name(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function label(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function handler(string $handler): self
|
||||
{
|
||||
$this->handler = $handler;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function form(DynamicForm $form): self
|
||||
{
|
||||
$this->form = $form;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function defaultUser(string $defaultUser): self
|
||||
{
|
||||
$this->defaultUser = $defaultUser;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
$providers = config('server-provider.providers');
|
||||
|
||||
$providers[$this->name] = [
|
||||
'label' => $this->label,
|
||||
'handler' => $this->handler,
|
||||
'form' => $this->form ? $this->form->toArray() : [],
|
||||
'default_user' => $this->defaultUser,
|
||||
];
|
||||
|
||||
config(['server-provider.providers' => $providers]);
|
||||
}
|
||||
}
|
112
app/Plugins/RegisterServiceType.php
Normal file
112
app/Plugins/RegisterServiceType.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins;
|
||||
|
||||
use App\DTOs\DynamicForm;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class RegisterServiceType
|
||||
{
|
||||
/**
|
||||
* @param array<string> $versions
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function __construct(
|
||||
private string $name,
|
||||
private string $type = '',
|
||||
private string $unit = '',
|
||||
private string $label = '',
|
||||
private string $handler = '',
|
||||
private ?DynamicForm $form = null,
|
||||
private array $versions = ['latest'],
|
||||
private array $data = []
|
||||
) {}
|
||||
|
||||
public static function make(string $name): self
|
||||
{
|
||||
return new self($name);
|
||||
}
|
||||
|
||||
public function name(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function type(string $type): self
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function unit(string $unit): self
|
||||
{
|
||||
$this->unit = $unit;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function label(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function handler(string $handler): self
|
||||
{
|
||||
$this->handler = $handler;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function form(DynamicForm $form): self
|
||||
{
|
||||
$this->form = $form;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $versions
|
||||
*/
|
||||
public function versions(array $versions): self
|
||||
{
|
||||
$this->versions = $versions;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function data(array $data): self
|
||||
{
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
$types = config('service.services');
|
||||
|
||||
if (! $this->type) {
|
||||
throw new InvalidArgumentException('Service type must be specified.');
|
||||
}
|
||||
|
||||
$types[$this->name] = [
|
||||
'type' => $this->type,
|
||||
'unit' => $this->unit,
|
||||
'label' => $this->label,
|
||||
'handler' => $this->handler,
|
||||
'form' => $this->form ? $this->form->toArray() : [],
|
||||
'versions' => $this->versions,
|
||||
'data' => $this->data,
|
||||
];
|
||||
|
||||
config(['service.services' => $types]);
|
||||
}
|
||||
}
|
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]);
|
||||
}
|
||||
}
|
70
app/Plugins/RegisterSiteFeatureAction.php
Normal file
70
app/Plugins/RegisterSiteFeatureAction.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins;
|
||||
|
||||
use App\DTOs\DynamicForm;
|
||||
use RuntimeException;
|
||||
|
||||
class RegisterSiteFeatureAction
|
||||
{
|
||||
public function __construct(
|
||||
public string $type,
|
||||
public string $feature,
|
||||
public string $name,
|
||||
public string $label = '',
|
||||
public string $handler = '',
|
||||
public ?DynamicForm $form = null,
|
||||
) {}
|
||||
|
||||
public static function make(string $type, string $feature, string $name): self
|
||||
{
|
||||
return new self($type, $feature, $name);
|
||||
}
|
||||
|
||||
public function label(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function handler(string $handler): self
|
||||
{
|
||||
$this->handler = $handler;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function form(DynamicForm $form): self
|
||||
{
|
||||
$this->form = $form;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
if (! config()->has('site.types.'.$this->type)) {
|
||||
throw new RuntimeException('Site types not found');
|
||||
}
|
||||
|
||||
$feature = config('site.types.'.$this->type.'.features.'.$this->feature);
|
||||
|
||||
if (! $feature) {
|
||||
throw new RuntimeException("Feature '{$this->feature}' not found for type '{$this->type}'");
|
||||
}
|
||||
|
||||
$actions = $feature['actions'] ?? [];
|
||||
if (isset($actions[$this->name])) {
|
||||
throw new RuntimeException("Action '{$this->name}' already exists for feature '{$this->feature}' in type '{$this->type}'");
|
||||
}
|
||||
|
||||
$actions[$this->name] = [
|
||||
'label' => $this->label,
|
||||
'handler' => $this->handler,
|
||||
'form' => $this->form ? $this->form->toArray() : [],
|
||||
];
|
||||
|
||||
config(['site.types.'.$this->type.'.features.'.$this->feature.'.actions' => $actions]);
|
||||
}
|
||||
}
|
54
app/Plugins/RegisterSiteType.php
Normal file
54
app/Plugins/RegisterSiteType.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins;
|
||||
|
||||
use App\DTOs\DynamicForm;
|
||||
|
||||
class RegisterSiteType
|
||||
{
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label = '',
|
||||
public string $handler = '',
|
||||
public ?DynamicForm $form = null,
|
||||
) {}
|
||||
|
||||
public static function make(string $name): self
|
||||
{
|
||||
return new self($name);
|
||||
}
|
||||
|
||||
public function label(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function handler(string $handler): self
|
||||
{
|
||||
$this->handler = $handler;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function form(DynamicForm $form): self
|
||||
{
|
||||
$this->form = $form;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
$types = config('site.types');
|
||||
|
||||
$types[$this->name] = [
|
||||
'label' => $this->label,
|
||||
'handler' => $this->handler,
|
||||
'form' => $this->form ? $this->form->toArray() : [],
|
||||
];
|
||||
|
||||
config(['site.types' => $types]);
|
||||
}
|
||||
}
|
61
app/Plugins/RegisterSourceControl.php
Normal file
61
app/Plugins/RegisterSourceControl.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins;
|
||||
|
||||
use App\DTOs\DynamicForm;
|
||||
|
||||
class RegisterSourceControl
|
||||
{
|
||||
public function __construct(
|
||||
private string $name,
|
||||
private string $label = '',
|
||||
private string $handler = '',
|
||||
private ?DynamicForm $form = null,
|
||||
) {}
|
||||
|
||||
public static function make(string $name): self
|
||||
{
|
||||
return new self($name);
|
||||
}
|
||||
|
||||
public function name(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function label(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function handler(string $handler): self
|
||||
{
|
||||
$this->handler = $handler;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function form(DynamicForm $form): self
|
||||
{
|
||||
$this->form = $form;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
$providers = config('source-control.providers');
|
||||
|
||||
$providers[$this->name] = [
|
||||
'label' => $this->label,
|
||||
'handler' => $this->handler,
|
||||
'form' => $this->form ? $this->form->toArray() : [],
|
||||
];
|
||||
|
||||
config(['source-control.providers' => $providers]);
|
||||
}
|
||||
}
|
61
app/Plugins/RegisterStorageProvider.php
Normal file
61
app/Plugins/RegisterStorageProvider.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins;
|
||||
|
||||
use App\DTOs\DynamicForm;
|
||||
|
||||
class RegisterStorageProvider
|
||||
{
|
||||
public function __construct(
|
||||
private string $name,
|
||||
private string $label = '',
|
||||
private string $handler = '',
|
||||
private ?DynamicForm $form = null,
|
||||
) {}
|
||||
|
||||
public static function make(string $name): self
|
||||
{
|
||||
return new self($name);
|
||||
}
|
||||
|
||||
public function name(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function label(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function handler(string $handler): self
|
||||
{
|
||||
$this->handler = $handler;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function form(DynamicForm $form): self
|
||||
{
|
||||
$this->form = $form;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
$providers = config('storage-provider.providers');
|
||||
|
||||
$providers[$this->name] = [
|
||||
'label' => $this->label,
|
||||
'handler' => $this->handler,
|
||||
'form' => $this->form ? $this->form->toArray() : [],
|
||||
];
|
||||
|
||||
config(['storage-provider.providers' => $providers]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user