mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 21:57:16 +02:00
Added logic draft and optimized rights
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user