mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 22:17:26 +01:00
Optimized entity mapping for collections
This commit is contained in:
parent
b11b53884b
commit
e0edc8935d
@ -7,22 +7,24 @@ use App\Helper\DimensionHelper;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
* @todo this attribut should be refactored to mapp fully on collections instead of members
|
||||||
*/
|
*/
|
||||||
trait MembersAttribut
|
trait MembersAttribut
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Collection
|
* @var Collection
|
||||||
*/
|
*/
|
||||||
protected $members;
|
protected $collection;
|
||||||
|
|
||||||
public function getMembers(): Collection
|
public function getMembers(): Collection
|
||||||
{
|
{
|
||||||
return $this->members;
|
return $this->collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMembers(Collection $members): void
|
public function setMembers(Collection $members): void
|
||||||
{
|
{
|
||||||
$this->members = $members;
|
$this->collection = $members;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,10 +37,11 @@ class Reciever extends AbstractMeta implements RecieverInterface
|
|||||||
*
|
*
|
||||||
* @var ArrayCollection | SourceInterface[]
|
* @var ArrayCollection | SourceInterface[]
|
||||||
*/
|
*/
|
||||||
protected $members;
|
protected $collection;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->members = new ArrayCollection();
|
parent::__construct();
|
||||||
|
$this->collection = new ArrayCollection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface
|
|||||||
* @todo Rename table to use the right schema
|
* @todo Rename table to use the right schema
|
||||||
*
|
*
|
||||||
* @var Collection|MemberCollectionSource[]
|
* @var Collection|MemberCollectionSource[]
|
||||||
* @ORM\ManyToMany(targetEntity="App\Entity\Source\Collection\MemberCollectionSource",mappedBy="members")
|
* @ORM\ManyToMany(targetEntity="App\Entity\Source\Collection\MemberCollectionSource",mappedBy="collection")
|
||||||
*/
|
*/
|
||||||
protected $memberships;
|
protected $memberships;
|
||||||
|
|
||||||
|
@ -4,13 +4,34 @@ namespace App\Entity\Source\Collection;
|
|||||||
|
|
||||||
use App\Entity\Source\AbstractSource;
|
use App\Entity\Source\AbstractSource;
|
||||||
use App\Entity\Attribut\CollectionAttribut;
|
use App\Entity\Attribut\CollectionAttribut;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use App\Entity\Source\SourceInterface;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo Implement inhiering classes!
|
* @ORM\Entity
|
||||||
|
* @ORM\Table(name="source_collection")
|
||||||
|
* @ORM\InheritanceType("JOINED")
|
||||||
|
* @ORM\DiscriminatorColumn(name="discr", type="string")
|
||||||
|
* @ORM\DiscriminatorMap({"member" = "MemberCollectionSource"})
|
||||||
*
|
*
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
abstract class AbstractCollectionSource extends AbstractSource implements CollectionSourceInterface
|
abstract class AbstractCollectionSource extends AbstractSource implements CollectionSourceInterface
|
||||||
{
|
{
|
||||||
use CollectionAttribut;
|
use CollectionAttribut;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Collection|SourceInterface[]
|
||||||
|
* @ORM\ManyToMany(targetEntity="App\Entity\Source\AbstractSource",inversedBy="memberships")
|
||||||
|
* @ORM\JoinTable(name="source_group_members")
|
||||||
|
*/
|
||||||
|
protected $collection;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->collection = new ArrayCollection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,7 @@
|
|||||||
namespace App\Entity\Source\Collection;
|
namespace App\Entity\Source\Collection;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Doctrine\Common\Collections\Collection;
|
|
||||||
use App\Entity\Attribut\MembersAttribut;
|
use App\Entity\Attribut\MembersAttribut;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
@ -15,17 +13,4 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||||||
final class MemberCollectionSource extends AbstractCollectionSource implements MemberCollectionSourceInterface
|
final class MemberCollectionSource extends AbstractCollectionSource implements MemberCollectionSourceInterface
|
||||||
{
|
{
|
||||||
use MembersAttribut;
|
use MembersAttribut;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Collection
|
|
||||||
* @ORM\ManyToMany(targetEntity="App\Entity\Source\AbstractSource",inversedBy="memberships")
|
|
||||||
* @ORM\JoinTable(name="source_group_members")
|
|
||||||
*/
|
|
||||||
protected $members;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
$this->members = new ArrayCollection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ namespace Tests\Unit\Entity\Source\Collection;
|
|||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use App\Entity\Source\Collection\CollectionSourceInterface;
|
use App\Entity\Source\Collection\CollectionSourceInterface;
|
||||||
use App\Entity\Source\Collection\AbstractCollectionSource;
|
use App\Entity\Source\Collection\AbstractCollectionSource;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
|
||||||
class AbstractCollectionSourceTest extends TestCase
|
class AbstractCollectionSourceTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -21,7 +22,6 @@ class AbstractCollectionSourceTest extends TestCase
|
|||||||
|
|
||||||
public function testConstruct(): void
|
public function testConstruct(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\TypeError::class);
|
$this->assertInstanceOf(Collection::class, $this->collectionSource->getCollection());
|
||||||
$this->collectionSource->getCollection();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user