Implemented Source Namespace factory

This commit is contained in:
Kevin Frantz 2018-09-17 13:38:38 +02:00
parent a8781de51a
commit c15caf03a1
2 changed files with 36 additions and 1 deletions

View File

@ -10,6 +10,7 @@ use FOS\RestBundle\Controller\FOSRestController;
use App\Form\NameSourceType;
use App\Entity\SourceInterface;
use App\Creator\Factory\Template\Source\SourceTemplateFormFactory;
use App\Creator\Factory\Form\Source\SourceFormFactory;
/**
* @todo IMPLEMENT SECURITY!
@ -41,7 +42,7 @@ class SourceController extends FOSRestController
public function edit(Request $request, int $id): Response
{
$source = $this->loadSource($request, $id);
$form = $this->createForm(NameSourceType::class, $source);
$form = $this->createForm((new SourceFormFactory($source))->getNamespace(), $source);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$source = $form->getData();

View File

@ -0,0 +1,34 @@
<?php
namespace App\Creator\Factory\Form\Source;
use App\Entity\SourceInterface;
/**
*
* @author kevinfrantz
*
*/
class SourceFormFactory
{
const FORM_NAMESPACE = 'App\Form\\';
/**
* @var SourceInterface
*/
private $source;
public function __construct(SourceInterface $source){
$this->source = $source;
}
public function getNamespace():string{
return self::FORM_NAMESPACE.$this->getName();
}
protected function getName(): string
{
$reflectionClass = new \ReflectionClass($this->source);
return $reflectionClass->getShortName().'Type';
}
}