Optimized for SPA

This commit is contained in:
Kevin Frantz
2019-01-05 23:52:37 +01:00
parent 9e685260e9
commit bccd6efaff
393 changed files with 253 additions and 37 deletions

View File

@@ -0,0 +1,9 @@
<?php
namespace App\Domain\SourceManagement;
use App\Domain\AbstractDomainService;
abstract class AbstractSourceService extends AbstractDomainService
{
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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());
}
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View 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;
}
}

View File

@@ -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;
}

View File

@@ -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.');
}
}
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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;
}