mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Optimized for SPA
This commit is contained in:
12
application/symfony/src/Domain/AbstractDomainService.php
Normal file
12
application/symfony/src/Domain/AbstractDomainService.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain;
|
||||
|
||||
/**
|
||||
* @deprecated Doesn't make sense!
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
abstract class AbstractDomainService
|
||||
{
|
||||
}
|
63
application/symfony/src/Domain/FormManagement/FormMeta.php
Normal file
63
application/symfony/src/Domain/FormManagement/FormMeta.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\FormManagement;
|
||||
|
||||
use App\Domain\SourceManagement\SourceMetaInterface;
|
||||
use App\Domain\TemplateManagement\TemplateMetaInterface;
|
||||
use App\Domain\TemplateManagement\TemplateMeta;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Optimize contructor parameter!
|
||||
*/
|
||||
class FormMeta implements FormMetaInterface
|
||||
{
|
||||
const FOLDER = 'form';
|
||||
|
||||
/**
|
||||
* @var SourceMetaInterface
|
||||
*/
|
||||
private $sourceMeta;
|
||||
|
||||
/**
|
||||
* @var TemplateMetaInterface
|
||||
*/
|
||||
private $templateMeta;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $formClass;
|
||||
|
||||
public function __construct(SourceMetaInterface $sourceMeta)
|
||||
{
|
||||
$this->sourceMeta = $sourceMeta;
|
||||
$this->setMeta();
|
||||
$this->setFormClass();
|
||||
}
|
||||
|
||||
private function setFormClass(): void
|
||||
{
|
||||
$this->formClass = 'App\\Form';
|
||||
foreach ($this->sourceMeta->getBasicPathArray() as $element) {
|
||||
$this->formClass .= '\\'.ucfirst($element);
|
||||
}
|
||||
$this->formClass .= '\\'.ucfirst($this->sourceMeta->getBasicName()).'Type';
|
||||
}
|
||||
|
||||
private function setMeta(): void
|
||||
{
|
||||
$this->templateMeta = new TemplateMeta($this->sourceMeta->getBasicPathArray(), $this->sourceMeta->getBasicName(), self::FOLDER);
|
||||
}
|
||||
|
||||
public function getFormClass(): string
|
||||
{
|
||||
return $this->formClass;
|
||||
}
|
||||
|
||||
public function getTemplateMeta(): TemplateMetaInterface
|
||||
{
|
||||
return $this->templateMeta;
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\FormManagement;
|
||||
|
||||
use App\Domain\TemplateManagement\TemplateMetaInterface;
|
||||
|
||||
interface FormMetaInterface
|
||||
{
|
||||
public function getFormClass(): string;
|
||||
|
||||
public function getTemplateMeta(): TemplateMetaInterface;
|
||||
}
|
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\LawManagement;
|
||||
|
||||
use PhpCollection\CollectionInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Meta\LawInterface;
|
||||
use App\Domain\RightManagement\RightChecker;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Domain\SourceManagement\SourceMemberInformation;
|
||||
|
||||
/**
|
||||
* @todo Implement checking by operation sources
|
||||
* @todo chek if recievers are still neccessary and if they should be implemented
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class LawPermissionCheckerService implements LawPermissionCheckerServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var LawInterface
|
||||
*/
|
||||
private $law;
|
||||
|
||||
/**
|
||||
* @param Collection|RightInterface[] $rights
|
||||
* @param string $value
|
||||
* @param string $attribut
|
||||
*
|
||||
* @return Collection|RightInterface[]
|
||||
*/
|
||||
private function getFilteredRights(Collection $rights, string $value, string $attribut): Collection
|
||||
{
|
||||
$result = new ArrayCollection();
|
||||
foreach ($rights as $right) {
|
||||
if ($right->{'get'.$attribut}() === $value) {
|
||||
$result->add($right);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection|RightInterface[] $rights
|
||||
* @param string $type
|
||||
*
|
||||
* @return Collection|RightInterface[]
|
||||
*/
|
||||
private function getRightsByType(Collection $rights, string $type): Collection
|
||||
{
|
||||
return $this->getFilteredRights($rights, $type, 'Type');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection|RightInterface[] $rights
|
||||
* @param SourceInterface $reciever
|
||||
*
|
||||
* @return Collection|RightInterface[]
|
||||
*/
|
||||
private function getRightsByReciever(Collection $rights, SourceInterface $reciever): Collection
|
||||
{
|
||||
$result = new ArrayCollection();
|
||||
foreach ($rights as $right) {
|
||||
if ($right->getReciever() === $reciever || $this->memberExist($right, $reciever)) {
|
||||
$result->add($right);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implement!
|
||||
*
|
||||
* @param RightInterface $right
|
||||
* @param SourceInterface $recieverSource
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function memberExist(RightInterface $right, SourceInterface $recieverSource): bool
|
||||
{
|
||||
$rightMemberInformation = new SourceMemberInformation($right->getReciever());
|
||||
$rightMemberSources = $rightMemberInformation->getAllMembers();
|
||||
foreach ($rightMemberSources as $memberSource) {
|
||||
if ($memberSource === $recieverSource) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection|RightInterface[] $rights
|
||||
* @param string $layer
|
||||
*
|
||||
* @return Collection|RightInterface[]
|
||||
*/
|
||||
private function getRightsByLayer(Collection $rights, string $layer): Collection
|
||||
{
|
||||
return $this->getFilteredRights($rights, $layer, 'Layer');
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo seems like this can be solved on a nicer way
|
||||
*
|
||||
* @param Collection|RightInterface[] $rights
|
||||
*
|
||||
* @return Collection|RightInterface[]
|
||||
*/
|
||||
private function sortByPriority(Collection $rights): Collection
|
||||
{
|
||||
$iterator = $rights->getIterator();
|
||||
$iterator->uasort(function ($first, $second) {
|
||||
return (int) $first->getPriority() > (int) $second->getPriority() ? 1 : -1;
|
||||
});
|
||||
$sorted = new ArrayCollection();
|
||||
foreach ($iterator as $right) {
|
||||
$sorted->add($right);
|
||||
}
|
||||
|
||||
return $sorted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CollectionInterface|RightInterface[] $rights
|
||||
* the rights which exist
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isGranted(Collection $rights, RightInterface $client): bool
|
||||
{
|
||||
if (0 === $rights->count()) {
|
||||
return $this->law->getGrant();
|
||||
}
|
||||
$right = $rights[0];
|
||||
$rightChecker = new RightChecker($right);
|
||||
|
||||
return $rightChecker->isGranted($client->getLayer(), $client->getType(), $client->getReciever());
|
||||
}
|
||||
|
||||
public function __construct(LawInterface $law)
|
||||
{
|
||||
$this->law = $law;
|
||||
}
|
||||
|
||||
public function hasPermission(RightInterface $clientRight): bool
|
||||
{
|
||||
$rights = clone $this->law->getRights();
|
||||
$rights = $this->getRightsByType($rights, $clientRight->getType());
|
||||
$rights = $this->getRightsByLayer($rights, $clientRight->getLayer());
|
||||
$rights = $this->getRightsByReciever($rights, $clientRight->getReciever());
|
||||
$rights = $this->sortByPriority($rights);
|
||||
|
||||
return $this->isGranted($rights, $clientRight);
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\LawManagement;
|
||||
|
||||
use App\Entity\Meta\RightInterface;
|
||||
|
||||
/**
|
||||
* Allows to check if a source has rights on a source.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface LawPermissionCheckerServiceInterface
|
||||
{
|
||||
/**
|
||||
* Checks if the client has the right for executing.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPermission(RightInterface $clientRight): bool;
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\MemberManagement;
|
||||
|
||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
|
||||
|
||||
final class MemberManager implements MemberManagerInterface
|
||||
{
|
||||
/**
|
||||
* @var MemberRelationInterface
|
||||
*/
|
||||
private $memberRelation;
|
||||
|
||||
public function __construct(MemberRelationInterface $memberRelation)
|
||||
{
|
||||
$this->memberRelation = $memberRelation;
|
||||
}
|
||||
|
||||
public function addMember(MemberRelationInterface $member): void
|
||||
{
|
||||
if (!$this->memberRelation->getMembers()->contains($member)) {
|
||||
$this->memberRelation->getMembers()[] = $member;
|
||||
(new self($member))->addMembership($this->memberRelation);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeMember(MemberRelationInterface $member): void
|
||||
{
|
||||
if ($this->memberRelation->getMembers()->contains($member)) {
|
||||
$this->memberRelation->getMembers()->removeElement($member);
|
||||
(new self($member))->removeMembership($this->memberRelation);
|
||||
}
|
||||
}
|
||||
|
||||
public function addMembership(MemberRelationInterface $membership): void
|
||||
{
|
||||
if (!$this->memberRelation->getMemberships()->contains($membership)) {
|
||||
$this->memberRelation->getMemberships()[] = $membership;
|
||||
(new self($membership))->addMember($this->memberRelation);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeMembership(MemberRelationInterface $membership): void
|
||||
{
|
||||
if ($this->memberRelation->getMemberships()->contains($membership)) {
|
||||
$this->memberRelation->getMemberships()->removeElement($membership);
|
||||
(new self($membership))->removeMember($this->memberRelation);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\MemberManagement;
|
||||
|
||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
|
||||
|
||||
interface MemberManagerInterface
|
||||
{
|
||||
/**
|
||||
* @param MemberRelationInterface $member
|
||||
*/
|
||||
public function addMember(MemberRelationInterface $member): void;
|
||||
|
||||
/**
|
||||
* @param MemberRelationInterface $member
|
||||
*/
|
||||
public function removeMember(MemberRelationInterface $member): void;
|
||||
|
||||
/**
|
||||
* @param MemberRelationInterface $membership
|
||||
*/
|
||||
public function addMembership(MemberRelationInterface $membership): void;
|
||||
|
||||
/**
|
||||
* @param MemberRelationInterface $membership
|
||||
*/
|
||||
public function removeMembership(MemberRelationInterface $membership): void;
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\ResponseManagement;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Entity\UserInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use App\Domain\UserManagement\UserIdentityManager;
|
||||
use FOS\RestBundle\View\ViewHandlerInterface;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Domain\SecureLoadManagement\SecureSourceLoader;
|
||||
use FOS\RestBundle\View\View;
|
||||
use App\Exception\AllreadyDefinedException;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class SourceRESTResponseManager implements SourceRESTResponseManagerInterface
|
||||
{
|
||||
/**
|
||||
* @var UserInterface
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @var RightInterface
|
||||
*/
|
||||
private $requestedRight;
|
||||
|
||||
/**
|
||||
* @var ViewHandlerInterface
|
||||
*/
|
||||
private $viewHandler;
|
||||
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
private $loadedSource;
|
||||
|
||||
/**
|
||||
* @var View
|
||||
*/
|
||||
private $view;
|
||||
|
||||
/**
|
||||
* @param UserInterface $user
|
||||
* @param EntityManagerInterface $entityManager
|
||||
* @param RightInterface $requestedRight
|
||||
* @param ViewHandlerInterface $viewHandler
|
||||
*/
|
||||
public function __construct(?UserInterface $user, EntityManagerInterface $entityManager, RightInterface $requestedRight, ViewHandlerInterface $viewHandler)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->viewHandler = $viewHandler;
|
||||
$this->setUser($user);
|
||||
$this->setRequestedRight($requestedRight);
|
||||
$this->setLoadedSource();
|
||||
$this->setView();
|
||||
}
|
||||
|
||||
protected function setView(): void
|
||||
{
|
||||
$this->view = new View($this->loadedSource, 200);
|
||||
}
|
||||
|
||||
private function setLoadedSource(): void
|
||||
{
|
||||
$secureSourceLoader = new SecureSourceLoader($this->entityManager, $this->requestedRight);
|
||||
$this->loadedSource = $secureSourceLoader->getSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserInterface $user
|
||||
*/
|
||||
private function setUser(?UserInterface $user): void
|
||||
{
|
||||
$userIdentityManager = new UserIdentityManager($this->entityManager, $user);
|
||||
$this->user = $userIdentityManager->getUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RightInterface $requestedRight
|
||||
*
|
||||
* @throws AllreadyDefinedException
|
||||
*/
|
||||
private function setRequestedRight(RightInterface $requestedRight): void
|
||||
{
|
||||
try {
|
||||
$requestedRight->getReciever();
|
||||
throw new AllreadyDefinedException('The reciever is allready defined.');
|
||||
} catch (\TypeError $error) {
|
||||
$requestedRight->setReciever($this->user->getSource());
|
||||
$this->requestedRight = $requestedRight;
|
||||
}
|
||||
}
|
||||
|
||||
public function getResponse(): Response
|
||||
{
|
||||
return $this->viewHandler->handle($this->view);
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\ResponseManagement;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
interface SourceRESTResponseManagerInterface
|
||||
{
|
||||
/**
|
||||
* @return Response
|
||||
*/
|
||||
public function getResponse(): Response;
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* @todo Implement the check of conditions!
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class RightChecker implements RightCheckerInterface
|
||||
{
|
||||
/**
|
||||
* @var RightInterface
|
||||
*/
|
||||
private $right;
|
||||
|
||||
/**
|
||||
* @todo Implement a performant solution
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function getAllSourcesToWhichRightApplies(): Collection
|
||||
{
|
||||
$rightSourceMemberInformation = new SourceMemberInformation($this->right->getReciever());
|
||||
$allSourcesToWhichRightApplies = clone $rightSourceMemberInformation->getAllMembers();
|
||||
$allSourcesToWhichRightApplies->add($this->right->getReciever());
|
||||
|
||||
return $allSourcesToWhichRightApplies;
|
||||
}
|
||||
|
||||
private function hasClientSource(SourceInterface $clientSource): bool
|
||||
{
|
||||
return $this->getAllSourcesToWhichRightApplies()->contains($clientSource);
|
||||
}
|
||||
|
||||
private function isLayerEqual(string $layer): bool
|
||||
{
|
||||
return $this->right->getLayer() === $layer;
|
||||
}
|
||||
|
||||
private function isTypeEqual(string $type): bool
|
||||
{
|
||||
return $this->right->getType() === $type;
|
||||
}
|
||||
|
||||
private function checkPermission(): bool
|
||||
{
|
||||
return $this->right->getGrant();
|
||||
}
|
||||
|
||||
public function __construct(RightInterface $right)
|
||||
{
|
||||
$this->right = $right;
|
||||
}
|
||||
|
||||
public function isGranted(string $layer, string $type, SourceInterface $source): bool
|
||||
{
|
||||
return $this->isLayerEqual($layer) && $this->isTypeEqual($type) && $this->hasClientSource($source) && $this->checkPermission();
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\RightManagement;
|
||||
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
interface RightCheckerInterface
|
||||
{
|
||||
public function isGranted(string $layer, string $type, SourceInterface $source): bool;
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureLoadManagement;
|
||||
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use Doctrine\Common\Persistence\ObjectRepository;
|
||||
use App\Domain\SecureManagement\SecureSourceChecker;
|
||||
use App\Exception\SourceAccessDenied;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class SecureSourceLoader implements SecureSourceLoaderInterface
|
||||
{
|
||||
/**
|
||||
* @todo It would be better to specify the type
|
||||
*
|
||||
* @var ObjectRepository
|
||||
*/
|
||||
private $sourceRepository;
|
||||
|
||||
/**
|
||||
* The source attribute of the right needs a slug OR id.
|
||||
*
|
||||
* @var RightInterface the right which is requested
|
||||
*/
|
||||
private $requestedRight;
|
||||
|
||||
/**
|
||||
* @param SourceInterface $source
|
||||
*
|
||||
* @return RightInterface
|
||||
*/
|
||||
private function getClonedRightWithModifiedSource(SourceInterface $source): RightInterface
|
||||
{
|
||||
$requestedRight = clone $this->requestedRight;
|
||||
$requestedRight->setSource($source);
|
||||
|
||||
return $requestedRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SourceInterface
|
||||
*/
|
||||
private function loadSource(): SourceInterface
|
||||
{
|
||||
try {
|
||||
return $this->sourceRepository->find($this->requestedRight->getSource()->getId());
|
||||
} catch (\Error $error) {
|
||||
return $this->sourceRepository->findOneBySlug($this->requestedRight->getSource()->getSlug());
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager, RightInterface $requestedRight)
|
||||
{
|
||||
$this->sourceRepository = $entityManager->getRepository(AbstractSource::class);
|
||||
$this->requestedRight = $requestedRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\SecureLoadManagement\SecureSourceLoaderInterface::getSource()
|
||||
*/
|
||||
public function getSource(): SourceInterface
|
||||
{
|
||||
$source = $this->loadSource();
|
||||
$requestedRight = $this->getClonedRightWithModifiedSource($source);
|
||||
$secureSourceChecker = new SecureSourceChecker($source);
|
||||
if ($secureSourceChecker->hasPermission($requestedRight)) {
|
||||
return $source;
|
||||
}
|
||||
throw new SourceAccessDenied();
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureLoadManagement;
|
||||
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface SecureSourceLoaderInterface
|
||||
{
|
||||
/**
|
||||
* @throws AccessDeniedHttpException
|
||||
*
|
||||
* @return SourceInterface
|
||||
*/
|
||||
public function getSource(): SourceInterface;
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureManagement;
|
||||
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Domain\LawManagement\LawPermissionCheckerService;
|
||||
use App\Exception\SourceAccessDenied;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class SecureSourceChecker implements SecureSourceCheckerInterface
|
||||
{
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
private $source;
|
||||
|
||||
/**
|
||||
* @param SourceInterface $source
|
||||
*/
|
||||
public function __construct(SourceInterface $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $methodName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isGetter(string $methodName): bool
|
||||
{
|
||||
return 'get' === substr($methodName, 0, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isSource($value): bool
|
||||
{
|
||||
return $value instanceof SourceInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $methodName
|
||||
*
|
||||
* @return SourceInterface|null
|
||||
*/
|
||||
private function getExpectedSource(string $methodName): ?SourceInterface
|
||||
{
|
||||
try {
|
||||
return $this->source->{$methodName}();
|
||||
} catch (\TypeError $typeError) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RightInterface $requestedRight
|
||||
*
|
||||
* @throws SourceAccessDenied It's important to fire this exception to reduce complexity in debuging
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function itterateOverSourceAttributs(RightInterface $requestedRight): bool
|
||||
{
|
||||
foreach (get_class_methods($this->source) as $methodName) {
|
||||
if ($this->isGetter($methodName)) {
|
||||
$attributExpectedSource = $this->getExpectedSource($methodName);
|
||||
if ($attributExpectedSource) {
|
||||
$requestedSubSourceRight = clone $requestedRight;
|
||||
$requestedSubSourceRight->setSource($attributExpectedSource);
|
||||
if ($this->isSource($attributExpectedSource)) {
|
||||
$methodSecureSourceChecker = new self($attributExpectedSource);
|
||||
if (!$methodSecureSourceChecker->hasPermission($requestedSubSourceRight)) {
|
||||
throw new SourceAccessDenied('Access denied for subsource!');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\SecureManagement\SecureSourceCheckerInterface::hasPermission()
|
||||
*/
|
||||
public function hasPermission(RightInterface $requestedRight): bool
|
||||
{
|
||||
$law = new LawPermissionCheckerService($this->source->getLaw());
|
||||
|
||||
return $law->hasPermission($requestedRight) && $this->itterateOverSourceAttributs($requestedRight);
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureManagement;
|
||||
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use App\Exception\SourceAccessDenied;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface SecureSourceCheckerInterface
|
||||
{
|
||||
/**
|
||||
* @throws SourceAccessDenied
|
||||
*
|
||||
* @param RightInterface $right
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPermission(RightInterface $requestedRight): bool;
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use App\Domain\AbstractDomainService;
|
||||
|
||||
abstract class AbstractSourceService extends AbstractDomainService
|
||||
{
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
|
||||
|
||||
final class SourceMemberInformation implements SourceMemberInformationInterface
|
||||
{
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
private $source;
|
||||
|
||||
/**
|
||||
* @var Collection|SourceInterface[]
|
||||
*/
|
||||
private $members;
|
||||
|
||||
public function __construct(SourceInterface $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection|MemberRelationInterface[] $members
|
||||
*/
|
||||
private function itterateOverMembers(Collection $members): void
|
||||
{
|
||||
foreach ($members as $member) {
|
||||
if (!$this->members->contains($member->getSource())) {
|
||||
$this->members->add($member->getSource());
|
||||
$this->itterateOverMembers($member->getMembers());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\SourceManagement\SourceMemberInformationInterface::getAllMembers()
|
||||
*/
|
||||
public function getAllMembers(): Collection
|
||||
{
|
||||
$this->members = new ArrayCollection();
|
||||
$this->itterateOverMembers($this->source->getMemberRelation()->getMembers());
|
||||
|
||||
return $this->members;
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
interface SourceMemberInformationInterface
|
||||
{
|
||||
/**
|
||||
* @return Collection|SourceInterface[] All Members which belong to a source
|
||||
*/
|
||||
public function getAllMembers(): Collection;
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Domain\MemberManagement\MemberManagerInterface;
|
||||
use App\Domain\MemberManagement\MemberManager;
|
||||
|
||||
final class SourceMemberManager implements SourceMemberManagerInterface
|
||||
{
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
private $source;
|
||||
|
||||
/**
|
||||
* @var MemberManagerInterface
|
||||
*/
|
||||
private $memberManager;
|
||||
|
||||
public function __construct(SourceInterface $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
$this->memberManager = new MemberManager($this->source->getMemberRelation());
|
||||
}
|
||||
|
||||
public function addMember(SourceInterface $member): void
|
||||
{
|
||||
$this->memberManager->addMember($member->getMemberRelation());
|
||||
}
|
||||
|
||||
public function removeMember(SourceInterface $member): void
|
||||
{
|
||||
$this->memberManager->removeMember($member->getMemberRelation());
|
||||
}
|
||||
|
||||
public function addMembership(SourceInterface $membership): void
|
||||
{
|
||||
$this->memberManager->addMembership($membership->getMemberRelation());
|
||||
}
|
||||
|
||||
public function removeMembership(SourceInterface $membership): void
|
||||
{
|
||||
$this->memberManager->removeMembership($membership->getMemberRelation());
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
interface SourceMemberManagerInterface
|
||||
{
|
||||
/**
|
||||
* @param SourceInterface $member
|
||||
*/
|
||||
public function addMember(SourceInterface $member): void;
|
||||
|
||||
/**
|
||||
* @param SourceInterface $member
|
||||
*/
|
||||
public function removeMember(SourceInterface $member): void;
|
||||
|
||||
/**
|
||||
* @param SourceInterface $membership
|
||||
*/
|
||||
public function addMembership(SourceInterface $membership): void;
|
||||
|
||||
/**
|
||||
* @param SourceInterface $membership
|
||||
*/
|
||||
public function removeMembership(SourceInterface $membership): void;
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
|
||||
|
||||
final class SourceMembershipInformation implements SourceMembershipInformationInterface
|
||||
{
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
private $source;
|
||||
|
||||
/**
|
||||
* @var Collection|SourceInterface[]
|
||||
*/
|
||||
private $memberships;
|
||||
|
||||
public function __construct(SourceInterface $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection|MemberRelationInterface[] $memberships
|
||||
*/
|
||||
private function itterateOverMemberships(Collection $memberships): void
|
||||
{
|
||||
foreach ($memberships as $membership) {
|
||||
if (!$this->memberships->contains($membership->getSource())) {
|
||||
$this->memberships->add($membership->getSource());
|
||||
$this->itterateOverMemberships($membership->getMemberships());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\SourceManagement\SourceMembershipInformationInterface::getAllMemberships()
|
||||
*/
|
||||
public function getAllMemberships(): Collection
|
||||
{
|
||||
$this->memberships = new ArrayCollection();
|
||||
$this->itterateOverMemberships($this->source->getMemberRelation()->getMemberships());
|
||||
|
||||
return $this->memberships;
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
interface SourceMembershipInformationInterface
|
||||
{
|
||||
/**
|
||||
* @return Collection|SourceInterface[] all Sources which a Source belongs to
|
||||
*/
|
||||
public function getAllMemberships(): Collection;
|
||||
}
|
126
application/symfony/src/Domain/SourceManagement/SourceMeta.php
Normal file
126
application/symfony/src/Domain/SourceManagement/SourceMeta.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use App\Domain\FormManagement\FormMetaInterface;
|
||||
use App\Domain\TemplateManagement\TemplateMetaInterface;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Domain\TemplateManagement\TemplateMeta;
|
||||
use App\Domain\FormManagement\FormMeta;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class SourceMeta implements SourceMetaInterface
|
||||
{
|
||||
const FOLDER = 'entity';
|
||||
|
||||
/**
|
||||
* @var \ReflectionClass
|
||||
*/
|
||||
private $sourceReflection;
|
||||
|
||||
/**
|
||||
* @var \ReflectionClass
|
||||
*/
|
||||
private $interfaceReflection;
|
||||
|
||||
/**
|
||||
* @var TemplateMetaInterface
|
||||
*/
|
||||
private $templateMeta;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $basicPathArray;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $basicName;
|
||||
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
private $source;
|
||||
|
||||
/**
|
||||
* @var FormMetaInterface
|
||||
*/
|
||||
private $formMeta;
|
||||
|
||||
public function __construct(SourceInterface $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
$this->sourceReflection = new \ReflectionClass($source);
|
||||
$this->setBasicPathArray();
|
||||
$this->setBasicName();
|
||||
$this->setInterfaceReflection();
|
||||
$this->setTemplateMeta();
|
||||
$this->formMeta = new FormMeta($this);
|
||||
}
|
||||
|
||||
private function setTemplateMeta(): void
|
||||
{
|
||||
$this->templateMeta = new TemplateMeta($this->basicPathArray, $this->basicName, self::FOLDER);
|
||||
}
|
||||
|
||||
private function setBasicPathArray(): void
|
||||
{
|
||||
$namespace = $this->sourceReflection->getNamespaceName();
|
||||
$namespaceWithoutRoot = str_replace('App\\Entity\\', '', $namespace);
|
||||
$this->basicPathArray = [];
|
||||
foreach (explode('\\', $namespaceWithoutRoot) as $element) {
|
||||
$this->basicPathArray[] = strtolower($element);
|
||||
}
|
||||
}
|
||||
|
||||
private function setInterfaceReflection(): void
|
||||
{
|
||||
$namespace = str_replace('\Abstract', '\\', $this->sourceReflection->getName()).'Interface';
|
||||
$this->interfaceReflection = new \ReflectionClass($namespace);
|
||||
}
|
||||
|
||||
private function setBasicName(): void
|
||||
{
|
||||
$withoutAbstract = str_replace('Abstract', '', $this->sourceReflection->getShortName());
|
||||
$withoutSource = str_replace('Source', '', $withoutAbstract);
|
||||
$this->basicName = strtolower($withoutSource);
|
||||
}
|
||||
|
||||
public function getBasicPathArray(): array
|
||||
{
|
||||
return $this->basicPathArray;
|
||||
}
|
||||
|
||||
public function getInterfaceReflection(): \ReflectionClass
|
||||
{
|
||||
return $this->interfaceReflection;
|
||||
}
|
||||
|
||||
public function getSourceReflection(): \ReflectionClass
|
||||
{
|
||||
return $this->sourceReflection;
|
||||
}
|
||||
|
||||
public function getTemplateMeta(): TemplateMetaInterface
|
||||
{
|
||||
return $this->templateMeta;
|
||||
}
|
||||
|
||||
public function getBasicName(): string
|
||||
{
|
||||
return $this->basicName;
|
||||
}
|
||||
|
||||
public function getSource(): SourceInterface
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
public function getFormMeta(): FormMetaInterface
|
||||
{
|
||||
return $this->formMeta;
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use App\Domain\TemplateManagement\TemplateMetaInterface;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Domain\FormManagement\FormMetaInterface;
|
||||
|
||||
/**
|
||||
* A meta source offers informations, which the system needs to handle the source.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface SourceMetaInterface
|
||||
{
|
||||
public function getSourceReflection(): \ReflectionClass;
|
||||
|
||||
public function getInterfaceReflection(): \ReflectionClass;
|
||||
|
||||
public function getTemplateMeta(): TemplateMetaInterface;
|
||||
|
||||
/**
|
||||
* @return array the namespace elements without the root
|
||||
*/
|
||||
public function getBasicPathArray(): array;
|
||||
|
||||
/**
|
||||
* @return string Short class name in lower case without "Abstract" and "Source"
|
||||
*/
|
||||
public function getBasicName(): string;
|
||||
|
||||
/**
|
||||
* @return SourceInterface The source to which the meta object belongs to
|
||||
*/
|
||||
public function getSource(): SourceInterface;
|
||||
|
||||
public function getFormMeta(): FormMetaInterface;
|
||||
}
|
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Exception\AllreadySetException;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
use App\Entity\Meta\Law;
|
||||
use App\Exception\AllreadyDefinedException;
|
||||
use App\Exception\NotSetException;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class SourceRightManager implements SourceRightManagerInterface
|
||||
{
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
private $source;
|
||||
|
||||
/**
|
||||
* @param SourceInterface $source
|
||||
*/
|
||||
public function __construct(SourceInterface $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws AllreadyDefinedException If the attribut is allready defined
|
||||
*/
|
||||
private function checkRightAttributes(RightInterface $right): void
|
||||
{
|
||||
$attributes = ['source', 'law'];
|
||||
foreach ($attributes as $attribut) {
|
||||
try {
|
||||
$right->{'get'.ucfirst($attribut)}();
|
||||
throw new AllreadyDefinedException("The attribut \"$attribut\" is allready defined!");
|
||||
} catch (\Error $error) {
|
||||
//Expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayCollection|RightInterface[]
|
||||
*/
|
||||
private function getRights(): ArrayCollection
|
||||
{
|
||||
return $this->source->getLaw()->getRights();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\SourceManagement\SourceRightManagerInterface::addRight()
|
||||
*/
|
||||
public function addRight(RightInterface $right): void
|
||||
{
|
||||
if ($this->getRights()->contains($right)) {
|
||||
throw new AllreadySetException('The right was allready added.');
|
||||
}
|
||||
$this->checkRightAttributes($right);
|
||||
$right->setSource($this->source);
|
||||
$right->setLaw($this->source->getLaw());
|
||||
$this->getRights()->add($right);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\SourceManagement\SourceRightManagerInterface::removeRight()
|
||||
*/
|
||||
public function removeRight(RightInterface $right): void
|
||||
{
|
||||
$right->setSource(new class() extends AbstractSource {
|
||||
});
|
||||
$right->setLaw(new Law());
|
||||
if (!$this->getRights()->removeElement($right)) {
|
||||
throw new NotSetException('The right to remove is not set.');
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use App\Exception\AllreadySetException;
|
||||
use App\Exception\AllreadyDefinedException;
|
||||
use App\Exception\NotSetException;
|
||||
|
||||
interface SourceRightManagerInterface
|
||||
{
|
||||
/**
|
||||
* @param RightInterface $right
|
||||
*
|
||||
* @throws AllreadySetException
|
||||
* @throws AllreadyDefinedException
|
||||
*/
|
||||
public function addRight(RightInterface $right): void;
|
||||
|
||||
/**
|
||||
* @param RightInterface $right
|
||||
*
|
||||
* @throws NotSetException
|
||||
*/
|
||||
public function removeRight(RightInterface $right): void;
|
||||
}
|
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use App\Entity\Source\Complex\Collection\TreeCollectionSourceInterface;
|
||||
use App\Entity\Source\Complex\Collection\TreeCollectionSource;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
/**
|
||||
* Allows to iterate over a tree.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Maybe lazy loading would be helpfull for performance
|
||||
*/
|
||||
final class TreeSourceService extends AbstractSourceService implements TreeSourceServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var TreeCollectionSourceInterface
|
||||
*/
|
||||
private $source;
|
||||
|
||||
/**
|
||||
* Containes all branches of the actual level of the tree.
|
||||
*
|
||||
* @var Collection
|
||||
*/
|
||||
private $branches;
|
||||
|
||||
/**
|
||||
* Containes all leaves of the actual level of the tree.
|
||||
*
|
||||
* @var Collection
|
||||
*/
|
||||
private $leaves;
|
||||
|
||||
public function __construct(TreeCollectionSource $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
$this->branches = new ArrayCollection();
|
||||
$this->leaves = new ArrayCollection();
|
||||
$this->basicSort();
|
||||
}
|
||||
|
||||
private function sortMember(SourceInterface $member): bool
|
||||
{
|
||||
if ($member instanceof TreeCollectionSource) {
|
||||
return $this->branches->add($member);
|
||||
}
|
||||
|
||||
return $this->leaves->add($member);
|
||||
}
|
||||
|
||||
private function basicSort(): void
|
||||
{
|
||||
foreach ($this->source->getCollection() as $member) {
|
||||
$this->sortMember($member);
|
||||
}
|
||||
}
|
||||
|
||||
public function getBranches(): Collection
|
||||
{
|
||||
return $this->branches;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Remove the optional parameter and put the logic in a private funtion.
|
||||
* @todo Remove the getAllBranches use inside the function.
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\SourceManagement\TreeSourceServiceInterface::getAllBranches()
|
||||
*/
|
||||
public function getAllBranches(): Collection
|
||||
{
|
||||
$allBranches = new ArrayCollection($this->branches->toArray());
|
||||
foreach ($this->branches->toArray() as $branch) {
|
||||
$this->itterateOverBranch($branch, $allBranches);
|
||||
}
|
||||
|
||||
return $allBranches;
|
||||
}
|
||||
|
||||
private function itterateOverBranch(TreeCollectionSourceInterface $branch, ArrayCollection $allBranches): void
|
||||
{
|
||||
foreach ((new self($branch))->getBranches() as $branchBranch) {
|
||||
if (!$allBranches->contains($branchBranch)) {
|
||||
$allBranches->add($branchBranch);
|
||||
if ($branchBranch instanceof TreeCollectionSourceInterface) {
|
||||
$this->itterateOverBranch($branchBranch, $allBranches);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getLeaves(): Collection
|
||||
{
|
||||
return $this->leaves;
|
||||
}
|
||||
|
||||
public function getAllLeaves(): Collection
|
||||
{
|
||||
$leaves = new ArrayCollection($this->getLeaves()->toArray());
|
||||
foreach ($this->getAllBranches() as $branch) {
|
||||
foreach ((new self($branch))->getLeaves() as $leave) {
|
||||
if (!$leaves->contains($leave)) {
|
||||
$leaves->add($leave);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $leaves;
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SourceManagement;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
interface TreeSourceServiceInterface
|
||||
{
|
||||
/**
|
||||
* Delivers the branches of the actual tree back.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBranches(): Collection;
|
||||
|
||||
/**
|
||||
* Delivers the members of the actual tree back.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getLeaves(): Collection;
|
||||
|
||||
/**
|
||||
* Delivers all members till a infinite level of the tree back.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllLeaves(): Collection;
|
||||
|
||||
/**
|
||||
* Delivers all branches till a infinite level of the actual tree back.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllBranches(): Collection;
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\TemplateManagement;
|
||||
|
||||
use App\DBAL\Types\RESTResponseType;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class TemplateMeta implements TemplateMetaInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $basicPathArray;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $basicName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $type = RESTResponseType::HTML;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $pathSuffix;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $frameTemplatePath;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $contentTemplatePath;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $folder;
|
||||
|
||||
public function __construct(array $basicPathArray, string $basicName, string $folder)
|
||||
{
|
||||
$this->basicPathArray = $basicPathArray;
|
||||
$this->basicName = $basicName;
|
||||
$this->folder = $folder;
|
||||
$this->init();
|
||||
}
|
||||
|
||||
private function init()
|
||||
{
|
||||
$this->setPathSuffix();
|
||||
$this->setFrameTemplatePath();
|
||||
$this->setContentTemplatePath();
|
||||
}
|
||||
|
||||
private function setPathSuffix(): void
|
||||
{
|
||||
$this->pathSuffix = $this->folder.'/'.implode('/', $this->basicPathArray).'/'.$this->basicName.'.'.$this->type.'.twig';
|
||||
}
|
||||
|
||||
private function setFrameTemplatePath(): void
|
||||
{
|
||||
$this->frameTemplatePath = 'frame/'.$this->pathSuffix;
|
||||
}
|
||||
|
||||
private function setContentTemplatePath(): void
|
||||
{
|
||||
$this->contentTemplatePath = 'content/'.$this->pathSuffix;
|
||||
}
|
||||
|
||||
public function getFrameTemplatePath(): string
|
||||
{
|
||||
return $this->frameTemplatePath;
|
||||
}
|
||||
|
||||
public function getContentTemplatePath(): string
|
||||
{
|
||||
return $this->contentTemplatePath;
|
||||
}
|
||||
|
||||
public function setTemplateType(string $type): void
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->init();
|
||||
}
|
||||
|
||||
public function getTemplateType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\TemplateManagement;
|
||||
|
||||
/**
|
||||
* Manages all informations which are needed to process templates.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface TemplateMetaInterface
|
||||
{
|
||||
/**
|
||||
* Sets the template type which should be processed(General html);.
|
||||
*/
|
||||
public function setTemplateType(string $type): void;
|
||||
|
||||
public function getTemplateType(): string;
|
||||
|
||||
/**
|
||||
* Returns a template inclusiv frame.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFrameTemplatePath(): string;
|
||||
|
||||
/**
|
||||
* Returns a template without a frame.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContentTemplatePath(): string;
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\UserManagement;
|
||||
|
||||
use App\Entity\UserInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\DBAL\Types\SystemSlugType;
|
||||
use App\Entity\User;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
use App\Repository\Source\SourceRepository;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class UserIdentityManager implements UserIdentityManagerInterface
|
||||
{
|
||||
/**
|
||||
* @var UserInterface
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @var SourceRepository
|
||||
*/
|
||||
private $sourceRepository;
|
||||
|
||||
/**
|
||||
* @param EntityManagerInterface $entityManager
|
||||
*/
|
||||
private function setSourceRepository(EntityManagerInterface $entityManager): void
|
||||
{
|
||||
$this->sourceRepository = $entityManager->getRepository(AbstractSource::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserInterface $user
|
||||
*/
|
||||
private function setUser(?UserInterface $user): void
|
||||
{
|
||||
if ($user) {
|
||||
$this->user = $user;
|
||||
|
||||
return;
|
||||
}
|
||||
$this->user = new User();
|
||||
$this->user->setSource($this->sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EntityManagerInterface $entityManager
|
||||
* @param UserInterface $user
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entityManager, ?UserInterface $user)
|
||||
{
|
||||
$this->setSourceRepository($entityManager);
|
||||
$this->setUser($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\UserManagement\UserIdentityManagerInterface::getUser()
|
||||
*/
|
||||
public function getUser(): UserInterface
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\UserManagement;
|
||||
|
||||
use App\Entity\UserInterface;
|
||||
|
||||
interface UserIdentityManagerInterface
|
||||
{
|
||||
/**
|
||||
* @return UserInterface
|
||||
*/
|
||||
public function getUser(): UserInterface;
|
||||
}
|
Reference in New Issue
Block a user