Optimized RequestedEntityFormBuilderService and implemented form classes and logic

This commit is contained in:
Kevin Frantz
2019-02-03 15:21:45 +01:00
parent c3b8e1a92d
commit ed3062a203
18 changed files with 247 additions and 79 deletions

View File

@@ -1,21 +0,0 @@
<?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;
}

View File

@@ -2,8 +2,6 @@
namespace App\Domain\FormManagement;
use App\Entity\EntityInterface;
/**
* @author kevinfrantz
*/
@@ -16,14 +14,13 @@ final class FormClassNameService implements FormClassNameServiceInterface
const SUFFIX = 'Type';
/**
* @param EntityInterface $entity
* {@inheritdoc}
*
* @return string
* @see \App\Domain\FormManagement\FormClassNameServiceInterface::getClass()
*/
public function getName(EntityInterface $entity): string
public function getClass(string $origineClass): string
{
$class = get_class($entity);
$replaced = str_replace(self::ENTITY_BASE_PATH, self::FORM_BASE_PATH, $class);
$replaced = str_replace(self::ENTITY_BASE_PATH, self::FORM_BASE_PATH, $origineClass);
$withSuffix = $replaced.self::SUFFIX;
return $withSuffix;

View File

@@ -14,5 +14,5 @@ interface FormClassNameServiceInterface
*
* @return string The name of the form of the entity
*/
public function getName(EntityInterface $entity): string;
public function getClass(string $origineClass): string;
}

View File

@@ -2,13 +2,13 @@
namespace App\Domain\FormManagement;
use App\Entity\EntityInterface;
use Symfony\Component\Form\FormBuilderInterface;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
/**
* @author kevinfrantz
*/
final class EntityFormBuilderService implements EntityFormBuilderServiceInterface
final class RequestedEntityFormBuilderService implements EntityFormBuilderServiceInterface
{
/**
* @var FormBuilderInterface
@@ -34,9 +34,13 @@ final class EntityFormBuilderService implements EntityFormBuilderServiceInterfac
*
* @see \App\Domain\FormManagement\EntityFormBuilderServiceInterface::create()
*/
public function create(EntityInterface $entity): FormBuilderInterface
public function create(RequestedEntityInterface $requestedEntity): FormBuilderInterface
{
$class = $this->formClassNameService->getName($entity);
$origineClass = $requestedEntity->getClass();
$class = $this->formClassNameService->getClass($origineClass);
if ($requestedEntity->hasIdentity()) {
$entity = $requestedEntity->getEntity();
}
$form = $this->formBuilder->create($class, $entity);
return $form;

View File

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