mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 21:57:16 +02:00
Added EntityFormBuilderService
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
Reference in New Issue
Block a user