entity factory create with additional attributes

This commit is contained in:
Yuri Kuznetsov
2025-06-23 18:13:59 +03:00
parent 4a38109d10
commit c2f4afd520

View File

@@ -77,6 +77,14 @@ class EntityFactory implements EntityFactoryInterface
}
public function create(string $entityType): Entity
{
return $this->createInternal($entityType);
}
/**
* @param ?array<string, mixed> $attributeDefs
*/
private function createInternal(string $entityType, ?array $attributeDefs = null): Entity
{
$className = $this->getClassName($entityType);
@@ -90,6 +98,10 @@ class EntityFactory implements EntityFactoryInterface
throw new RuntimeException("Entity '$entityType' is not defined in metadata.");
}
if ($attributeDefs) {
$defs['attributes'] = array_merge($defs['attributes'] ?? [], $attributeDefs);
}
$relations = $this->injectableFactory->createWithBinding(
RDBRelations::class,
BindingContainerBuilder::create()
@@ -123,6 +135,16 @@ class EntityFactory implements EntityFactoryInterface
return $entity;
}
/**
* @param array<string, mixed> $attributeDefs
* @internal
* @noinspection PhpUnused
*/
public function createWithAdditionalAttributes(string $entityType, array $attributeDefs): Entity
{
return $this->createInternal($entityType, $attributeDefs);
}
/**
* @return class-string<Entity>
*/