Optimized EntityDomService

This commit is contained in:
Kevin Frantz 2019-02-25 10:05:42 +01:00
parent 4385e84cc7
commit d0adc9b42a
18 changed files with 109 additions and 17 deletions

View File

@ -8,4 +8,5 @@ twig:
requested_action_service: "@Infinito\\Domain\\RequestManagement\\Action\\RequestedActionService"
action_icon_class_map: "@Infinito\\Domain\\TwigManagement\\ActionIconClassMap"
action_template_name_service: "@Infinito\\Domain\\TemplateManagement\\ActionTemplateNameServiceInterface"
action_template_data_store_service: "@Infinito\\Domain\\TemplateManagement\\ActionTemplateDataStoreServiceInterface"
action_template_data_store_service: "@Infinito\\Domain\\TemplateManagement\\ActionTemplateDataStoreServiceInterface"
entity_dom_service: "@Infinito\\Domain\\DomManagement\\EntityDomServiceInterface"

View File

@ -16,7 +16,6 @@ final class ActionType extends CRUDType
*/
const EXECUTE = 'execute';
/**
* @var array
*/

View File

@ -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',
];
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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,
];
/**

View File

@ -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;
}

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -0,0 +1,12 @@
<?php
namespace Infinito\Repository\Meta\Relation\Member;
use Infinito\Repository\AbstractRepository;
/**
* @author kevinfrantz
*/
final class MemberRepository extends AbstractRepository
{
}

View File

@ -0,0 +1,12 @@
<?php
namespace Infinito\Repository\Meta\Relation\Parent;
use Infinito\Repository\AbstractRepository;
/**
* @author kevinfrantz
*/
final class CreatorRepository extends AbstractRepository
{
}

View File

@ -0,0 +1,12 @@
<?php
namespace Infinito\Repository\Meta\Relation\Parent;
use Infinito\Repository\AbstractRepository;
/**
* @author kevinfrantz
*/
final class HeredityRepository extends AbstractRepository
{
}

View File

@ -0,0 +1,23 @@
<table class="Table">
<tr>
<th>{{'Attribut'|trans}}</th>
<th>{{'Value'|trans}}</th>
</tr>
{% for node in entity_dom_service.getDomDocument().childNodes %}
{% set id = node.getAttribute('id') %}
{% set layer = node.getAttribute('layer') %}
{% set content = node.getAttribute('value') %}
{% set name = node.getAttribute('name') %}
<tr>
<td>{{ name|trans }}</td>
<td>
{% if id and layer %}
<a href="{{ path('infinito_api_rest_layer_read',{'identity':id,'layer':layer,'_format':'html'}) }}">{{ content }}</a>
{% else %}
{{ content }}
{% endif %}
</td>
</tr>
{% endfor %}
</table>

View File

@ -15,8 +15,8 @@
</h1>
<div id="accordion">
{% for action in layer_action_map.getActions(layer) %}
{{ action_template_name_service.setActionType(action) }}
{% if action_template_name_service.doesAtomTemplateExist() %}
{% if action_template_data_store_service.isDataStored(action) %}
{{ action_template_name_service.setActionType(action) }}
<div class="card">
<div class="card-header" id="heading_{{ action }}">
<h5 class="mb-0">
@ -30,7 +30,7 @@
<div id="collapse_{{ action }}" class="collapse"
aria-labelledby="heading_{{ action }}" data-parent="#accordion">
<div class="card-body">
{% include action_template_name_service.getAtomTemplateName() %}
{% include [action_template_name_service.getAtomTemplateName(),'entity/_entity_'~action~'.html.twig'] %}
</div>
</div>
</div>