Added SourceMemberInformation

This commit is contained in:
Kevin Frantz
2018-12-06 20:22:27 +01:00
parent 61a6ea6b36
commit e97003b91d
6 changed files with 122 additions and 10 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Domain\SourceManagement;
use Doctrine\Common\Collections\Collection;
use App\Entity\Source\SourceInterface;
use Doctrine\Common\Collections\ArrayCollection;
final class SourceMemberInformation implements SourceMemberInformationInterface
{
/**
* @var SourceInterface
*/
private $source;
/**
* @var Collection|SourceInterface[]
*/
private $members;
public function __construct(SourceInterface $source)
{
$this->source = $source;
}
private function itterateOverMembers(Collection $members): void
{
foreach ($members as $member) {
if (!$this->members->contains($member)) {
$this->members->add($member);
$this->itterateOverMembers($member->getMemberRelation()->getMembers());
}
}
}
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

@@ -6,7 +6,7 @@ use Doctrine\Common\Collections\Collection;
use App\Entity\Source\SourceInterface;
use Doctrine\Common\Collections\ArrayCollection;
class SourceMembershipInformation implements SourceMembershipInformationInterface
final class SourceMembershipInformation implements SourceMembershipInformationInterface
{
/**
* @var SourceInterface
@@ -14,7 +14,7 @@ class SourceMembershipInformation implements SourceMembershipInformationInterfac
private $source;
/**
* @var Collection
* @var Collection|SourceInterface[]
*/
private $memberships;

View File

@@ -3,8 +3,12 @@
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;
}