From c15caf03a19f65014551f6ce8f4efef53b93c22a Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Mon, 17 Sep 2018 13:38:38 +0200 Subject: [PATCH] Implemented Source Namespace factory --- .../src/Controller/SourceController.php | 3 +- .../Factory/Form/Source/SourceFormFactory.php | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 application/src/Creator/Factory/Form/Source/SourceFormFactory.php diff --git a/application/src/Controller/SourceController.php b/application/src/Controller/SourceController.php index 04a2614..488a222 100644 --- a/application/src/Controller/SourceController.php +++ b/application/src/Controller/SourceController.php @@ -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(); diff --git a/application/src/Creator/Factory/Form/Source/SourceFormFactory.php b/application/src/Creator/Factory/Form/Source/SourceFormFactory.php new file mode 100644 index 0000000..b9c88ce --- /dev/null +++ b/application/src/Creator/Factory/Form/Source/SourceFormFactory.php @@ -0,0 +1,34 @@ +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'; + } +} +