mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2026-01-13 10:36:52 +00:00
Optimized RequestedEntityFormBuilderService and implemented form classes and logic
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user