In between commit implementing reciever

This commit is contained in:
Kevin Frantz 2018-10-31 17:19:10 +01:00
parent bb01080b34
commit e7f82c4835
8 changed files with 77 additions and 40 deletions

View File

@ -0,0 +1,54 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @author kevinfrantz
*/
trait MembersAttribut
{
/**
* @var Collection
*/
protected $members;
public function getMembers(): Collection
{
return $this->members;
}
public function setMembers(Collection $members): void
{
$this->members = $members;
}
/**
* @param int $dimension The dimensions start with 1 for the members of the actuall dimension and NULL for all members
* @param Collection $members A reference to a members list, to which new members should be add
*
* @return Collection|MembersAttributInterface[] Returns all members till the defined dimension
*/
public function getMembersInclusiveChildren(int $dimension = null, Collection &$members = null): Collection
{
// Subtract minus one, so that following members start on a other dimension:
--$dimension;
//Define members if no members are passed
if (!$members) {
$members = new ArrayCollection();
}
foreach ($this->members as $member) {
if (!$members->contains($member)) {
$members->add($member);
if ($dimension > 0 || null === $dimension) {
$member->getMembersInclusiveChildren($dimension, $members);
}
}
}
return $members;
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace App\Entity\Source\Attribut;
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\Collection;
@ -20,4 +20,9 @@ interface MembersAttributInterface
* @return Collection
*/
public function getMembers(): Collection;
/**
* @return Collection
*/
public function getMembersInclusiveChildren(int $dimension = null): Collection;
}

View File

@ -4,9 +4,9 @@ namespace App\Entity\Meta;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
use App\Entity\Attribut\RelationAttribut;
use App\Entity\Attribut\RelationAttributInterface;
use App\Entity\Attribut\MembersAttribut;
/**
* @author kevinfrantz
@ -15,7 +15,7 @@ use App\Entity\Attribut\RelationAttributInterface;
*/
class Reciever extends AbstractMeta implements RecieverInterface
{
use RelationAttribut;
use RelationAttribut, MembersAttribut;
/**
* The node for which the right exists.
@ -29,6 +29,7 @@ class Reciever extends AbstractMeta implements RecieverInterface
public function getAllRecievers(): ArrayCollection
{
foreach ($this->members->getValues() as $source) {
}
}
}

View File

@ -4,11 +4,12 @@ namespace App\Entity\Meta;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attribut\RelationAttributInterface;
use App\Entity\Attribut\MembersAttributInterface;
/**
* @author kevinfrantz
*/
interface RecieverInterface extends RelationAttributInterface, MetaInterface
interface RecieverInterface extends RelationAttributInterface, MetaInterface, MembersAttributInterface
{
public function getAllRecievers(): ArrayCollection;
}

View File

@ -1,26 +0,0 @@
<?php
namespace App\Entity\Source\Attribut;
use Doctrine\Common\Collections\Collection;
/**
* @author kevinfrantz
*/
trait MembersAttribut
{
/**
* @var Collection
*/
protected $members;
public function getMembers(): Collection
{
return $this->members;
}
public function setMembers(Collection $members): void
{
$this->members = $members;
}
}

View File

@ -4,8 +4,8 @@ namespace App\Entity\Source;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use App\Entity\Source\Attribut\MembersAttributInterface;
use App\Entity\Source\Attribut\MembersAttribut;
use App\Entity\Attribut\MembersAttributInterface;
use App\Entity\Attribut\MembersAttribut;
use Doctrine\Common\Collections\ArrayCollection;
/**

View File

@ -2,7 +2,7 @@
namespace App\Entity\Source;
use App\Entity\Source\Attribut\MembersAttributInterface;
use App\Entity\Attribut\MembersAttributInterface;
/**
* @author kevinfrantz

View File

@ -1,4 +1,5 @@
<?php
namespace App\tests\unit\Entity\Meta;
use PHPUnit\Framework\TestCase;
@ -9,16 +10,17 @@ use App\Entity\Meta\RecieverInterface;
class RecieverTest extends TestCase
{
/**
*
* @var RecieverInterface
*/
public $reciever;
public function setUp():void{
public function setUp(): void
{
$this->reciever = new Reciever();
}
public function testConstructor():void {
public function testConstructor(): void
{
$this->assertEquals(Collection::class, $this->reciever->getAllRecievers());
}
}
}