mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 07:22:34 +00:00
#591 - sites [wip]
This commit is contained in:
113
app/DTOs/DynamicFieldDTO.php
Normal file
113
app/DTOs/DynamicFieldDTO.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\DTOs;
|
||||
|
||||
class DynamicFieldDTO
|
||||
{
|
||||
/**
|
||||
* @param array<int, mixed>|null $options
|
||||
*/
|
||||
public function __construct(
|
||||
private string $name,
|
||||
private string $type = 'text',
|
||||
private string $label = '',
|
||||
private mixed $default = null,
|
||||
private ?string $placeholder = null,
|
||||
private ?string $description = null,
|
||||
private ?array $options = null
|
||||
) {}
|
||||
|
||||
public static function make(string $name): self
|
||||
{
|
||||
return new self($name);
|
||||
}
|
||||
|
||||
public function component(): self
|
||||
{
|
||||
$this->type = 'component';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function text(): self
|
||||
{
|
||||
$this->type = 'text';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function select(): self
|
||||
{
|
||||
$this->type = 'select';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function checkbox(): self
|
||||
{
|
||||
$this->type = 'checkbox';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function name(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function label(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function default(mixed $default): self
|
||||
{
|
||||
$this->default = $default;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function placeholder(?string $placeholder): self
|
||||
{
|
||||
$this->placeholder = $placeholder;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function description(?string $description): self
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, mixed>|null $options
|
||||
*/
|
||||
public function options(?array $options): self
|
||||
{
|
||||
$this->options = $options;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'type' => $this->type,
|
||||
'name' => $this->name,
|
||||
'label' => $this->label,
|
||||
'default' => $this->default,
|
||||
'placeholder' => $this->placeholder,
|
||||
'description' => $this->description,
|
||||
'options' => $this->options,
|
||||
];
|
||||
}
|
||||
}
|
26
app/DTOs/DynamicFieldsCollectionDTO.php
Normal file
26
app/DTOs/DynamicFieldsCollectionDTO.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\DTOs;
|
||||
|
||||
readonly class DynamicFieldsCollectionDTO
|
||||
{
|
||||
/**
|
||||
* @param array<int, DynamicFieldDTO> $fields
|
||||
*/
|
||||
public function __construct(
|
||||
private array $fields = [],
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$fields = [];
|
||||
foreach ($this->fields as $field) {
|
||||
$fields[] = $field->toArray();
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user