<?phpclassFooEntityFactoryextendsAbstractFactory
{
// ...// override this methodprotectedfunctionpersistEntity($entity): void
{
/** @var FooEntity $entity */$pdo = new \PDO('mysql:host=localhost;dbname=foo_db', 'user', 'password');
$stmt = $pdo->prepare('INSERT INTO foo (name) VALUES (:name)');
$stmt->bindValue(':name', $entity->getName());
$stmt->execute();
}
}
// call store method when you want to store an entity in database$foo = FooEntityFactory::start()->store();
Check attribute keys
<?phpclassFooEntityFactoryextendsAbstractFactory
{
// ...// override this methodprotectedfunctionfillable(): array
{
return ['name', 'email'];
}
}
try {
FooEntityFactory::start()->make(['foo' => 'bar']);
} catch (EntityFactoryExceptionInterface$e) {
echo$e->getMessage(); // "foo is not fillable."
}