Moved meta entities to meta

This commit is contained in:
Kevin Frantz
2018-10-28 15:25:32 +01:00
parent 5af5a6b5e2
commit 25020bbe97
23 changed files with 76 additions and 44 deletions

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Entity\Meta;
use App\Entity\AbstractEntity;
/**
*
* @author kevinfrantz
*
*/
abstract class AbstractMeta extends AbstractEntity implements MetaInterface
{
}

View File

@@ -0,0 +1,60 @@
<?php
namespace App\Entity\Meta;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\RightsAttribute;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attribut\RelationAttribut;
/**
*
* @author kevinfrantz
* @ORM\Table(name="law")
* @ORM\Entity(repositoryClass="App\Repository\LawRepository")
*/
class Law extends AbstractMeta implements LawInterface
{
use RightsAttribute, RelationAttribut;
/**
*
* @ORM\OneToMany(targetEntity="Right", mappedBy="law", cascade={"persist", "remove"})
*
* @var ArrayCollection | Right[]
*/
protected $rights;
/**
*
* @ORM\OneToOne(targetEntity="Relation",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id")
*
* @var RelationInterface
*/
protected $relation;
public function __construct()
{
$this->initAllRights();
}
private function initAllRights(): void
{
$this->rights = new ArrayCollection();
}
public function isGranted(RelationInterface $relation, string $layer, string $right): bool
{
/**
*
* @var RightInterface
*/
foreach ($this->rights->toArray() as $right) {
if ($right->isGranted($relation, $layer, $right)) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace App\Entity\Meta;
use App\Entity\Attribut\RightsAttributInterface;
use App\Entity\Attribut\RelationAttributInterface;
use App\Entity\Method\RelationGrantedInterface;
/**
* @author kevinfrantz
*/
interface LawInterface extends RightsAttributInterface, RelationGrantedInterface, RelationAttributInterface,MetaInterface
{
}

View File

@@ -0,0 +1,15 @@
<?php
namespace App\Entity\Meta;
use App\Entity\EntityInterface;
/**
* Meta entities contain informations which describe sources.
* If you refer from a meta entity to an source be aware to catch infinite loops!
* @author kevinfrantz
*
*/
interface MetaInterface extends EntityInterface
{
}

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Entity\Meta;
use App\Entity\Attribut\RecieverAttribut;
use Doctrine\Common\Collections\ArrayCollection;
use App\DBAL\Types\RecieverType;
use Symfony\Component\Intl\Exception\NotImplementedException;
use Doctrine\ORM\Mapping as ORM;
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
use App\Entity\Attribut\RelationAttribut;
use App\Entity\Attribut\RelationAttributInterface;
/**
* @author kevinfrantz
* @ORM\Table(name="reciever_group")
* @ORM\Entity()
*/
class RecieverGroup extends AbstractMeta implements RecieverGroupInterface
{
use RelationAttribut,RecieverAttribut;
/**
* @ORM\Column(name="reciever", type="RecieverType", nullable=false)
* @DoctrineAssert\Enum(entity="App\DBAL\Types\RecieverType")
*
* @var string
*/
protected $reciever;
/**
* The node for which the right exists.
*
* @ORM\ManyToOne(targetEntity="Relation")
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id")
*
* @var RelationAttributInterface
*/
protected $relation;
public function getAllRecievers(): ArrayCollection
{
switch ($this->reciever) {
case RecieverType::PARENTS:
return $this->node->getParents();
case RecieverType::NODE:
return new ArrayCollection([$this->node]);
case RecieverType::CHILDREN:
return $this->node->getChilds();
}
throw new NotImplementedException('Reciever '.$this->reciever.' not implemented.');
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace App\Entity\Meta;
use App\Entity\Attribut\RecieverAttributInterface;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attribut\RelationAttributInterface;
/**
* @author kevinfrantz
*/
interface RecieverGroupInterface extends RelationAttributInterface, RecieverAttributInterface,MetaInterface
{
public function getAllRecievers(): ArrayCollection;
}

View File

@@ -0,0 +1,81 @@
<?php
namespace App\Entity\Meta;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\IdAttribut;
use App\Entity\Attribut\SourceAttribut;
use App\Entity\Attribut\ParentsAttribut;
use App\Entity\Attribut\ChildsAttribut;
use App\Entity\Attribut\LawAttribut;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Source\SourceInterface;
use Doctrine\Common\Collections\Collection;
/**
* This class represents a relation.
* It allows a better right management of the meta informations.
* Also it is used to capsel the logic relation to an own logical unit.
* @author kevinfrantz
* @todo rename and refactor this class
* @ORM\Table(name="node")
* @ORM\Entity()
*/
class Relation extends AbstractMeta implements RelationInterface
{
use IdAttribut,
SourceAttribut,
ParentsAttribut,
LawAttribut,
ChildsAttribut;
/**
* Parents represent the creators of the relation
* @ORM\ManyToMany(targetEntity="Relation")
* @ORM\JoinTable(name="relation_parents",
* joinColumns={@ORM\JoinColumn(name="relation_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="relation_id", referencedColumnName="id")}
* )
*
* @var Collection|RelationInterface[]
*/
protected $parents;
/**
* Childs represent the by the object produced relations
* @todo Replace this by self referencing
* @see https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/association-mapping.html
* @ORM\ManyToMany(targetEntity="Relation")
* @ORM\JoinTable(name="relation_childs",
* joinColumns={@ORM\JoinColumn(name="relation_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="relation_id", referencedColumnName="id")}
* )
*
* @var Collection|RelationInterface[]
*/
protected $childs;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Source\AbstractSource",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="source_id", referencedColumnName="id")
*
* @var SourceInterface
*/
protected $source;
/**
* @ORM\OneToOne(targetEntity="Law",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="law_id", referencedColumnName="id")
*
* @var LawInterface
*/
protected $law;
public function __construct()
{
$this->law = new Law();
$this->parents = new ArrayCollection();
$this->childs = new ArrayCollection();
$this->law->setNode($this);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Entity\Meta;
use App\Entity\Attribut\SourceAttributInterface;
use App\Entity\Attribut\IdAttributInterface;
use App\Entity\Attribut\ParentsAttributInterface;
use App\Entity\Attribut\ChildsAttributeInterface;
use App\Entity\Attribut\LawAttributInterface;
/**
* @author kevinfrantz
*/
interface RelationInterface extends SourceAttributInterface, IdAttributInterface, ParentsAttributInterface, ChildsAttributeInterface, LawAttributInterface,MetaInterface
{
}

View File

@@ -0,0 +1,112 @@
<?php
namespace App\Entity\Meta;
use App\Entity\Attribut\TypeAttribut;
use Doctrine\ORM\Mapping as ORM;
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
use App\Entity\Attribut\LawAttribut;
use App\DBAL\Types\LayerType;
use App\DBAL\Types\RightType;
use App\Entity\Attribut\GrantAttribut;
use App\Logic\Operation\OperationInterface;
use App\Entity\Attribut\ConditionAttribut;
use App\Entity\Attribut\RecieverGroupAttribut;
use App\Entity\Attribut\LayerAttribut;
use App\Entity\Attribut\RelationAttribut;
/**
* @author kevinfrantz
* @ORM\Table(name="`right`")
* @ORM\Entity(repositoryClass="App\Repository\RightRepository")
*/
class Right extends AbstractMeta implements RightInterface
{
use TypeAttribut,LawAttribut, RelationAttribut, GrantAttribut,ConditionAttribut,RecieverGroupAttribut,LayerAttribut;
/**
* @ORM\ManyToOne(targetEntity="Law", inversedBy="rights")
* @ORM\JoinColumn(name="law_id", referencedColumnName="id")
*
* @var LawInterface
*/
protected $law;
/**
* @ORM\Column(name="layer", type="LayerType", nullable=false)
* @DoctrineAssert\Enum(entity="App\DBAL\Types\LayerType")
*
* @var string
*/
protected $layer;
/**
* @ORM\OneToOne(targetEntity="RecieverGroup",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="reciever_id", referencedColumnName="id")
*
* @var RecieverGroupInterface
*/
protected $recieverGroup;
/**
* @ORM\Column(type="boolean",name="`grant`")
*
* @var bool
*/
protected $grant;
/**
* @ORM\ManyToOne(targetEntity="Relation")
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id")
*
* @var RelationInterface
*/
protected $relation;
/**
* @ORM\Column(name="type", type="RightType", nullable=false)
* @DoctrineAssert\Enum(entity="App\DBAL\Types\RightType")
*
* @var string
*/
protected $type;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Source\Operation\AbstractOperation",cascade={"persist"})
* @ORM\JoinColumn(name="operation_id", referencedColumnName="id",nullable=true)
*
* @var OperationInterface
*/
protected $condition;
public function __construct()
{
parent::__construct();
$this->grant = true;
//$this->node = new Node();
//$this->recieverGroup = new RecieverGroup();
}
public function isGranted(RelationInterface $relation, string $layer, string $right): bool
{
if ($this->layer == $layer && $this->type == $right && $this->checkIfNodeIsReciever($relation) && $this->getConditionBoolOrTrue()) {
return $this->grant;
}
return !($this->grant);
}
private function getConditionBoolOrTrue(): bool
{
if ($this->hasCondition()) {
return $this->condition->getResult()->getBool();
}
return true;
}
private function checkIfNodeIsReciever(RelationInterface $relation): bool
{
return $this->recieverGroup->getAllRecievers()->contains($relation);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Entity\Meta;
use App\Entity\Attribut\TypeAttributInterface;
use App\Entity\Attribut\LawAttributInterface;
use App\Entity\Attribut\RecieverGroupAttributInterface;
use App\Entity\Attribut\GrantAttributInterface;
use App\Entity\Attribut\ConditionAttributInterface;
use App\Entity\Attribut\LayerAttributInterface;
use App\Entity\Method\RelationGrantedInterface;
use App\Entity\Attribut\RelationAttributInterface;
/**
*
* @author kevinfrantz
*/
interface RightInterface extends TypeAttributInterface, LawAttributInterface, RelationGrantedInterface, GrantAttributInterface, RecieverGroupAttributInterface, RelationAttributInterface, ConditionAttributInterface, LayerAttributInterface, MetaInterface
{
}