mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +01:00
Implemented Source Namespace factory
This commit is contained in:
parent
a8781de51a
commit
c15caf03a1
@ -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();
|
||||
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user