fixing multiple references
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\BlockUi;
|
||||
|
||||
use Lucent\Schema\FieldInfo;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\FieldType;
|
||||
use Lucent\Schema\Validator\MinMaxInterface;
|
||||
|
||||
class File implements FieldInterface, MinMaxInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
|
||||
/**
|
||||
* @param string[] $collections
|
||||
*/
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public string $mime = "",
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public array $collections = [],
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("file", "File", FieldType::FILE);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function failMin(mixed $value): bool
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return count($value) < $this->min;
|
||||
}
|
||||
|
||||
public function failMax(mixed $value): bool
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return count($value) < $this->min;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\BlockUi;
|
||||
|
||||
use Lucent\Schema\FieldInfo;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\FieldType;
|
||||
use Lucent\Schema\Nullable;
|
||||
use Lucent\Schema\Validator\RequiredInterface;
|
||||
|
||||
class Heading implements FieldInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public string $default = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("heading", "Heading", FieldType::STRING);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$output[$this->name] = $input[$this->name] ?? "";
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\BlockUi;
|
||||
|
||||
use Lucent\Schema\FieldInfo;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\FieldType;
|
||||
use Lucent\Schema\Nullable;
|
||||
use Lucent\Schema\Validator\RequiredInterface;
|
||||
|
||||
class Markdown implements FieldInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public string $default = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("markdown", "Markdown Editor", FieldType::STRING);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$output[$this->name] = $input[$this->name] ?? "";
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\BlockUi;
|
||||
|
||||
use Lucent\Schema\FieldInfo;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\FieldType;
|
||||
use Lucent\Schema\Validator\MinMaxInterface;
|
||||
|
||||
class Reference implements FieldInterface, MinMaxInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
/**
|
||||
* @param string[] $collections
|
||||
*/
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public array $collections = [],
|
||||
public string $searchField = "",
|
||||
public string $layout = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("reference", "Reference", FieldType::REFERENCE);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function failMin(mixed $value): bool
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return count($value) < $this->min;
|
||||
}
|
||||
|
||||
public function failMax(mixed $value): bool
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return count($value) < $this->min;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\BlockUi;
|
||||
|
||||
use Lucent\Schema\FieldInfo;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\FieldType;
|
||||
use Lucent\Schema\Nullable;
|
||||
use Lucent\Schema\Validator\RequiredInterface;
|
||||
|
||||
class Rich implements FieldInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public string $default = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("rich", "Rich Editor", FieldType::STRING);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$output[$this->name] = $input[$this->name] ?? "";
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\BlockUi;
|
||||
|
||||
use Lucent\Schema\FieldInfo;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\FieldType;
|
||||
use Lucent\Schema\Nullable;
|
||||
use Lucent\Schema\Validator\RequiredInterface;
|
||||
|
||||
class Textarea implements FieldInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public string $default = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("textarea", "Textarea", FieldType::STRING);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$output[$this->name] = $input[$this->name] ?? "";
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Lucent\Schema;
|
||||
|
||||
use Lucent\LucentException;
|
||||
use Lucent\Primitive\Collection;
|
||||
|
||||
class SchemaService
|
||||
@@ -52,16 +53,32 @@ class SchemaService
|
||||
|
||||
public function mapFields(array $field): FieldInterface
|
||||
{
|
||||
$className = "\\Lucent\Schema\Ui\\" . ucfirst($field["ui"]);
|
||||
unset($field["ui"]);
|
||||
|
||||
return new $className(...$field);
|
||||
$schemaFields = [
|
||||
\Lucent\Schema\Ui\Checkbox::class,
|
||||
\Lucent\Schema\Ui\Color::class,
|
||||
\Lucent\Schema\Ui\Date::class,
|
||||
\Lucent\Schema\Ui\Datetime::class,
|
||||
\Lucent\Schema\Ui\File::class,
|
||||
\Lucent\Schema\Ui\Json::class,
|
||||
\Lucent\Schema\Ui\Markdown::class,
|
||||
\Lucent\Schema\Ui\Number::class,
|
||||
\Lucent\Schema\Ui\Reference::class,
|
||||
\Lucent\Schema\Ui\Rich::class,
|
||||
\Lucent\Schema\Ui\Slug::class,
|
||||
\Lucent\Schema\Ui\Text::class,
|
||||
\Lucent\Schema\Ui\Textarea::class,
|
||||
];
|
||||
$ui = collect($schemaFields)->filter(function ($className) use ($field) {
|
||||
return str_ends_with(strtolower($className), "\\" . strtolower($field["ui"]));
|
||||
})->first();
|
||||
|
||||
if (empty($ui)) {
|
||||
throw new LucentException("Field UI " . $field["ui"] . " not found");
|
||||
}
|
||||
|
||||
unset($field["ui"]);
|
||||
return new $ui(...$field);
|
||||
}
|
||||
|
||||
public function mapBlockFields(array $field): FieldInterface
|
||||
{
|
||||
$className = "\\Lucent\Schema\BlockUi\\" . ucfirst($field["ui"]);
|
||||
unset($field["ui"]);
|
||||
return new $className(...$field);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\Ui;
|
||||
|
||||
use Lucent\Schema\FieldInfo;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\FieldType;
|
||||
use Lucent\Schema\Nullable;
|
||||
use Lucent\Schema\Validator\RequiredInterface;
|
||||
|
||||
class Block implements FieldInterface, RequiredInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public bool $nullable = false,
|
||||
public bool $required = false,
|
||||
public string $default = "",
|
||||
public string $help = "",
|
||||
public bool $readonly = false,
|
||||
public string $schema = "",
|
||||
public string $group = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("block", "Block editor", FieldType::JSON);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$value = $input[$this->name] ?? null;
|
||||
|
||||
if (is_string($value)) {
|
||||
$value = json_decode($value, true);
|
||||
}
|
||||
|
||||
$output[$this->name] = (new Nullable($this->nullable, $value, []))->value();
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function failRequired(mixed $value): bool
|
||||
{
|
||||
return empty($value);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class Checkbox implements FieldInterface, RequiredInterface
|
||||
public string $group = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("checkbox", "Block Checkbox", FieldType::BOOLEAN);
|
||||
$this->info = new FieldInfo("checkbox", "Checkbox", FieldType::BOOLEAN);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
|
||||
Reference in New Issue
Block a user