mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-03-28 01:23:33 +01:00
Optimized EntityDomService
This commit is contained in:
parent
4385e84cc7
commit
d0adc9b42a
@ -8,4 +8,5 @@ twig:
|
|||||||
requested_action_service: "@Infinito\\Domain\\RequestManagement\\Action\\RequestedActionService"
|
requested_action_service: "@Infinito\\Domain\\RequestManagement\\Action\\RequestedActionService"
|
||||||
action_icon_class_map: "@Infinito\\Domain\\TwigManagement\\ActionIconClassMap"
|
action_icon_class_map: "@Infinito\\Domain\\TwigManagement\\ActionIconClassMap"
|
||||||
action_template_name_service: "@Infinito\\Domain\\TemplateManagement\\ActionTemplateNameServiceInterface"
|
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"
|
@ -16,7 +16,6 @@ final class ActionType extends CRUDType
|
|||||||
*/
|
*/
|
||||||
const EXECUTE = 'execute';
|
const EXECUTE = 'execute';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
@ -21,6 +21,8 @@ final class LayerType extends AbstractEnumType
|
|||||||
|
|
||||||
public const MEMBER = 'member';
|
public const MEMBER = 'member';
|
||||||
|
|
||||||
|
const CREATOR = 'creator';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array Ordered by the importants of implementation
|
* @var array Ordered by the importants of implementation
|
||||||
*/
|
*/
|
||||||
@ -30,5 +32,6 @@ final class LayerType extends AbstractEnumType
|
|||||||
self::RIGHT => 'right',
|
self::RIGHT => 'right',
|
||||||
self::MEMBER => 'member',
|
self::MEMBER => 'member',
|
||||||
self::HEREDITY => 'heredity',
|
self::HEREDITY => 'heredity',
|
||||||
|
self::CREATOR => 'creator',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ use Infinito\Entity\EntityInterface;
|
|||||||
use Infinito\Domain\LayerManagement\LayerClassMap;
|
use Infinito\Domain\LayerManagement\LayerClassMap;
|
||||||
use Infinito\Domain\RightManagement\RightTransformerService;
|
use Infinito\Domain\RightManagement\RightTransformerService;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Infinito\Domain\RequestManagement\Entity\RequestedEntityServiceInterface;
|
||||||
|
use Infinito\Exception\NotCorrectInstanceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
@ -22,6 +24,11 @@ final class EntityDomService implements EntityDomServiceInterface
|
|||||||
*/
|
*/
|
||||||
const HAS_METHOD = RightTransformerService::HAS_PREFIX;
|
const HAS_METHOD = RightTransformerService::HAS_PREFIX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var RequestedEntityServiceInterface
|
||||||
|
*/
|
||||||
|
private $requestedEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var EntityInterface
|
* @var EntityInterface
|
||||||
*/
|
*/
|
||||||
@ -42,6 +49,14 @@ final class EntityDomService implements EntityDomServiceInterface
|
|||||||
*/
|
*/
|
||||||
private $domDocument;
|
private $domDocument;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param RequestedEntityServiceInterface $requestedEntity
|
||||||
|
*/
|
||||||
|
public function __construct(RequestedEntityServiceInterface $requestedEntity)
|
||||||
|
{
|
||||||
|
$this->requestedEntity = $requestedEntity;
|
||||||
|
}
|
||||||
|
|
||||||
private function createProperties(): void
|
private function createProperties(): void
|
||||||
{
|
{
|
||||||
$this->properties = $this->entityReflectionClass->getProperties();
|
$this->properties = $this->entityReflectionClass->getProperties();
|
||||||
@ -84,8 +99,9 @@ final class EntityDomService implements EntityDomServiceInterface
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$getMethod = $this->getMethodName(self::GET_METHOD, $propertyName);
|
$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) {
|
foreach (LayerClassMap::LAYER_CLASS_MAP as $layer => $class) {
|
||||||
if ($value instanceof $class) {
|
if ($value instanceof $class) {
|
||||||
$domElement->setAttribute('layer', $layer);
|
$domElement->setAttribute('layer', $layer);
|
||||||
|
$domElement->setAttribute('id', $value->getId());
|
||||||
$domElement->setAttribute('value', $value->getId());
|
$domElement->setAttribute('value', $value->getId());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (is_object($value)) {
|
||||||
|
throw new NotCorrectInstanceException('The instance '.get_class($value).' is not supported!');
|
||||||
|
}
|
||||||
$domElement->setAttribute('value', $value);
|
$domElement->setAttribute('value', $value);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -135,25 +155,32 @@ final class EntityDomService implements EntityDomServiceInterface
|
|||||||
*
|
*
|
||||||
* @see \Infinito\Domain\DomManagement\EntityDomServiceInterface::getDomDocument()
|
* @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->createProperties();
|
||||||
$this->createDomDocument();
|
$this->createDomDocument();
|
||||||
foreach ($this->properties as $property) {
|
foreach ($this->properties as $property) {
|
||||||
$propertyName = $property->getName();
|
$propertyName = $property->getName();
|
||||||
if ($this->isPropertyAccessible($propertyName)) {
|
if ($this->isPropertyAccessible($propertyName)) {
|
||||||
$domElement = $this->domDocument->createElement($propertyName);
|
$domElement = $this->domDocument->createElement('attribut');
|
||||||
|
$domElement->setAttribute('name', $propertyName);
|
||||||
$value = $this->getPropertyValue($propertyName);
|
$value = $this->getPropertyValue($propertyName);
|
||||||
if ($value instanceof Collection) {
|
if ($value instanceof Collection) {
|
||||||
foreach ($value as $valueElement) {
|
foreach ($value as $valueElement) {
|
||||||
$domSubElement = $domElement->createElement('list-element');
|
$domSubElement = $domElement->createElement('list-element');
|
||||||
|
$domElement->setAttribute('name', $propertyName);
|
||||||
$this->mappValue($valueElement, $domSubElement);
|
$this->mappValue($valueElement, $domSubElement);
|
||||||
|
$domElement->appendChild($domSubElement);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->mappValue($value, $domElement);
|
$this->mappValue($value, $domElement);
|
||||||
}
|
}
|
||||||
|
$this->domDocument->appendChild($domElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$this->domDocument->saveXML();
|
||||||
|
|
||||||
return $this->domDocument;
|
return $this->domDocument;
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Infinito\Domain\DomManagement;
|
namespace Infinito\Domain\DomManagement;
|
||||||
|
|
||||||
use Infinito\Entity\EntityInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to build a DOM for an entity.
|
* Allows to build a DOM for an entity.
|
||||||
*
|
*
|
||||||
@ -14,9 +12,7 @@ use Infinito\Entity\EntityInterface;
|
|||||||
interface EntityDomServiceInterface
|
interface EntityDomServiceInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param EntityInterface $entity
|
|
||||||
*
|
|
||||||
* @return \DOMDocument
|
* @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\Exception\NotSetException;
|
||||||
use Infinito\Entity\Meta\Law;
|
use Infinito\Entity\Meta\Law;
|
||||||
use Infinito\Entity\Meta\Right;
|
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
|
* @author kevinfrantz
|
||||||
@ -20,6 +23,9 @@ final class LayerClassMap implements LayerClassMapInterface
|
|||||||
LayerType::SOURCE => AbstractSource::class,
|
LayerType::SOURCE => AbstractSource::class,
|
||||||
LayerType::LAW => Law::class,
|
LayerType::LAW => Law::class,
|
||||||
LayerType::RIGHT => Right::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
|
* @var string The path to the general entity template
|
||||||
*/
|
*/
|
||||||
const TWIG_ENTITY_TEMPLATE_PATH = 'entity/entity.html.twig';
|
const TWIG_ENTITY_TEMPLATE_PATH = 'entity/entity.html.twig';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ActionHandlerServiceInterface
|
* @var ActionHandlerServiceInterface
|
||||||
*/
|
*/
|
||||||
@ -55,6 +55,7 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
|
|||||||
{
|
{
|
||||||
$view = View::create();
|
$view = View::create();
|
||||||
$view->setTemplate(self::TWIG_ENTITY_TEMPLATE_PATH);
|
$view->setTemplate(self::TWIG_ENTITY_TEMPLATE_PATH);
|
||||||
|
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
* @ORM\Entity()
|
* @ORM\Entity(repositoryClass="Infinito\Repository\Meta\Relation\Member\MemberRepository")
|
||||||
*/
|
*/
|
||||||
class MemberRelation extends AbstractRelation implements MemberRelationInterface
|
class MemberRelation extends AbstractRelation implements MemberRelationInterface
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@ use Doctrine\Common\Collections\Collection;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
* @ORM\Entity()
|
* @ORM\Entity(repositoryClass="Infinito\Repository\Meta\Relation\Parent\CreatorRepository")
|
||||||
*/
|
*/
|
||||||
class CreatorRelation extends AbstractParentRelation implements CreatorRelationInterface
|
class CreatorRelation extends AbstractParentRelation implements CreatorRelationInterface
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
* @ORM\Entity()
|
* * @ORM\Entity(repositoryClass="Infinito\Repository\Meta\Relation\Parent\HeredityRepository")
|
||||||
*/
|
*/
|
||||||
class HeredityRelation extends AbstractParentRelation implements HeredityRelationInterface
|
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
|
||||||
|
{
|
||||||
|
}
|
23
application/symfony/templates/entity/_entity_read.html.twig
Normal file
23
application/symfony/templates/entity/_entity_read.html.twig
Normal 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>
|
||||||
|
|
@ -15,8 +15,8 @@
|
|||||||
</h1>
|
</h1>
|
||||||
<div id="accordion">
|
<div id="accordion">
|
||||||
{% for action in layer_action_map.getActions(layer) %}
|
{% for action in layer_action_map.getActions(layer) %}
|
||||||
{{ action_template_name_service.setActionType(action) }}
|
{% if action_template_data_store_service.isDataStored(action) %}
|
||||||
{% if action_template_name_service.doesAtomTemplateExist() %}
|
{{ action_template_name_service.setActionType(action) }}
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header" id="heading_{{ action }}">
|
<div class="card-header" id="heading_{{ action }}">
|
||||||
<h5 class="mb-0">
|
<h5 class="mb-0">
|
||||||
@ -30,7 +30,7 @@
|
|||||||
<div id="collapse_{{ action }}" class="collapse"
|
<div id="collapse_{{ action }}" class="collapse"
|
||||||
aria-labelledby="heading_{{ action }}" data-parent="#accordion">
|
aria-labelledby="heading_{{ action }}" data-parent="#accordion">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
{% include action_template_name_service.getAtomTemplateName() %}
|
{% include [action_template_name_service.getAtomTemplateName(),'entity/_entity_'~action~'.html.twig'] %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user