Added EntityFormBuilderService

This commit is contained in:
Kevin Frantz
2019-01-25 22:39:23 +01:00
parent 806c6408e8
commit 36198e8196
3 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Domain\FormManagement;
use App\Entity\EntityInterface;
use Symfony\Component\Form\FormBuilderInterface;
/**
* @author kevinfrantz
*/
final class EntityFormBuilderService implements EntityFormBuilderServiceInterface
{
/**
* @var FormBuilderInterface
*/
private $formBuilder;
/**
* @var FormClassNameServiceInterface
*/
private $formClassNameService;
/**
* @param FormBuilderInterface $formBuilder
*/
public function __construct(FormBuilderInterface $formBuilder, FormClassNameServiceInterface $formClassNameService)
{
$this->formBuilder = $formBuilder;
$this->formClassNameService = $formClassNameService;
}
/**
* {@inheritdoc}
*
* @see \App\Domain\FormManagement\EntityFormBuilderServiceInterface::create()
*/
public function create(EntityInterface $entity): FormBuilderInterface
{
$class = $this->formClassNameService->getName($entity);
$form = $this->formBuilder->create($class, $entity);
return $form;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Domain\FormManagement;
use App\Entity\EntityInterface;
use Symfony\Component\Form\FormBuilderInterface;
/**
* Allowes to create an form which fits to an entity.
*
* @author kevinfrantz
*/
interface EntityFormBuilderServiceInterface
{
/**
* @param EntityInterface $entity
*
* @return FormBuilderInterface
*/
public function create(EntityInterface $entity): FormBuilderInterface;
}