175 lines
3.9 KiB
PHP
175 lines
3.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Repository\PluginRepository;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
#[ORM\Entity(repositoryClass: PluginRepository::class)]
|
|
#[ORM\Table(name: 'og_plugins')]
|
|
class Plugin extends AbstractEntity
|
|
{
|
|
use NameableTrait;
|
|
use ToggleableTrait;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private string $title = '';
|
|
|
|
#[ORM\Column(length: 50)]
|
|
private string $version = '1.0.0';
|
|
|
|
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
|
private ?string $description = null;
|
|
|
|
#[ORM\Column(length: 255, nullable: true)]
|
|
private ?string $author = null;
|
|
|
|
#[ORM\Column(length: 100, nullable: true)]
|
|
private ?string $icon = null;
|
|
|
|
#[ORM\Column(type: Types::JSON, nullable: true)]
|
|
private ?array $commands = null;
|
|
|
|
#[ORM\Column(name: 'schema_definition', type: Types::JSON, nullable: true)]
|
|
private ?array $schemaDefinition = null;
|
|
|
|
#[ORM\Column(name: 'config_data', type: Types::JSON, nullable: true)]
|
|
private ?array $configData = null;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function getTitle(): string
|
|
{
|
|
return $this->title;
|
|
}
|
|
|
|
public function setTitle(string $title): static
|
|
{
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getVersion(): string
|
|
{
|
|
return $this->version;
|
|
}
|
|
|
|
public function setVersion(string $version): static
|
|
{
|
|
$this->version = $version;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDescription(): ?string
|
|
{
|
|
return $this->description;
|
|
}
|
|
|
|
public function setDescription(?string $description): static
|
|
{
|
|
$this->description = $description;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getAuthor(): ?string
|
|
{
|
|
return $this->author;
|
|
}
|
|
|
|
public function setAuthor(?string $author): static
|
|
{
|
|
$this->author = $author;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getIcon(): ?string
|
|
{
|
|
return $this->icon;
|
|
}
|
|
|
|
public function setIcon(?string $icon): static
|
|
{
|
|
$this->icon = $icon;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCommands(): ?array
|
|
{
|
|
return $this->commands;
|
|
}
|
|
|
|
public function setCommands(?array $commands): static
|
|
{
|
|
$this->commands = $commands;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSchemaDefinition(): ?array
|
|
{
|
|
return $this->schemaDefinition;
|
|
}
|
|
|
|
public function setSchemaDefinition(?array $schemaDefinition): static
|
|
{
|
|
$this->schemaDefinition = $schemaDefinition;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getConfigData(): ?array
|
|
{
|
|
return $this->configData;
|
|
}
|
|
|
|
public function setConfigData(?array $configData): static
|
|
{
|
|
$this->configData = $configData;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'uuid' => (string) $this->uuid,
|
|
'name' => $this->name,
|
|
'title' => $this->title,
|
|
'version' => $this->version,
|
|
'description' => $this->description,
|
|
'author' => $this->author,
|
|
'icon' => $this->icon,
|
|
'enabled' => $this->enabled,
|
|
'commands' => $this->commands ?? [],
|
|
'schema' => $this->schemaDefinition ?? [],
|
|
'config' => $this->configData ?? [],
|
|
'defaultConfig' => $this->extractDefaultConfig(),
|
|
];
|
|
}
|
|
|
|
private function extractDefaultConfig(): array
|
|
{
|
|
$defaults = [];
|
|
if (is_array($this->schemaDefinition)) {
|
|
foreach ($this->schemaDefinition as $field) {
|
|
if (isset($field['key']) && array_key_exists('default', $field)) {
|
|
$defaults[$field['key']] = $field['default'];
|
|
}
|
|
}
|
|
}
|
|
return $defaults;
|
|
}
|
|
}
|