mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 01:09:41 +00:00 
			
		
		
		
	Implemented new law draft
This commit is contained in:
		| @@ -12,12 +12,12 @@ final class LayerType extends AbstractEnumType | ||||
|     public const NODE = 'node'; | ||||
|  | ||||
|     public const SOURCE = 'source'; | ||||
|      | ||||
|  | ||||
|     public const LAW = 'law'; | ||||
|  | ||||
|     protected static $choices = [ | ||||
|         self::NODE => 'node', | ||||
|         self::LAW =>'law', | ||||
|         self::LAW => 'law', | ||||
|         self::SOURCE => 'source', | ||||
|     ]; | ||||
| } | ||||
|   | ||||
| @@ -15,9 +15,12 @@ final class RecieverType extends AbstractEnumType | ||||
|  | ||||
|     public const CHILDREN = 'children'; | ||||
|  | ||||
|     public const SIBLINGS = 'siblings'; | ||||
|  | ||||
|     protected static $choices = [ | ||||
|         self::NODE => 'node', | ||||
|         self::PARENTS => 'parents', | ||||
|         self::CHILDREN => 'children', | ||||
|         self::SIBLINGS => 'siblings', | ||||
|     ]; | ||||
| } | ||||
|   | ||||
| @@ -1,38 +1,42 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity; | ||||
|  | ||||
| use App\Logic\Result\ResultInterface; | ||||
| use App\Logic\Operation\OperationInterface; | ||||
| use App\Logic\Operation\OperandInterface; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  *         | ||||
|  * @ORM\Entity | ||||
|  * @ORM\Table(name="source_operation") | ||||
|  * @ORM\InheritanceType("JOINED") | ||||
|  * @ORM\DiscriminatorColumn(name="discr", type="string") | ||||
|  * @ORM\DiscriminatorMap({"and" = "AndOperation"}) | ||||
|  */ | ||||
| abstract class AbstractOperation extends AbstractSource implements OperationInterface | ||||
| { | ||||
|      | ||||
|     /** | ||||
|      * The result MUST NOT be saved via Doctrine! | ||||
|      * | ||||
|      * @var ResultInterface | ||||
|      */ | ||||
|     protected $result; | ||||
|      | ||||
|  | ||||
|     /** | ||||
|      * @var ArrayCollection|OperandInterface[] | ||||
|      */ | ||||
|     protected $operands; | ||||
|      | ||||
|  | ||||
|     public function getResult(): ResultInterface | ||||
|     { | ||||
|         return $this->result; | ||||
|     } | ||||
|      | ||||
|  | ||||
|     public function setOperators(ArrayCollection $operands): void | ||||
|     { | ||||
|         $this->operands = $operands; | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -11,6 +11,7 @@ use JMS\Serializer\Annotation\Exclude; | ||||
|  * | ||||
|  * @see https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/inheritance-mapping.html | ||||
|  * @ORM\Entity | ||||
|  * @ORM\Table(name="source") | ||||
|  * @ORM\InheritanceType("JOINED") | ||||
|  * @ORM\DiscriminatorColumn(name="discr", type="string") | ||||
|  * @ORM\DiscriminatorMap({"user" = "UserSource","name" = "NameSource"}) | ||||
|   | ||||
| @@ -1,32 +1,34 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity; | ||||
|  | ||||
| use App\Logic\Operation\OperandInterface; | ||||
| use App\Logic\Result\Result; | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  *         | ||||
|  * @ORM\Table(name="source_operation_user") | ||||
|  * @ORM\Entity() | ||||
|  */ | ||||
| class AndOperation extends AbstractOperation | ||||
| { | ||||
|     public function process(): void | ||||
|     { | ||||
|         if($this->operands->isEmpty()){ | ||||
|             throw new \Exception("Operands must be defined!"); | ||||
|         if ($this->operands->isEmpty()) { | ||||
|             throw new \Exception('Operands must be defined!'); | ||||
|         } | ||||
|         $this->result = new Result(); | ||||
|         /** | ||||
|          * @var OperandInterface $operand | ||||
|          * @var OperandInterface | ||||
|          */ | ||||
|         foreach ($this->operands->toArray() as $operand){ | ||||
|             if(!$operand->getResult()->getBool()){ | ||||
|         foreach ($this->operands->toArray() as $operand) { | ||||
|             if (!$operand->getResult()->getBool()) { | ||||
|                 $this->result->setAll(false); | ||||
|  | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
|         $this->result->setAll(true); | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										31
									
								
								application/src/Entity/Attribut/ConditionAttribut.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								application/src/Entity/Attribut/ConditionAttribut.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Attribut; | ||||
|  | ||||
| use App\Logic\Operation\OperationInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| trait ConditionAttribut | ||||
| { | ||||
|     /** | ||||
|      * @var OperationInterface | ||||
|      */ | ||||
|     protected $condition; | ||||
|  | ||||
|     public function getCondition(): OperationInterface | ||||
|     { | ||||
|         return $this->condition; | ||||
|     } | ||||
|  | ||||
|     public function setCondition(OperationInterface $condition): void | ||||
|     { | ||||
|         $this->condition = $condition; | ||||
|     } | ||||
|  | ||||
|     public function hasCondition(): bool | ||||
|     { | ||||
|         return $this->condition; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,17 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Attribut; | ||||
|  | ||||
| use App\Logic\Operation\OperationInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface ConditionAttributInterface | ||||
| { | ||||
|     public function getCondition(): OperationInterface; | ||||
|  | ||||
|     public function setCondition(OperationInterface $operation): void; | ||||
|  | ||||
|     public function hasCondition(): bool; | ||||
| } | ||||
							
								
								
									
										24
									
								
								application/src/Entity/Attribut/LayerAttribut.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								application/src/Entity/Attribut/LayerAttribut.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Attribut; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| trait LayerAttribut | ||||
| { | ||||
|     /** | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $layer; | ||||
|  | ||||
|     public function setLayer(string $layer): void | ||||
|     { | ||||
|         $this->layer = $layer; | ||||
|     } | ||||
|  | ||||
|     public function getLayer(): string | ||||
|     { | ||||
|         return $this->layer; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										13
									
								
								application/src/Entity/Attribut/LayerAttributInterface.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								application/src/Entity/Attribut/LayerAttributInterface.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Attribut; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface LayerAttributInterface | ||||
| { | ||||
|     public function setLayer(string $layer): void; | ||||
|  | ||||
|     public function getLayer(): string; | ||||
| } | ||||
							
								
								
									
										26
									
								
								application/src/Entity/Attribut/RecieverGroupAttribut.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								application/src/Entity/Attribut/RecieverGroupAttribut.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Attribut; | ||||
|  | ||||
| use App\Entity\RecieverGroupInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| trait RecieverGroupAttribut | ||||
| { | ||||
|     /** | ||||
|      * @var RecieverGroupInterface | ||||
|      */ | ||||
|     protected $recieverGroup; | ||||
|  | ||||
|     public function setRecieverGroup(RecieverGroupInterface $recieverGroup): void | ||||
|     { | ||||
|         $this->recieverGroup = $recieverGroup; | ||||
|     } | ||||
|  | ||||
|     public function getRecieverGroup(): RecieverGroupInterface | ||||
|     { | ||||
|         return $this->recieverGroup; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Attribut; | ||||
|  | ||||
| use App\Entity\RecieverGroupInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface RecieverGroupAttributInterface | ||||
| { | ||||
|     public function setRecieverGroup(RecieverGroupInterface $recieverGroup): void; | ||||
|  | ||||
|     public function getRecieverGroup(): RecieverGroupInterface; | ||||
| } | ||||
| @@ -7,6 +7,7 @@ use App\Entity\Attribut\RightsAttribute; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use App\DBAL\Types\RightType; | ||||
| use App\Entity\Attribut\NodeAttribut; | ||||
| use App\DBAL\Types\LayerType; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
| @@ -20,7 +21,7 @@ class Law extends AbstractEntity implements LawInterface | ||||
|     /** | ||||
|      * @ORM\OneToMany(targetEntity="Right", mappedBy="law", cascade={"persist", "remove"}) | ||||
|      * | ||||
|      * @var ArrayCollection | ||||
|      * @var ArrayCollection | Right[] | ||||
|      */ | ||||
|     protected $rights; | ||||
|  | ||||
| @@ -40,11 +41,28 @@ class Law extends AbstractEntity implements LawInterface | ||||
|     private function initAllRights(): void | ||||
|     { | ||||
|         $this->rights = new ArrayCollection(); | ||||
|         foreach (RightType::getChoices() as $key => $value) { | ||||
|             $right = new Right(); | ||||
|             $right->setType($value); | ||||
|             $right->setLaw($this); | ||||
|             $this->rights->set($key, $right); | ||||
|         foreach (LayerType::getChoices() as $layerKey => $layerValue) { | ||||
|             foreach (RightType::getChoices() as $rightKey => $rightValue) { | ||||
|                 $right = new Right(); | ||||
|                 $right->setType($rightKey); | ||||
|                 $right->setLaw($this); | ||||
|                 $right->setLayer($layerKey); | ||||
|                 $this->rights->add($right); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public function isGranted(NodeInterface $node, string $layer, string $right): bool | ||||
|     { | ||||
|         /** | ||||
|          * @var RightInterface | ||||
|          */ | ||||
|         foreach ($this->rights->toArray() as $right) { | ||||
|             if ($right->isGranted($node, $layer, $right)) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -3,10 +3,11 @@ | ||||
| namespace App\Entity; | ||||
|  | ||||
| use App\Entity\Attribut\RightsAttributInterface; | ||||
| use App\Entity\Method\NodeGrantedInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface LawInterface extends RightsAttributInterface | ||||
| interface LawInterface extends RightsAttributInterface, NodeGrantedInterface | ||||
| { | ||||
| } | ||||
|   | ||||
							
								
								
									
										13
									
								
								application/src/Entity/Method/NodeGrantedInterface.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								application/src/Entity/Method/NodeGrantedInterface.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Method; | ||||
|  | ||||
| use App\Entity\NodeInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface NodeGrantedInterface | ||||
| { | ||||
|     public function isGranted(NodeInterface $node, string $layer, string $right): bool; | ||||
| } | ||||
| @@ -1,58 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity; | ||||
|  | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
| use App\Entity\Attribut\NodeAttribut; | ||||
| use App\Entity\Attribut\RightAttribut; | ||||
| use App\Entity\Attribut\RecieverAttribut; | ||||
| use App\DBAL\Types\RecieverType; | ||||
| use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert; | ||||
| use App\Entity\Attribut\GrantAttribut; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  * @ORM\Table(name="permission") | ||||
|  * @ORM\Entity(repositoryClass="App\Repository\PermissionRepository") | ||||
|  */ | ||||
| class Permission extends AbstractEntity implements PermissionInterface | ||||
| { | ||||
|     use NodeAttribut,RightAttribut,RecieverAttribut,GrantAttribut; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(name="reciever", type="RecieverType", nullable=false) | ||||
|      * @DoctrineAssert\Enum(entity="App\DBAL\Types\RecieverType") | ||||
|      * | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $reciever; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="boolean",name="`grant`") | ||||
|      * | ||||
|      * @var bool | ||||
|      */ | ||||
|     protected $grant; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\ManyToOne(targetEntity="Node") | ||||
|      * @ORM\JoinColumn(name="node_id", referencedColumnName="id") | ||||
|      * | ||||
|      * @var NodeInterface | ||||
|      */ | ||||
|     protected $node; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\ManyToOne(targetEntity="Right",inversedBy="permissions") | ||||
|      * @ORM\JoinColumn(name="right_id", referencedColumnName="id") | ||||
|      * | ||||
|      * @var RightInterface | ||||
|      */ | ||||
|     protected $right; | ||||
|  | ||||
|     public function __construct() | ||||
|     { | ||||
|         $this->reciever = RecieverType::NODE; | ||||
|         $this->grant = true; | ||||
|     } | ||||
| } | ||||
| @@ -1,15 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity; | ||||
|  | ||||
| use App\Entity\Attribut\NodeAttributInterface; | ||||
| use App\Entity\Attribut\RightAttributInterface; | ||||
| use App\Entity\Attribut\RecieverAttributInterface; | ||||
| use App\Entity\Attribut\GrantAttributInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface PermissionInterface extends NodeAttributInterface, RightAttributInterface, RecieverAttributInterface, GrantAttributInterface | ||||
| { | ||||
| } | ||||
							
								
								
									
										48
									
								
								application/src/Entity/RecieverGroup.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								application/src/Entity/RecieverGroup.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity; | ||||
|  | ||||
| use App\Entity\Attribut\NodeAttribut; | ||||
| use App\Entity\Attribut\RecieverAttribut; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use App\DBAL\Types\RecieverType; | ||||
| use Symfony\Component\Intl\Exception\NotImplementedException; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| class RecieverGroup extends AbstractEntity implements RecieverGroupInterface | ||||
| { | ||||
|     use NodeAttribut,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="Node") | ||||
|      * @ORM\JoinColumn(name="node_id", referencedColumnName="id") | ||||
|      * | ||||
|      * @var NodeInterface | ||||
|      */ | ||||
|     protected $node; | ||||
|  | ||||
|     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.'); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										15
									
								
								application/src/Entity/RecieverGroupInterface.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								application/src/Entity/RecieverGroupInterface.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity; | ||||
|  | ||||
| use App\Entity\Attribut\NodeAttributInterface; | ||||
| use App\Entity\Attribut\RecieverAttributInterface; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface RecieverGroupInterface extends NodeAttributInterface, RecieverAttributInterface | ||||
| { | ||||
|     public function getAllRecievers(): ArrayCollection; | ||||
| } | ||||
| @@ -2,14 +2,20 @@ | ||||
|  | ||||
| namespace App\Entity; | ||||
|  | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use App\Entity\Attribut\TypeAttribut; | ||||
| use App\DBAL\Types\RightType; | ||||
| 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\PermissionsAttribut; | ||||
| use Doctrine\Common\Collections\Collection; | ||||
| use App\Entity\Attribut\NodeAttribut; | ||||
| use App\Entity\Attribut\RecieverAttribut; | ||||
| 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; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
| @@ -18,7 +24,7 @@ use Doctrine\Common\Collections\Collection; | ||||
|  */ | ||||
| class Right extends AbstractEntity implements RightInterface | ||||
| { | ||||
|     use TypeAttribut,LawAttribut,PermissionsAttribut; | ||||
|     use TypeAttribut,LawAttribut,PermissionsAttribut, NodeAttribut, RecieverAttribut,GrantAttribut,ConditionAttribut,RecieverGroupAttribut,LayerAttribut; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\ManyToOne(targetEntity="Law", inversedBy="rights") | ||||
| @@ -28,6 +34,37 @@ class Right extends AbstractEntity implements RightInterface | ||||
|      */ | ||||
|     protected $law; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(name="type", 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="Node") | ||||
|      * @ORM\JoinColumn(name="node_id", referencedColumnName="id") | ||||
|      * | ||||
|      * @var NodeInterface | ||||
|      */ | ||||
|     protected $node; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(name="type", type="RightType", nullable=false) | ||||
|      * @DoctrineAssert\Enum(entity="App\DBAL\Types\RightType") | ||||
| @@ -37,19 +74,38 @@ class Right extends AbstractEntity implements RightInterface | ||||
|     protected $type; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\OneToMany(targetEntity="Permission", mappedBy="right", cascade={"persist", "remove"}) | ||||
|      * @ORM\OneToOne(targetEntity="AbstractOperation",cascade={"persist"},nullable=true) | ||||
|      * | ||||
|      * @var Collection | ||||
|      * @var OperationInterface | ||||
|      */ | ||||
|     protected $permissions; | ||||
|  | ||||
|     public function isGranted(NodeInterface $node): bool | ||||
|     { | ||||
|     } | ||||
|     protected $condition; | ||||
|  | ||||
|     public function __construct() | ||||
|     { | ||||
|         parent::__construct(); | ||||
|         $this->permissions = new ArrayCollection(); | ||||
|         $this->grant = true; | ||||
|     } | ||||
|  | ||||
|     public function isGranted(NodeInterface $node, string $layer, string $right): bool | ||||
|     { | ||||
|         if ($this->layer == $layer && $this->type == $right && $this->checkIfNodeIsReciever($node) && $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(NodeInterface $node): bool | ||||
|     { | ||||
|         return $this->recieverGroup->getAllRecievers()->contains($node); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -4,12 +4,16 @@ namespace App\Entity; | ||||
|  | ||||
| use App\Entity\Attribut\TypeAttributInterface; | ||||
| use App\Entity\Attribut\LawAttributInterface; | ||||
| use App\Entity\Attribut\PermissionsAttributInterface; | ||||
| use App\Entity\Method\NodeGrantedInterface; | ||||
| use App\Entity\Attribut\RecieverGroupAttributInterface; | ||||
| use App\Entity\Attribut\GrantAttributInterface; | ||||
| use App\Entity\Attribut\NodeAttributInterface; | ||||
| use App\Entity\Attribut\ConditionAttributInterface; | ||||
| use App\Entity\Attribut\LayerAttributInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface RightInterface extends TypeAttributInterface, LawAttributInterface, PermissionsAttributInterface | ||||
| interface RightInterface extends TypeAttributInterface, LawAttributInterface, NodeGrantedInterface, GrantAttributInterface, RecieverGroupAttributInterface, NodeAttributInterface, ConditionAttributInterface, LayerAttributInterface | ||||
| { | ||||
|     public function isGranted(NodeInterface $node): bool; | ||||
| } | ||||
|   | ||||
| @@ -1,19 +1,18 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Logic\Operation; | ||||
|  | ||||
| use App\Logic\Result\ResultInterface; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  *         | ||||
|  */ | ||||
| interface OperandInterface | ||||
| { | ||||
|     /** | ||||
|      * Returns the result of the Operation | ||||
|      * Returns the result of the Operation. | ||||
|      * | ||||
|      * @return ResultInterface | ||||
|      */ | ||||
|     public function getResult():ResultInterface; | ||||
|     public function getResult(): ResultInterface; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,26 +1,23 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Logic\Operation; | ||||
|  | ||||
| use App\Logic\Result\ResultInterface; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  *         | ||||
|  */ | ||||
| interface OperationInterface extends OperandInterface | ||||
| { | ||||
|     /** | ||||
|      * Sets the Operators the operation has to deal with | ||||
|      * Sets the Operators the operation has to deal with. | ||||
|      * | ||||
|      * @param ArrayCollection $operands | OperandInterface[] | ||||
|      */ | ||||
|     public function setOperators(ArrayCollection $operands):void; | ||||
|      | ||||
|     /** | ||||
|      * Process the logic | ||||
|      */ | ||||
|     public function process():void; | ||||
| } | ||||
|     public function setOperators(ArrayCollection $operands): void; | ||||
|  | ||||
|     /** | ||||
|      * Process the logic. | ||||
|      */ | ||||
|     public function process(): void; | ||||
| } | ||||
|   | ||||
| @@ -1,10 +1,9 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Logic\Result; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  *         | ||||
|  */ | ||||
| class Result implements ResultInterface | ||||
| { | ||||
| @@ -12,9 +11,10 @@ class Result implements ResultInterface | ||||
|      * @var bool | ||||
|      */ | ||||
|     protected $bool; | ||||
|      | ||||
|  | ||||
|     /** | ||||
|      * The concrete result value | ||||
|      * The concrete result value. | ||||
|      * | ||||
|      * @var mixed | ||||
|      */ | ||||
|     protected $value; | ||||
| @@ -28,7 +28,7 @@ class Result implements ResultInterface | ||||
|     { | ||||
|         return $this->bool; | ||||
|     } | ||||
|      | ||||
|  | ||||
|     public function setBool(bool $bool): void | ||||
|     { | ||||
|         $this->bool = $bool; | ||||
| @@ -38,12 +38,10 @@ class Result implements ResultInterface | ||||
|     { | ||||
|         $this->value = $value; | ||||
|     } | ||||
|      | ||||
|  | ||||
|     public function setAll($value): void | ||||
|     { | ||||
|         $this->bool = (bool)$value; | ||||
|         $this->bool = (bool) $value; | ||||
|         $this->value = $value; | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,39 +1,41 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Logic\Result; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  *         | ||||
|  */ | ||||
| interface ResultInterface  | ||||
| interface ResultInterface | ||||
| { | ||||
|     /** | ||||
|      * Returns the Result as a string | ||||
|      * Returns the Result as a string. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     //public function __toString():string; | ||||
|      | ||||
|  | ||||
|     /** | ||||
|      * Returns if the result is true | ||||
|      * Returns if the result is true. | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function getBool():bool; | ||||
|      | ||||
|     public function setBool(bool $bool):void; | ||||
|      | ||||
|     public function getBool(): bool; | ||||
|  | ||||
|     public function setBool(bool $bool): void; | ||||
|  | ||||
|     /** | ||||
|      * Returns the concrete result value | ||||
|      * Returns the concrete result value. | ||||
|      * | ||||
|      * @var mixed | ||||
|      */ | ||||
|     public function getValue(); | ||||
|      | ||||
|     public function setValue($value):void; | ||||
|      | ||||
|  | ||||
|     public function setValue($value): void; | ||||
|  | ||||
|     /** | ||||
|      * Sets bool and value attribut | ||||
|      * Sets bool and value attribut. | ||||
|      * | ||||
|      * @param mixed $value | ||||
|      */ | ||||
|     public function setAll($value):void; | ||||
|     public function setAll($value): void; | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user