2018-12-08 12:51:29 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Domain\RightManagement;
|
|
|
|
|
|
|
|
use App\Entity\Meta\RightInterface;
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
|
|
|
use App\Entity\Source\SourceInterface;
|
|
|
|
use App\Domain\SourceManagement\SourceMemberInformation;
|
|
|
|
|
|
|
|
/**
|
2018-12-08 13:22:50 +01:00
|
|
|
* @todo Implement the check of conditions!
|
|
|
|
*
|
2018-12-08 12:51:29 +01:00
|
|
|
* @author kevinfrantz
|
|
|
|
*/
|
|
|
|
final class RightChecker implements RightCheckerInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var RightInterface
|
|
|
|
*/
|
|
|
|
private $right;
|
|
|
|
|
|
|
|
/**
|
2018-12-08 13:22:50 +01:00
|
|
|
* @todo Implement a performant solution
|
|
|
|
*
|
|
|
|
* @return Collection
|
2018-12-08 12:51:29 +01:00
|
|
|
*/
|
2018-12-08 13:22:50 +01:00
|
|
|
private function getAllSourcesToWhichRightApplies(): Collection
|
2018-12-08 12:51:29 +01:00
|
|
|
{
|
2018-12-14 10:10:28 +01:00
|
|
|
$rightSourceMemberInformation = new SourceMemberInformation($this->right->getReciever());
|
2018-12-08 13:22:50 +01:00
|
|
|
$allSourcesToWhichRightApplies = clone $rightSourceMemberInformation->getAllMembers();
|
2018-12-14 10:10:28 +01:00
|
|
|
$allSourcesToWhichRightApplies->add($this->right->getReciever());
|
2018-12-08 13:22:50 +01:00
|
|
|
|
|
|
|
return $allSourcesToWhichRightApplies;
|
2018-12-08 12:51:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function hasSource(SourceInterface $source): bool
|
|
|
|
{
|
2018-12-08 13:22:50 +01:00
|
|
|
return $this->getAllSourcesToWhichRightApplies()->contains($source);
|
2018-12-08 12:51:29 +01:00
|
|
|
}
|
2018-12-08 13:22:50 +01:00
|
|
|
|
|
|
|
private function isLayerEqual(string $layer): bool
|
|
|
|
{
|
|
|
|
return $this->right->getLayer() === $layer;
|
2018-12-08 12:51:29 +01:00
|
|
|
}
|
2018-12-08 13:22:50 +01:00
|
|
|
|
|
|
|
private function isTypeEqual(string $type): bool
|
|
|
|
{
|
|
|
|
return $this->right->getType() === $type;
|
2018-12-08 12:51:29 +01:00
|
|
|
}
|
2018-12-08 13:22:50 +01:00
|
|
|
|
|
|
|
private function checkPermission(): bool
|
|
|
|
{
|
2018-12-08 12:51:29 +01:00
|
|
|
return $this->right->getGrant();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __construct(RightInterface $right)
|
|
|
|
{
|
|
|
|
$this->right = $right;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isGranted(string $layer, string $type, SourceInterface $source): bool
|
|
|
|
{
|
2018-12-08 13:22:50 +01:00
|
|
|
return $this->isLayerEqual($layer) && $this->isTypeEqual($type) && $this->hasSource($source) && $this->checkPermission();
|
2018-12-08 12:51:29 +01:00
|
|
|
}
|
|
|
|
}
|