Importer
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command\Pf2eSchemaGenerator;
|
||||
|
||||
class SchemaItem
|
||||
{
|
||||
public string $name;
|
||||
|
||||
public string $type = "";
|
||||
|
||||
public bool $required = true;
|
||||
|
||||
public ?array $elements = [];
|
||||
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function disableRequired(): void
|
||||
{
|
||||
$this->required = false;
|
||||
}
|
||||
|
||||
public function adapt(mixed $value): void
|
||||
{
|
||||
$type = Schema::resolveType($value);
|
||||
|
||||
$this->type = Schema::mergeTypes($this->type, $type);
|
||||
|
||||
if (str_contains($this->type, "[]") && !is_null($this->elements)) {
|
||||
foreach ($value as $element) {
|
||||
if (!in_array($element, $this->elements)) {
|
||||
$this->elements[] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->elements) > 20) {
|
||||
$this->elements = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function strings(): array {
|
||||
$name = $this->name;
|
||||
|
||||
if (!$this->required) {
|
||||
$name = "[{$name}]";
|
||||
}
|
||||
|
||||
$rows = [
|
||||
sprintf("%s: %s", $name, $this->type),
|
||||
];
|
||||
|
||||
if (!empty($this->elements)) {
|
||||
sort($this->elements);
|
||||
$elements = [];
|
||||
foreach ($this->elements as $element) {
|
||||
$elements[] = is_string($element) ? "\"{$element}\"" : strval($element);
|
||||
}
|
||||
$rows[] = " Elements: [ " . implode(", ", $elements) . " ]";
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user