mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +01:00
Added logic draft and optimized rights
This commit is contained in:
parent
fb6cf53785
commit
a4fdb07cb6
23
application/src/DBAL/Types/LayerType.php
Normal file
23
application/src/DBAL/Types/LayerType.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DBAL\Types;
|
||||||
|
|
||||||
|
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kevinfrantz
|
||||||
|
*/
|
||||||
|
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::SOURCE => 'source',
|
||||||
|
];
|
||||||
|
}
|
@ -9,14 +9,11 @@ use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
|
|||||||
*/
|
*/
|
||||||
final class RightType extends AbstractEnumType
|
final class RightType extends AbstractEnumType
|
||||||
{
|
{
|
||||||
public const ADMINISTRATION = 'administration';
|
|
||||||
|
|
||||||
public const READ = 'read';
|
public const READ = 'read';
|
||||||
|
|
||||||
public const WRITE = 'write';
|
public const WRITE = 'write';
|
||||||
|
|
||||||
protected static $choices = [
|
protected static $choices = [
|
||||||
self::ADMINISTRATION => 'administration',
|
|
||||||
self::READ => 'read',
|
self::READ => 'read',
|
||||||
self::WRITE => 'write',
|
self::WRITE => 'write',
|
||||||
];
|
];
|
||||||
|
38
application/src/Entity/AbstractOperation.php
Normal file
38
application/src/Entity/AbstractOperation.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Logic\Result\ResultInterface;
|
||||||
|
use App\Logic\Operation\OperationInterface;
|
||||||
|
use App\Logic\Operation\OperandInterface;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
32
application/src/Entity/AndOperation.php
Normal file
32
application/src/Entity/AndOperation.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Logic\Operation\OperandInterface;
|
||||||
|
use App\Logic\Result\Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class AndOperation extends AbstractOperation
|
||||||
|
{
|
||||||
|
public function process(): void
|
||||||
|
{
|
||||||
|
if($this->operands->isEmpty()){
|
||||||
|
throw new \Exception("Operands must be defined!");
|
||||||
|
}
|
||||||
|
$this->result = new Result();
|
||||||
|
/**
|
||||||
|
* @var OperandInterface $operand
|
||||||
|
*/
|
||||||
|
foreach ($this->operands->toArray() as $operand){
|
||||||
|
if(!$operand->getResult()->getBool()){
|
||||||
|
$this->result->setAll(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->result->setAll(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
19
application/src/Logic/Operation/OperandInterface.php
Normal file
19
application/src/Logic/Operation/OperandInterface.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Logic\Operation;
|
||||||
|
|
||||||
|
use App\Logic\Result\ResultInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
interface OperandInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns the result of the Operation
|
||||||
|
* @return ResultInterface
|
||||||
|
*/
|
||||||
|
public function getResult():ResultInterface;
|
||||||
|
}
|
||||||
|
|
26
application/src/Logic/Operation/OperationInterface.php
Normal file
26
application/src/Logic/Operation/OperationInterface.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?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
|
||||||
|
* @param ArrayCollection $operands | OperandInterface[]
|
||||||
|
*/
|
||||||
|
public function setOperators(ArrayCollection $operands):void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the logic
|
||||||
|
*/
|
||||||
|
public function process():void;
|
||||||
|
}
|
||||||
|
|
49
application/src/Logic/Result/Result.php
Normal file
49
application/src/Logic/Result/Result.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Logic\Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Result implements ResultInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The concrete result value
|
||||||
|
* @var mixed
|
||||||
|
*/
|
||||||
|
protected $value;
|
||||||
|
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBool(): bool
|
||||||
|
{
|
||||||
|
return $this->bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBool(bool $bool): void
|
||||||
|
{
|
||||||
|
$this->bool = $bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue($value): void
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAll($value): void
|
||||||
|
{
|
||||||
|
$this->bool = (bool)$value;
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
39
application/src/Logic/Result/ResultInterface.php
Normal file
39
application/src/Logic/Result/ResultInterface.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Logic\Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
interface ResultInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns the Result as a string
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
//public function __toString():string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if the result is true
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getBool():bool;
|
||||||
|
|
||||||
|
public function setBool(bool $bool):void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the concrete result value
|
||||||
|
* @var mixed
|
||||||
|
*/
|
||||||
|
public function getValue();
|
||||||
|
|
||||||
|
public function setValue($value):void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets bool and value attribut
|
||||||
|
* @param mixed $value
|
||||||
|
*/
|
||||||
|
public function setAll($value):void;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user