refactor fields

This commit is contained in:
2024-03-21 22:33:41 +02:00
parent bb77a37ff7
commit 8526fd471f
68 changed files with 635 additions and 297 deletions
+9 -10
View File
@@ -5,15 +5,16 @@ namespace Lucent\Schema\Ui;
use Lucent\JsonSchema\Property\Property;
use Lucent\JsonSchema\Property\PropertyType;
use Lucent\JsonSchema\Property\TypeProperty;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Record\RecordData;
use Lucent\Schema\Field\FieldDataInterface;
use Lucent\Schema\Field\FieldInfo;
use Lucent\Schema\Field\FieldInterface;
use Lucent\Schema\Field\FieldType;
use Lucent\Schema\Validator\MinMaxInterface;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
class Number implements FieldInterface, RequiredInterface, MinMaxInterface
class Number implements FieldInterface, RequiredInterface,FieldDataInterface, MinMaxInterface
{
public FieldInfo $info;
@@ -21,7 +22,6 @@ class Number implements FieldInterface, RequiredInterface, MinMaxInterface
public string $name,
public string $label,
public bool $required = false,
public bool $nullable = false,
public int $decimals = 0,
public ?int $min = null,
public ?int $max = null,
@@ -37,9 +37,9 @@ class Number implements FieldInterface, RequiredInterface, MinMaxInterface
$this->info = new FieldInfo("number", "Number", FieldType::NUMBER);
}
public function format(array $input, array $output): array
public function format(RecordData $input, RecordData $output): RecordData
{
$value = $input[$this->name] ?? null;
$value = $input->get($this->name);
if (!is_numeric($value)) {
$newValue = null;
} else {
@@ -51,8 +51,7 @@ class Number implements FieldInterface, RequiredInterface, MinMaxInterface
);
$newValue = $this->decimals === 0 ? (int)$newValue : floatval($newValue);
}
$output[$this->name] = (new Nullable($this->nullable, $newValue, 0))->value();
$output->set($this->name,$newValue);
return $output;
}