- WIP on database storage filling

This commit is contained in:
Dave Mc Nicoll committed 2026-05-21 15:21:45 +00:00
1 parent 2fd9331c15
commit 7117021750
6 files changed
+208 -8

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
<?php
namespace Lean\Console\Form\Storage\Database;
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
use \Lean\Console\{ Lib, Entity };
use Picea\Compiler\Context;
use Psr\Http\Message\ServerRequestInterface;
use Ulmus\{Attribute\Property\Field, Entity\EntityInterface, Entity\Field\Datetime, EntityCollection};
class Insert implements FormInterface
{
public function __construct(
protected EntityInterface $entity
) { }
public function initialize(FormContextInterface $context) : void
{
}
public function validate(FormContextInterface $context) : bool
{
return $context->valid();
}
public function execute(FormContextInterface $context) : void
{
foreach ($this->entity::resolveEntity()->fieldList() as $field) {
$type = $field->getTypes()[0];
$value = $context->{$field->name};
if (! $field->getAttribute(Field::class)->object->readonly) {
if ($type->isEnum() && $value) {
$this->entity->{$field->name} = $type->type::from($value);
}
else {
$this->entity->{$field->name} = $value;
}
}
}
# Temp patch while fixing default value in sqlite
if (property_exists($this->entity, 'createdAt')) {
$this->entity->createdAt = new Datetime();
}
$this->entity::repository()->save($this->entity);
}
}