mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 21:57:16 +02:00
Optimized RequestedEntityFormBuilderService and implemented form classes and logic
This commit is contained in:
@@ -30,11 +30,12 @@ abstract class AbstractAction extends AbstractActionConstructor implements Actio
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\ActionInterface::execute()
|
||||
*/
|
||||
public function execute()
|
||||
final public function execute()
|
||||
{
|
||||
if ($this->isSecure()) {
|
||||
if ($this->isValidByForm()) {
|
||||
|
@@ -6,7 +6,7 @@ use App\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||
use App\Domain\SecureManagement\SecureRequestedRightCheckerInterface;
|
||||
use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use App\Domain\FormManagement\EntityFormBuilderServiceInterface;
|
||||
use App\Domain\FormManagement\RequestedEntityFormBuilderServiceInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use App\Repository\RepositoryInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -38,7 +38,7 @@ final class ActionService implements ActionServiceInterface
|
||||
private $layerRepositoryFactoryService;
|
||||
|
||||
/**
|
||||
* @var
|
||||
* @var RequestedEntityFormBuilderServiceInterface
|
||||
*/
|
||||
private $entityFormBuilderService;
|
||||
|
||||
@@ -50,13 +50,13 @@ final class ActionService implements ActionServiceInterface
|
||||
/**
|
||||
* @param RequestedActionInterface $requestedAction
|
||||
*/
|
||||
public function __construct(RequestedActionInterface $requestedAction, SecureRequestedRightCheckerInterface $secureRequestedRightChecker, RequestStack $requestStack, LayerRepositoryFactoryServiceInterface $layerRepositoryFactoryService, EntityFormBuilderServiceInterface $entityFormBuilderService, EntityManagerInterface $entityManager)
|
||||
public function __construct(RequestedActionInterface $requestedAction, SecureRequestedRightCheckerInterface $secureRequestedRightChecker, RequestStack $requestStack, LayerRepositoryFactoryServiceInterface $layerRepositoryFactoryService, RequestedEntityFormBuilderServiceInterface $requestedEntityFormBuilderService, EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->requestedAction = $requestedAction;
|
||||
$this->secureRequestedRightChecker = $secureRequestedRightChecker;
|
||||
$this->requestStack = $requestStack;
|
||||
$this->layerRepositoryFactoryService = $layerRepositoryFactoryService;
|
||||
$this->entityFormBuilderService = $entityFormBuilderService;
|
||||
$this->entityFormBuilderService = $requestedEntityFormBuilderService;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
@@ -85,9 +85,9 @@ final class ActionService implements ActionServiceInterface
|
||||
*/
|
||||
public function getForm(): FormBuilderInterface
|
||||
{
|
||||
$entity = $this->requestedAction->getRequestedEntity()->getEntity();
|
||||
$requestedEntity = $this->requestedAction->getRequestedEntity();
|
||||
|
||||
return $this->entityFormBuilderService->create($entity);
|
||||
return $this->entityFormBuilderService->create($requestedEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -2,16 +2,55 @@
|
||||
|
||||
namespace App\Domain\ActionManagement\Create;
|
||||
|
||||
use App\Domain\SourceManagement\SourceClassInformationService;
|
||||
use App\Form\Source\SourceType;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class CreateSourceAction extends AbstractCreateAction
|
||||
{
|
||||
protected function isValidByForm(): bool
|
||||
/**
|
||||
* @var string default class name, when no parameter is defined
|
||||
*/
|
||||
const DEFAULT_CLASS = AbstractSource::class;
|
||||
|
||||
/**
|
||||
* @see SourceClassInformationService
|
||||
*
|
||||
* @var string The source class which should be used
|
||||
*/
|
||||
private $sourceClass;
|
||||
|
||||
private function setSourceClass(): void
|
||||
{
|
||||
$request = $this->actionService->getRequest();
|
||||
$this->sourceClass = $request->get(SourceType::CLASS_PARAMETER_NAME, self::DEFAULT_CLASS);
|
||||
}
|
||||
|
||||
private function prepare(): void
|
||||
{
|
||||
$this->setSourceClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\AbstractAction::isValidByForm()
|
||||
*/
|
||||
protected function isValidByForm(): bool
|
||||
{
|
||||
$this->actionService->getForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\ActionManagement\AbstractAction::proccess()
|
||||
*/
|
||||
protected function proccess()
|
||||
{
|
||||
$this->prepare();
|
||||
}
|
||||
}
|
||||
|
@@ -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