From c7c4e1c16ea152367f59593b61f61e6a7f654cef Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 6 Jan 2019 15:15:47 +0100 Subject: [PATCH] Implemented NameSpacePathMap as attribut --- .../EntityMetaInformation.php | 41 ++++--------------- .../EntityMetaInformationInterface.php | 11 ++--- .../FormManagement/FormMetaInformation.php | 2 +- .../TemplatePathInformation.php | 10 +++++ .../TemplatePathInformationInterface.php | 9 ++++ .../FormMetaInformationTest.php | 3 ++ .../SourceMetaInformationTest.php | 2 +- .../TemplatePathInformationTest.php | 4 +- 8 files changed, 37 insertions(+), 45 deletions(-) diff --git a/application/symfony/src/Domain/EntityManagement/EntityMetaInformation.php b/application/symfony/src/Domain/EntityManagement/EntityMetaInformation.php index 0a5b456..23dd42a 100644 --- a/application/symfony/src/Domain/EntityManagement/EntityMetaInformation.php +++ b/application/symfony/src/Domain/EntityManagement/EntityMetaInformation.php @@ -8,6 +8,7 @@ use App\Domain\TemplateManagement\TemplatePathFormAndView; use App\Domain\FormManagement\FormMetaInformationInterface; use App\Domain\FormManagement\FormMetaInformation; use App\Domain\PathManagement\NamespacePathMapInterface; +use App\Domain\PathManagement\NamespacePathMap; /** * @author kevinfrantz @@ -29,11 +30,6 @@ class EntityMetaInformation implements EntityMetaInformationInterface */ private $templatePathFormAndView; - /** - * @var array - */ - private $basicPathArray; - /** * @var string */ @@ -49,11 +45,6 @@ class EntityMetaInformation implements EntityMetaInformationInterface */ private $formMetaInformation; - /** - * @var string - */ - private $basicPathString; - /** * @var NamespacePathMapInterface */ @@ -67,31 +58,23 @@ class EntityMetaInformation implements EntityMetaInformationInterface $this->entity = $entity; $this->entityReflection = new \ReflectionClass($entity); $this->setBasicPathArray(); - $this->setBasicPathString(); $this->setPureName(); $this->setInterfaceReflection(); $this->setTemplatePathFormAndView(); $this->formMetaInformation = new FormMetaInformation($this); } - private function setBasicPathString(): void - { - $this->basicPathString = implode('/', $this->basicPathArray); - } - private function setTemplatePathFormAndView(): void { - $this->templatePathFormAndView = new TemplatePathFormAndView(implode('/', $this->basicPathArray), $this->pureName); + $this->templatePathFormAndView = new TemplatePathFormAndView($this->namespacePathMap->getPath(), $this->pureName); } private function setBasicPathArray(): void { $namespace = $this->entityReflection->getNamespaceName(); $namespaceWithoutRoot = str_replace('App\\Entity\\', '', $namespace); - $this->basicPathArray = []; - foreach (explode('\\', $namespaceWithoutRoot) as $element) { - $this->basicPathArray[] = strtolower($element); - } + $this->namespacePathMap = new NamespacePathMap(); + $this->namespacePathMap->setNamespace($namespaceWithoutRoot); } private function setInterfaceReflection(): void @@ -106,16 +89,6 @@ class EntityMetaInformation implements EntityMetaInformationInterface $this->pureName = strtolower($withoutAbstract); } - /** - * {@inheritdoc} - * - * @see \App\Domain\EntityManagement\EntityMetaInformationInterface::getBasicPathArray() - */ - public function getBasicPathArray(): array - { - return $this->basicPathArray; - } - /** * {@inheritdoc} * @@ -179,10 +152,10 @@ class EntityMetaInformation implements EntityMetaInformationInterface /** * {@inheritdoc} * - * @see \App\Domain\EntityManagement\EntityMetaInformationInterface::getBasicPathString() + * @see \App\Domain\EntityManagement\EntityMetaInformationInterface::getNamespacePathMap() */ - public function getBasicPathString(): string + public function getNamespacePathMap(): NamespacePathMapInterface { - return $this->basicPathString; + return $this->namespacePathMap; } } diff --git a/application/symfony/src/Domain/EntityManagement/EntityMetaInformationInterface.php b/application/symfony/src/Domain/EntityManagement/EntityMetaInformationInterface.php index 7e703f2..5185780 100644 --- a/application/symfony/src/Domain/EntityManagement/EntityMetaInformationInterface.php +++ b/application/symfony/src/Domain/EntityManagement/EntityMetaInformationInterface.php @@ -5,6 +5,8 @@ namespace App\Domain\EntityManagement; use App\Entity\EntityInterface; use App\Domain\TemplateManagement\TemplatePathFormAndViewInterface; use App\Domain\FormManagement\FormMetaInformationInterface; +use App\Domain\PathManagement\NamespacePathMap; +use App\Domain\PathManagement\NamespacePathMapInterface; /** * Offers informations, which the system needs to handle Entities. @@ -28,11 +30,6 @@ interface EntityMetaInformationInterface */ public function getTemplatePathFormAndView(): TemplatePathFormAndViewInterface; - /** - * @return array the namespace elements without the root - */ - public function getBasicPathArray(): array; - /** * @return string Short class name in lower case without "Abstract" */ @@ -49,7 +46,7 @@ interface EntityMetaInformationInterface public function getFormMetaInformation(): FormMetaInformationInterface; /** - * @return string + * @return NamespacePathMap */ - public function getBasicPathString(): string; + public function getNamespacePathMap(): NamespacePathMapInterface; } diff --git a/application/symfony/src/Domain/FormManagement/FormMetaInformation.php b/application/symfony/src/Domain/FormManagement/FormMetaInformation.php index eee5c12..a30340e 100644 --- a/application/symfony/src/Domain/FormManagement/FormMetaInformation.php +++ b/application/symfony/src/Domain/FormManagement/FormMetaInformation.php @@ -40,7 +40,7 @@ final class FormMetaInformation implements FormMetaInformationInterface private function setFormClass(): void { $this->formClass = 'App\\Form'; - foreach ($this->entityMetaInformation->getBasicPathArray() as $element) { + foreach ($this->entityMetaInformation->getNamespacePathMap()->getFolders() as $element) { $this->formClass .= '\\'.ucfirst($element); } $this->formClass .= '\\'.ucfirst($this->entityMetaInformation->getPureName()).'Type'; diff --git a/application/symfony/src/Domain/TemplateManagement/TemplatePathInformation.php b/application/symfony/src/Domain/TemplateManagement/TemplatePathInformation.php index 2d3e407..8b2db16 100644 --- a/application/symfony/src/Domain/TemplateManagement/TemplatePathInformation.php +++ b/application/symfony/src/Domain/TemplateManagement/TemplatePathInformation.php @@ -115,4 +115,14 @@ final class TemplatePathInformation implements TemplatePathInformationInterface $this->type = $type; $this->init(); } + + /** + * {@inheritdoc} + * + * @see \App\Domain\TemplateManagement\TemplatePathInformationInterface::getType() + */ + public function getType(): string + { + return $this->type; + } } diff --git a/application/symfony/src/Domain/TemplateManagement/TemplatePathInformationInterface.php b/application/symfony/src/Domain/TemplateManagement/TemplatePathInformationInterface.php index 4a26e6c..7ea350b 100644 --- a/application/symfony/src/Domain/TemplateManagement/TemplatePathInformationInterface.php +++ b/application/symfony/src/Domain/TemplateManagement/TemplatePathInformationInterface.php @@ -2,6 +2,8 @@ namespace App\Domain\TemplateManagement; +use App\DBAL\Types\RESTResponseType; + /** * Manages all informations which are needed to process templates. * @@ -18,4 +20,11 @@ interface TemplatePathInformationInterface extends ReloadTypeInterface * @return string a template without a frame */ public function getAtomTemplatePath(): string; + + /** + * @see RESTResponseType::$choices + * + * @return string Type of the template + */ + public function getType(): string; } diff --git a/application/symfony/tests/Unit/Domain/FormManagement/FormMetaInformationTest.php b/application/symfony/tests/Unit/Domain/FormManagement/FormMetaInformationTest.php index cf5fa3e..c2cc30a 100644 --- a/application/symfony/tests/Unit/Domain/FormManagement/FormMetaInformationTest.php +++ b/application/symfony/tests/Unit/Domain/FormManagement/FormMetaInformationTest.php @@ -9,6 +9,9 @@ use App\Domain\SourceManagement\SourceMetaInformation; use App\Domain\FormManagement\FormMetaInformation; use App\Domain\TemplateManagement\TemplatePathInformationInterface; +/** + * @author kevinfrantz + */ class FormMetaInformationTest extends TestCase { /** diff --git a/application/symfony/tests/Unit/Domain/SourceManagement/SourceMetaInformationTest.php b/application/symfony/tests/Unit/Domain/SourceManagement/SourceMetaInformationTest.php index 01329aa..97fa270 100644 --- a/application/symfony/tests/Unit/Domain/SourceManagement/SourceMetaInformationTest.php +++ b/application/symfony/tests/Unit/Domain/SourceManagement/SourceMetaInformationTest.php @@ -39,7 +39,7 @@ class SourceMetaInformationTest extends TestCase { $subset = ['source', 'complex']; $amount = count($subset); - $basicPathArray = $this->sourceMetaInformation->getBasicPathArray(); + $basicPathArray = $this->sourceMetaInformation->getNamespacePathMap()->getFolders(); for ($index = 0; $index < $amount; ++$index) { $this->assertEquals($subset[$index], $basicPathArray[$index]); } diff --git a/application/symfony/tests/Unit/Domain/TemplateManagement/TemplatePathInformationTest.php b/application/symfony/tests/Unit/Domain/TemplateManagement/TemplatePathInformationTest.php index 67bccda..b3fa3fb 100644 --- a/application/symfony/tests/Unit/Domain/TemplateManagement/TemplatePathInformationTest.php +++ b/application/symfony/tests/Unit/Domain/TemplateManagement/TemplatePathInformationTest.php @@ -36,7 +36,7 @@ class TemplatePathInformationTest extends TestCase { $this->source = new FirstNameSource(); $sourceMeta = new SourceMetaInformation($this->source); - $folder = implode('/', $sourceMeta->getBasicPathArray()); + $folder = $sourceMeta->getNamespacePathMap()->getPath(); $this->templateMeta = new TemplatePathInformation($sourceMeta->getPureName(), $folder, 'entity'); } @@ -56,7 +56,7 @@ class TemplatePathInformationTest extends TestCase $this->templateMeta->reloadType($type); $this->assertEquals($this->getExpectedPath($type, 'atom'), $this->templateMeta->getAtomTemplatePath()); $this->assertEquals($this->getExpectedPath($type, 'molecule'), $this->templateMeta->getMoleculeTemplatePath()); - $this->assertEquals($type, $this->templateMeta->getTemplateType()); + $this->assertEquals($type, $this->templateMeta->getType()); } } }