mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 06:01:35 +01:00
implemented sourcemeta and test
This commit is contained in:
parent
0e04da8ea1
commit
8a311caddc
22
application/src/DBAL/Types/TemplateType.php
Normal file
22
application/src/DBAL/Types/TemplateType.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\DBAL\Types;
|
||||
|
||||
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
|
||||
|
||||
/**
|
||||
* Containes the template types which the system can process.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class TemplateType extends AbstractEnumType
|
||||
{
|
||||
public const JSON = 'json';
|
||||
|
||||
public const HTML = 'html';
|
||||
|
||||
protected static $choices = [
|
||||
self::JSON => 'json',
|
||||
self::HTML => 'html',
|
||||
];
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\FormManagement;
|
||||
|
||||
interface FormMetaInterface
|
||||
{
|
||||
public function getFormPath(): string;
|
||||
}
|
106
application/src/Domain/SourceManagement/SourceMeta.php
Normal file
106
application/src/Domain/SourceManagement/SourceMeta.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use App\Domain\TemplateManagement\TemplateMetaInterface;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Domain\TemplateManagement\TemplateMeta;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class SourceMeta implements SourceMetaInterface
|
||||
{
|
||||
/**
|
||||
* @var \ReflectionClass
|
||||
*/
|
||||
private $sourceReflection;
|
||||
|
||||
/**
|
||||
* @var \ReflectionClass
|
||||
*/
|
||||
private $interfaceReflection;
|
||||
|
||||
/**
|
||||
* @var TemplateMetaInterface
|
||||
*/
|
||||
private $templateMeta;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $basicPathArray;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $basicName;
|
||||
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
private $source;
|
||||
|
||||
public function __construct(SourceInterface $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
$this->sourceReflection = new \ReflectionClass($source);
|
||||
$this->setBasicPathArray();
|
||||
$this->setBasicName();
|
||||
$this->setInterfaceReflection();
|
||||
$this->templateMeta = new TemplateMeta($this);
|
||||
}
|
||||
|
||||
private function setBasicPathArray(): void
|
||||
{
|
||||
$namespace = $this->sourceReflection->getNamespaceName();
|
||||
$namespaceWithoutRoot = str_replace('App\\', '', $namespace);
|
||||
$this->basicPathArray = [];
|
||||
foreach (explode('\\', $namespaceWithoutRoot) as $element) {
|
||||
$this->basicPathArray[] = strtolower($element);
|
||||
}
|
||||
}
|
||||
|
||||
private function setInterfaceReflection(): void
|
||||
{
|
||||
$namespace = str_replace('\Abstract', '\\', $this->sourceReflection->getName()).'Interface';
|
||||
$this->interfaceReflection = new \ReflectionClass($namespace);
|
||||
}
|
||||
|
||||
private function setBasicName(): void
|
||||
{
|
||||
$withoutAbstract = str_replace('Abstract', '', $this->sourceReflection->getShortName());
|
||||
$withoutSource = str_replace('Source', '', $withoutAbstract);
|
||||
$this->basicName = strtolower($withoutSource);
|
||||
}
|
||||
|
||||
public function getBasicPathArray(): array
|
||||
{
|
||||
return $this->basicPathArray;
|
||||
}
|
||||
|
||||
public function getInterfaceReflection(): \ReflectionClass
|
||||
{
|
||||
return $this->interfaceReflection;
|
||||
}
|
||||
|
||||
public function getSourceReflection(): \ReflectionClass
|
||||
{
|
||||
return $this->sourceReflection;
|
||||
}
|
||||
|
||||
public function getTemplateMeta(): TemplateMetaInterface
|
||||
{
|
||||
return $this->templateMeta;
|
||||
}
|
||||
|
||||
public function getBasicName(): string
|
||||
{
|
||||
return $this->basicName;
|
||||
}
|
||||
|
||||
public function getSource(): SourceInterface
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use App\Domain\TemplateManagement\TemplateMetaInterface;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
/**
|
||||
* A meta source offers informations, which the system needs to handle the source.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface SourceMetaInterface
|
||||
{
|
||||
public function getSourceReflection(): \ReflectionClass;
|
||||
|
||||
public function getInterfaceReflection(): \ReflectionClass;
|
||||
|
||||
public function getTemplateMeta(): TemplateMetaInterface;
|
||||
|
||||
/**
|
||||
* @return array the namespace elements without the root
|
||||
*/
|
||||
public function getBasicPathArray(): array;
|
||||
|
||||
/**
|
||||
* @return string Short class name in lower case without "Abstract" and "Source"
|
||||
*/
|
||||
public function getBasicName(): string;
|
||||
|
||||
/**
|
||||
* @return SourceInterface The source to which the meta object belongs to
|
||||
*/
|
||||
public function getSource(): SourceInterface;
|
||||
}
|
41
application/src/Domain/TemplateManagement/TemplateMeta.php
Normal file
41
application/src/Domain/TemplateManagement/TemplateMeta.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\TemplateManagement;
|
||||
|
||||
use App\Domain\FormManagement\FormMetaInterface;
|
||||
use App\Domain\SourceManagement\SourceMetaInterface;
|
||||
use App\DBAL\Types\TemplateType;
|
||||
|
||||
class TemplateMeta implements TemplateMetaInterface
|
||||
{
|
||||
/**
|
||||
* @var TemplateMetaInterface
|
||||
*/
|
||||
private $sourceMeta;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $type = TemplateType::HTML;
|
||||
|
||||
public function __construct(SourceMetaInterface $sourceMeta)
|
||||
{
|
||||
$this->sourceMeta = $sourceMeta;
|
||||
}
|
||||
|
||||
public function getFramedTemplatePath(): string
|
||||
{
|
||||
}
|
||||
|
||||
public function getFramelessTemplatePath(): string
|
||||
{
|
||||
}
|
||||
|
||||
public function getFormMeta(): FormMetaInterface
|
||||
{
|
||||
}
|
||||
|
||||
public function setTemplateType(string $type): void
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\TemplateManagement;
|
||||
|
||||
use App\Domain\FormManagement\FormMetaInterface;
|
||||
|
||||
/**
|
||||
* Manages all informations which are needed to process templates.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface TemplateMetaInterface
|
||||
{
|
||||
/**
|
||||
* Sets the template type which should be processed(General html);.
|
||||
*/
|
||||
public function setTemplateType(string $type): void;
|
||||
|
||||
/**
|
||||
* Returns a template inclusiv frame.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFramedTemplatePath(): string;
|
||||
|
||||
/**
|
||||
* Returns a template without a frame.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFramelessTemplatePath(): string;
|
||||
|
||||
/**
|
||||
* @return FormMetaInterface
|
||||
*/
|
||||
public function getFormMeta(): FormMetaInterface;
|
||||
}
|
@ -10,9 +10,6 @@ use App\Entity\Source\SourceInterface;
|
||||
trait SourceAttribut
|
||||
{
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="AbstractSource")
|
||||
* @ORM\JoinColumn(name="source_id", referencedColumnName="id")
|
||||
*
|
||||
* @var SourceInterface
|
||||
*/
|
||||
protected $source;
|
||||
|
@ -11,6 +11,7 @@ use App\Entity\UserInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @deprecated Just exists as a remembering to maybe use the voter for some use cases
|
||||
* @see https://symfony.com/doc/current/security/voters.html
|
||||
*/
|
||||
|
@ -12,7 +12,7 @@ class UrlIntegrationTest extends KernelTestCase
|
||||
'imprint' => 200,
|
||||
'register' => 301,
|
||||
'logout' => 302,
|
||||
'profile/edit'=>302,
|
||||
'profile/edit' => 302,
|
||||
];
|
||||
|
||||
public function setUp(): void
|
||||
|
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Domain\SourceManagement;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Domain\SourceManagement\SourceMetaInterface;
|
||||
use App\Entity\Source\Complex\UserSource;
|
||||
use App\Domain\SourceManagement\SourceMeta;
|
||||
use App\Entity\Source\Complex\UserSourceInterface;
|
||||
use App\Domain\TemplateManagement\TemplateMetaInterface;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
class SourceMetaTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var SourceMetaInterface
|
||||
*/
|
||||
protected $sourceMeta;
|
||||
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->source = new UserSource();
|
||||
$this->sourceMeta = new SourceMeta($this->source);
|
||||
}
|
||||
|
||||
public function testBasicName(): void
|
||||
{
|
||||
$this->assertEquals('user', $this->sourceMeta->getBasicName());
|
||||
$this->assertNotEquals('user2', $this->sourceMeta->getBasicName());
|
||||
}
|
||||
|
||||
public function testBasicPath(): void
|
||||
{
|
||||
$subset = ['entity', 'source', 'complex'];
|
||||
$amount = count($subset);
|
||||
$basicPathArray = $this->sourceMeta->getBasicPathArray();
|
||||
for ($index = 0; $index < $amount; ++$index) {
|
||||
$this->assertEquals($subset[$index], $basicPathArray[$index]);
|
||||
}
|
||||
$this->assertArraySubset($subset, $basicPathArray);
|
||||
$this->assertEquals($amount, count($basicPathArray));
|
||||
}
|
||||
|
||||
public function testInterfaceReflection(): void
|
||||
{
|
||||
/**
|
||||
* @var \ReflectionClass
|
||||
*/
|
||||
$interfaceReflection = $this->sourceMeta->getInterfaceReflection();
|
||||
$this->assertEquals(UserSourceInterface::class, $interfaceReflection->getName());
|
||||
}
|
||||
|
||||
public function testSourceReflection(): void
|
||||
{
|
||||
/**
|
||||
* @var \ReflectionClass
|
||||
*/
|
||||
$sourceReflection = $this->sourceMeta->getSourceReflection();
|
||||
$this->assertEquals(UserSource::class, $sourceReflection->getName());
|
||||
}
|
||||
|
||||
public function testTemplateMeta(): void
|
||||
{
|
||||
$this->assertInstanceOf(TemplateMetaInterface::class, $this->sourceMeta->getTemplateMeta());
|
||||
}
|
||||
|
||||
public function testSource(): void
|
||||
{
|
||||
$this->assertEquals($this->source, $this->sourceMeta->getSource());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user