Implemented formMeta

This commit is contained in:
Kevin Frantz 2018-11-23 16:21:26 +01:00
parent b9a312cfd9
commit 2009f1b691
6 changed files with 88 additions and 12 deletions

View File

@ -3,14 +3,55 @@
namespace App\Domain\FormManagement;
use App\Domain\SourceManagement\SourceMetaInterface;
use App\Domain\TemplateManagement\TemplateMetaInterface;
use App\Domain\TemplateManagement\TemplateMeta;
/**
* @author kevinfrantz
*/
class FormMeta implements FormMetaInterface
{
public function __construct(SourceMetaInterface $source)
const FOLDER = 'form';
/**
* @var SourceMetaInterface
*/
private $sourceMeta;
/**
* @var TemplateMetaInterface
*/
private $templateMeta;
/**
* @var string
*/
private $formClass;
public function __construct(SourceMetaInterface $sourceMeta)
{
$this->sourceMeta = $sourceMeta;
$this->setMeta();
$this->setFormClass();
}
public function getFormPath(): string
private function setFormClass(): void
{
$this->formClass = 'App\\Form\\'.implode('\\', $this->sourceMeta->getBasicPathArray()).'\\'.$this->sourceMeta->getBasicName().'Type';
}
private function setMeta(): void
{
$this->templateMeta = new TemplateMeta($this->sourceMeta->getBasicPathArray(), $this->sourceMeta->getBasicName(), self::FOLDER);
}
public function getFormClass(): string
{
return $this->formClass;
}
public function getTemplateMeta(): string
{
return $this->templateMeta;
}
}

View File

@ -4,5 +4,7 @@ namespace App\Domain\FormManagement;
interface FormMetaInterface
{
public function getFormPath(): string;
public function getFormClass(): string;
public function getTemplateMeta(): string;
}

View File

@ -2,9 +2,11 @@
namespace App\Domain\SourceManagement;
use App\Domain\FormManagement\FormMetaInterface;
use App\Domain\TemplateManagement\TemplateMetaInterface;
use App\Entity\Source\SourceInterface;
use App\Domain\TemplateManagement\TemplateMeta;
use App\Domain\FormManagement\FormMeta;
/**
* @author kevinfrantz
@ -41,6 +43,11 @@ class SourceMeta implements SourceMetaInterface
*/
private $source;
/**
* @var FormMetaInterface
*/
private $formMeta;
public function __construct(SourceInterface $source)
{
$this->source = $source;
@ -48,7 +55,8 @@ class SourceMeta implements SourceMetaInterface
$this->setBasicPathArray();
$this->setBasicName();
$this->setInterfaceReflection();
$this->templateMeta = new TemplateMeta($this);
$this->templateMeta = new TemplateMeta($this->basicPathArray, $this->basicName, 'entity');
$this->formMeta = new FormMeta($this);
}
private function setBasicPathArray(): void
@ -103,4 +111,9 @@ class SourceMeta implements SourceMetaInterface
{
return $this->source;
}
public function getFormMeta(): FormMetaInterface
{
return $this->formMeta;
}
}

View File

@ -4,6 +4,7 @@ namespace App\Domain\SourceManagement;
use App\Domain\TemplateManagement\TemplateMetaInterface;
use App\Entity\Source\SourceInterface;
use App\Domain\FormManagement\FormMetaInterface;
/**
* A meta source offers informations, which the system needs to handle the source.
@ -32,4 +33,6 @@ interface SourceMetaInterface
* @return SourceInterface The source to which the meta object belongs to
*/
public function getSource(): SourceInterface;
public function getFormMeta(): FormMetaInterface;
}

View File

@ -2,7 +2,6 @@
namespace App\Domain\TemplateManagement;
use App\Domain\SourceManagement\SourceMetaInterface;
use App\DBAL\Types\TemplateType;
/**
@ -11,9 +10,14 @@ use App\DBAL\Types\TemplateType;
class TemplateMeta implements TemplateMetaInterface
{
/**
* @var SourceMetaInterface
* @var array
*/
private $sourceMeta;
private $basicPathArray;
/**
* @var string
*/
private $basicName;
/**
* @var string
@ -35,9 +39,16 @@ class TemplateMeta implements TemplateMetaInterface
*/
private $contentTemplatePath;
public function __construct(SourceMetaInterface $sourceMeta)
/**
* @var string
*/
private $folder;
public function __construct(array $basicPathArray, string $basicName, string $folder)
{
$this->sourceMeta = $sourceMeta;
$this->basicPathArray = $basicPathArray;
$this->basicName = $basicName;
$this->folder = $folder;
$this->init();
}
@ -50,7 +61,7 @@ class TemplateMeta implements TemplateMetaInterface
private function setPathSuffix(): void
{
$this->pathSuffix = implode('/', $this->sourceMeta->getBasicPathArray()).'/'.$this->sourceMeta->getBasicName().'.'.$this->type.'.twig';
$this->pathSuffix = $this->folder.'/'.implode('/', $this->basicPathArray).'/'.$this->basicName.'.'.$this->type.'.twig';
}
private function setFrameTemplatePath(): void
@ -83,4 +94,9 @@ class TemplateMeta implements TemplateMetaInterface
{
return $this->type;
}
public function getPathSuffix(): string
{
return $this->pathSuffix;
}
}

View File

@ -23,13 +23,14 @@ class TemplateMetaTest extends TestCase
private function getExpectedPath(string $type, string $context): string
{
return $context.'/source/primitive/name/firstname.'.$type.'.twig';
return $context.'/entity/source/primitive/name/firstname.'.$type.'.twig';
}
public function setUp(): void
{
$this->source = new FirstNameSource();
$this->templateMeta = new TemplateMeta(new SourceMeta($this->source));
$sourceMeta = new SourceMeta($this->source);
$this->templateMeta = new TemplateMeta($sourceMeta->getBasicPathArray(), $sourceMeta->getBasicName(), 'entity');
}
public function testFrameTemplatePath(): void