mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Optimized EntityDomService
This commit is contained in:
@@ -16,7 +16,6 @@ final class ActionType extends CRUDType
|
||||
*/
|
||||
const EXECUTE = 'execute';
|
||||
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
@@ -21,6 +21,8 @@ final class LayerType extends AbstractEnumType
|
||||
|
||||
public const MEMBER = 'member';
|
||||
|
||||
const CREATOR = 'creator';
|
||||
|
||||
/**
|
||||
* @var array Ordered by the importants of implementation
|
||||
*/
|
||||
@@ -30,5 +32,6 @@ final class LayerType extends AbstractEnumType
|
||||
self::RIGHT => 'right',
|
||||
self::MEMBER => 'member',
|
||||
self::HEREDITY => 'heredity',
|
||||
self::CREATOR => 'creator',
|
||||
];
|
||||
}
|
||||
|
@@ -6,6 +6,8 @@ use Infinito\Entity\EntityInterface;
|
||||
use Infinito\Domain\LayerManagement\LayerClassMap;
|
||||
use Infinito\Domain\RightManagement\RightTransformerService;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Infinito\Domain\RequestManagement\Entity\RequestedEntityServiceInterface;
|
||||
use Infinito\Exception\NotCorrectInstanceException;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@@ -22,6 +24,11 @@ final class EntityDomService implements EntityDomServiceInterface
|
||||
*/
|
||||
const HAS_METHOD = RightTransformerService::HAS_PREFIX;
|
||||
|
||||
/**
|
||||
* @var RequestedEntityServiceInterface
|
||||
*/
|
||||
private $requestedEntity;
|
||||
|
||||
/**
|
||||
* @var EntityInterface
|
||||
*/
|
||||
@@ -42,6 +49,14 @@ final class EntityDomService implements EntityDomServiceInterface
|
||||
*/
|
||||
private $domDocument;
|
||||
|
||||
/**
|
||||
* @param RequestedEntityServiceInterface $requestedEntity
|
||||
*/
|
||||
public function __construct(RequestedEntityServiceInterface $requestedEntity)
|
||||
{
|
||||
$this->requestedEntity = $requestedEntity;
|
||||
}
|
||||
|
||||
private function createProperties(): void
|
||||
{
|
||||
$this->properties = $this->entityReflectionClass->getProperties();
|
||||
@@ -84,8 +99,9 @@ final class EntityDomService implements EntityDomServiceInterface
|
||||
return null;
|
||||
}
|
||||
$getMethod = $this->getMethodName(self::GET_METHOD, $propertyName);
|
||||
$result = $this->getMethodResult($getMethod);
|
||||
|
||||
return $this->getMethodResult($getMethod);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,11 +113,15 @@ final class EntityDomService implements EntityDomServiceInterface
|
||||
foreach (LayerClassMap::LAYER_CLASS_MAP as $layer => $class) {
|
||||
if ($value instanceof $class) {
|
||||
$domElement->setAttribute('layer', $layer);
|
||||
$domElement->setAttribute('id', $value->getId());
|
||||
$domElement->setAttribute('value', $value->getId());
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (is_object($value)) {
|
||||
throw new NotCorrectInstanceException('The instance '.get_class($value).' is not supported!');
|
||||
}
|
||||
$domElement->setAttribute('value', $value);
|
||||
|
||||
return;
|
||||
@@ -135,25 +155,32 @@ final class EntityDomService implements EntityDomServiceInterface
|
||||
*
|
||||
* @see \Infinito\Domain\DomManagement\EntityDomServiceInterface::getDomDocument()
|
||||
*/
|
||||
public function getDomDocument(EntityInterface $entity): \DOMDocument
|
||||
public function getDomDocument(): \DOMDocument
|
||||
{
|
||||
$this->entity = $this->requestedEntity->getEntity();
|
||||
$this->entityReflectionClass = new \ReflectionClass($this->entity);
|
||||
$this->createProperties();
|
||||
$this->createDomDocument();
|
||||
foreach ($this->properties as $property) {
|
||||
$propertyName = $property->getName();
|
||||
if ($this->isPropertyAccessible($propertyName)) {
|
||||
$domElement = $this->domDocument->createElement($propertyName);
|
||||
$domElement = $this->domDocument->createElement('attribut');
|
||||
$domElement->setAttribute('name', $propertyName);
|
||||
$value = $this->getPropertyValue($propertyName);
|
||||
if ($value instanceof Collection) {
|
||||
foreach ($value as $valueElement) {
|
||||
$domSubElement = $domElement->createElement('list-element');
|
||||
$domElement->setAttribute('name', $propertyName);
|
||||
$this->mappValue($valueElement, $domSubElement);
|
||||
$domElement->appendChild($domSubElement);
|
||||
}
|
||||
} else {
|
||||
$this->mappValue($value, $domElement);
|
||||
}
|
||||
$this->domDocument->appendChild($domElement);
|
||||
}
|
||||
}
|
||||
$this->domDocument->saveXML();
|
||||
|
||||
return $this->domDocument;
|
||||
}
|
||||
|
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Infinito\Domain\DomManagement;
|
||||
|
||||
use Infinito\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Allows to build a DOM for an entity.
|
||||
*
|
||||
@@ -14,9 +12,7 @@ use Infinito\Entity\EntityInterface;
|
||||
interface EntityDomServiceInterface
|
||||
{
|
||||
/**
|
||||
* @param EntityInterface $entity
|
||||
*
|
||||
* @return \DOMDocument
|
||||
*/
|
||||
public function getDomDocument(EntityInterface $entity): \DOMDocument;
|
||||
public function getDomDocument(): \DOMDocument;
|
||||
}
|
||||
|
@@ -7,6 +7,9 @@ use Infinito\Entity\Source\AbstractSource;
|
||||
use Infinito\Exception\NotSetException;
|
||||
use Infinito\Entity\Meta\Law;
|
||||
use Infinito\Entity\Meta\Right;
|
||||
use Infinito\Entity\Meta\Relation\Parent\HeredityRelation;
|
||||
use Infinito\Entity\Meta\Relation\Member\MemberRelation;
|
||||
use Infinito\Entity\Meta\Relation\Parent\CreatorRelation;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@@ -20,6 +23,9 @@ final class LayerClassMap implements LayerClassMapInterface
|
||||
LayerType::SOURCE => AbstractSource::class,
|
||||
LayerType::LAW => Law::class,
|
||||
LayerType::RIGHT => Right::class,
|
||||
LayerType::HEREDITY => HeredityRelation::class,
|
||||
LayerType::MEMBER => MemberRelation::class,
|
||||
LayerType::CREATOR => CreatorRelation::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@@ -22,7 +22,7 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
|
||||
* @var string The path to the general entity template
|
||||
*/
|
||||
const TWIG_ENTITY_TEMPLATE_PATH = 'entity/entity.html.twig';
|
||||
|
||||
|
||||
/**
|
||||
* @var ActionHandlerServiceInterface
|
||||
*/
|
||||
@@ -55,6 +55,7 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
|
||||
{
|
||||
$view = View::create();
|
||||
$view->setTemplate(self::TWIG_ENTITY_TEMPLATE_PATH);
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @ORM\Entity()
|
||||
* @ORM\Entity(repositoryClass="Infinito\Repository\Meta\Relation\Member\MemberRepository")
|
||||
*/
|
||||
class MemberRelation extends AbstractRelation implements MemberRelationInterface
|
||||
{
|
||||
|
@@ -7,7 +7,7 @@ use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @ORM\Entity()
|
||||
* @ORM\Entity(repositoryClass="Infinito\Repository\Meta\Relation\Parent\CreatorRepository")
|
||||
*/
|
||||
class CreatorRelation extends AbstractParentRelation implements CreatorRelationInterface
|
||||
{
|
||||
|
@@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @ORM\Entity()
|
||||
* * @ORM\Entity(repositoryClass="Infinito\Repository\Meta\Relation\Parent\HeredityRepository")
|
||||
*/
|
||||
class HeredityRelation extends AbstractParentRelation implements HeredityRelationInterface
|
||||
{
|
||||
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Repository\Meta\Relation\Member;
|
||||
|
||||
use Infinito\Repository\AbstractRepository;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class MemberRepository extends AbstractRepository
|
||||
{
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Repository\Meta\Relation\Parent;
|
||||
|
||||
use Infinito\Repository\AbstractRepository;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class CreatorRepository extends AbstractRepository
|
||||
{
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Repository\Meta\Relation\Parent;
|
||||
|
||||
use Infinito\Repository\AbstractRepository;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class HeredityRepository extends AbstractRepository
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user