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,103 @@
<?php
namespace App\Entity\Source;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Exclude;
use App\Entity\AbstractEntity;
use App\Entity\Attribut\LawAttribut;
use App\Entity\Meta\LawInterface;
use App\Entity\Meta\Law;
use App\Entity\Attribut\SlugAttribut;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Attribut\CreatorRelationAttribut;
use App\Entity\Meta\Relation\Parent\CreatorRelationInterface;
use App\Entity\Meta\Relation\Parent\CreatorRelation;
use App\Entity\Attribut\MemberRelationAttribut;
use App\Entity\Meta\Relation\Member\MemberRelation;
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
/**
* @author kevinfrantz
*
* For the members\memberships attribut checkout:
*
* @todo Move parts of discriminator map to subclasses
*
* @see http://www.inanzzz.com/index.php/post/h0jt/bidirectional-many-to-many-cascade-remove-and-orphan-removal-operations-in-doctrine
*
* @ORM\Entity(repositoryClass="App\Repository\Source\SourceRepository")
* @ORM\Table(name="source")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({
* "pure" = "PureSource",
* "text" = "App\Entity\Source\Primitive\Text\TextSource",
* "operation"="App\Entity\Source\Operation\AbstractOperation",
* "user" = "App\Entity\Source\Complex\UserSource",
* "fullpersonname" = "App\Entity\Source\Complex\FullPersonNameSource",
* "personidentitysource"="App\Entity\Source\Complex\PersonIdentitySource",
* "fullpersonnamesource"="App\Entity\Source\Complex\FullPersonNameSource",
* "member" = "App\Entity\Source\Complex\Collection\TreeCollectionSource",
* "and" = "App\Entity\Source\Operation\AndOperation",
* "nickname" = "App\Entity\Source\Primitive\Name\NicknameSource",
* "firstname" = "App\Entity\Source\Primitive\Name\FirstNameSource",
* "surname" = "App\Entity\Source\Primitive\Name\SurnameSource"
* })
* @UniqueEntity("slug",ignoreNull=true)
*/
abstract class AbstractSource extends AbstractEntity implements SourceInterface
{
use LawAttribut,SlugAttribut,CreatorRelationAttribut, MemberRelationAttribut;
/**
* System slugs should be writen in UPPER CASES
* Slugs which are defined by the user are checked via the assert.
*
* @ORM\Column(type="string",length=30,nullable=true,unique=true)
* @Assert\Regex(pattern="/^[a-z]+$/")
*
* @todo Check out if a plugin can solve this purpose;
*
* @see https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/sluggable.md
*
* @var string
*/
protected $slug;
/**
* @var CreatorRelationInterface
* @ORM\OneToOne(targetEntity="App\Entity\Meta\Relation\Parent\CreatorRelation",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="creator_relation_id", referencedColumnName="id", onDelete="CASCADE")
* @Exclude
*/
protected $creatorRelation;
/**
* @var MemberRelationInterface
* @ORM\OneToOne(targetEntity="App\Entity\Meta\Relation\Member\MemberRelation",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="member_relation_id", referencedColumnName="id", onDelete="CASCADE")
* @Exclude
*/
protected $memberRelation;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Meta\Law",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="law_id", referencedColumnName="id", onDelete="CASCADE")
*
* @var LawInterface
*/
protected $law;
public function __construct()
{
parent::__construct();
$this->creatorRelation = new CreatorRelation();
$this->creatorRelation->setSource($this);
$this->memberRelation = new MemberRelation();
$this->memberRelation->setSource($this);
$this->law = new Law();
$this->law->setSource($this);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Entity\Source\Complex;
use App\Entity\Source\AbstractSource;
/**
* @author kevinfrantz
*/
abstract class AbstractComplexSource extends AbstractSource implements ComplexSourceInterface
{
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Entity\Source\Complex\Collection;
use App\Entity\Source\AbstractSource;
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;
/**
* @author kevinfrantz
*/
abstract class AbstractCollectionSource extends AbstractSource implements CollectionSourceInterface
{
use CollectionAttribut;
/**
* @var Collection|SourceInterface[]
* @ORM\ManyToMany(targetEntity="App\Entity\Source\AbstractSource")
* @ORM\JoinTable(name="collection_source",
* joinColumns={@ORM\JoinColumn(name="collection_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="source_id", referencedColumnName="id")}
* )
*/
protected $collection;
public function __construct()
{
parent::__construct();
$this->collection = new ArrayCollection();
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Entity\Source\Complex\Collection;
use App\Entity\Source\SourceInterface;
use App\Entity\Attribut\CollectionAttributInterface;
interface CollectionSourceInterface extends SourceInterface, CollectionAttributInterface
{
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Entity\Source\Complex\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @author kevinfrantz
* @ORM\Entity
*/
class TreeCollectionSource extends AbstractCollectionSource implements TreeCollectionSourceInterface
{
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Entity\Source\Complex\Collection;
/**
* @author kevinfrantz
*/
interface TreeCollectionSourceInterface extends CollectionSourceInterface
{
}

View File

@@ -0,0 +1,14 @@
<?php
namespace App\Entity\Source\Complex;
use App\Entity\Source\SourceInterface;
/**
* Complex sources contain out of one or more primitive sources.
*
* @author kevinfrantz
*/
interface ComplexSourceInterface extends SourceInterface
{
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Entity\Source\Complex;
use App\Entity\Attribut\FirstNameSourceAttribut;
use App\Entity\Attribut\SurnameSourceAttribut;
use App\Entity\Source\Primitive\Name\SurnameSource;
use App\Entity\Source\Primitive\Name\FirstNameSource;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Source\Primitive\Name\SurnameSourceInterface;
use App\Entity\Source\Primitive\Name\FirstNameSourceInterface;
/**
* @author kevinfrantz
* @ORM\Entity()
*/
class FullPersonNameSource extends AbstractComplexSource implements FullPersonNameSourceInterface
{
use FirstNameSourceAttribut,SurnameSourceAttribut;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Source\Primitive\Name\SurnameSource",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="surname_id", referencedColumnName="id",onDelete="CASCADE")
*
* @var SurnameSourceInterface
*/
protected $surnameSource;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Source\Primitive\Name\FirstNameSource",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="firstname_id", referencedColumnName="id",onDelete="CASCADE")
*
* @var FirstNameSourceInterface
*/
protected $firstNameSource;
public function __construct()
{
parent::__construct();
$this->surnameSource = new SurnameSource();
$this->firstNameSource = new FirstNameSource();
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace App\Entity\Source\Complex;
use App\Entity\Attribut\FirstNameSourceAttributInterface;
use App\Entity\Attribut\SurnameSourceAttributInterface;
/**
* @todo Maybe a middle name would be helpfull in the future ;)
*
* @author kevinfrantz
*/
interface FullPersonNameSourceInterface extends ComplexSourceInterface, FirstNameSourceAttributInterface, SurnameSourceAttributInterface
{
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Entity\Source\Complex;
use App\Entity\Attribut\FullPersonNameSourceAttribut;
use Doctrine\ORM\Mapping as ORM;
/**
* @author kevinfrantz
* @ORM\Entity()
*/
class PersonIdentitySource extends AbstractComplexSource implements PersonIdentitySourceInterface
{
use FullPersonNameSourceAttribut;
/**
* @ORM\OneToOne(targetEntity="FullPersonNameSource",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="fullname_id", referencedColumnName="id",onDelete="CASCADE")
*
* @var FullPersonNameSourceInterface
*/
protected $fullPersonNameSource;
public function __construct()
{
parent::__construct();
$this->fullPersonNameSource = new FullPersonNameSource();
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace App\Entity\Source\Complex;
use App\Entity\Attribut\FullPersonNameSourceAttributInterface;
interface PersonIdentitySourceInterface extends ComplexSourceInterface, FullPersonNameSourceAttributInterface
{
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Entity\Source\Complex;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\UserAttribut;
use App\Entity\UserInterface;
use App\Entity\Attribut\PersonIdentitySourceAttribut;
/**
* @author kevinfrantz
* @ORM\Entity(repositoryClass="App\Repository\UserSourceRepository")
*/
class UserSource extends AbstractComplexSource implements UserSourceInterface
{
use UserAttribut,PersonIdentitySourceAttribut;
/**
* @ORM\OneToOne(targetEntity="App\Entity\User",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="user_id", referencedColumnName="id",onDelete="CASCADE")
*
* @var UserInterface
*/
protected $user;
/**
* @ORM\OneToOne(targetEntity="PersonIdentitySource",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="identity_id", referencedColumnName="id",onDelete="CASCADE")
*
* @var PersonIdentitySourceInterface
*/
protected $personIdentitySource;
public function __construct()
{
parent::__construct();
}
public function hasPersonIdentitySource(): bool
{
return isset($this->personIdentitySource);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Entity\Source\Complex;
use App\Entity\Attribut\UserAttributInterface;
use App\Entity\Attribut\PersonIdentitySourceAttributInterface;
/**
* @author kevinfrantz
*/
interface UserSourceInterface extends ComplexSourceInterface, UserAttributInterface, PersonIdentitySourceAttributInterface
{
/**
* Checks if the user has an identity source.
*
* @return bool
*/
public function hasPersonIdentitySource(): bool;
}

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Entity\Source\Operation;
use App\Logic\Result\ResultInterface;
use App\Logic\Operation\OperandInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Source\AbstractSource;
use App\Entity\Source\Operation\Attribut\OperandsAttribut;
use App\Exception\NotProcessedException;
/**
* @author kevinfrantz
* @ORM\Entity
*/
abstract class AbstractOperation extends AbstractSource implements OperationInterface
{
use OperandsAttribut;
/**
* The result MUST NOT be saved via Doctrine!
*
* @var ResultInterface
*/
protected $result;
/**
* @var ArrayCollection|OperandInterface[]
*/
protected $operands;
public function __construct()
{
parent::__construct();
$this->operands = new ArrayCollection();
}
public function getResult(): ResultInterface
{
if ($this->result) {
return $this->result;
}
throw new NotProcessedException('No result was generated!');
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Entity\Source\Operation;
use App\Logic\Result\Result;
use Doctrine\ORM\Mapping as ORM;
use App\Exception\NotDefinedException;
/**
* @author kevinfrantz
* @ORM\Entity()
*
* @todo move to the logic level!
*/
class AndOperation extends AbstractOperation implements AndOperationInterface
{
public function process(): void
{
if ($this->operands->isEmpty()) {
throw new NotDefinedException('Operands must be defined!');
}
$this->result = new Result();
/*
* @var OperandInterface
*/
foreach ($this->operands->toArray() as $operand) {
if (!$operand->getResult()->getBool()) {
$this->result->setAll(false);
return;
}
}
$this->result->setAll(true);
}
}

View File

@@ -0,0 +1,7 @@
<?php
namespace App\Entity\Source\Operation;
interface AndOperationInterface extends OperationInterface
{
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Entity\Source\Operation\Attribut;
use Doctrine\Common\Collections\Collection;
trait OperandsAttribut
{
/**
* @var Collection
*/
protected $operands;
/**
* @param Collection $collection
*/
public function setOperands(Collection $operands): void
{
$this->operands = $operands;
}
/**
* @return Collection
*/
public function getOperands(): Collection
{
return $this->operands;
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Entity\Source\Operation\Attribut;
use Doctrine\Common\Collections\Collection;
interface OperandsAttributInterface
{
/**
* @param Collection $collection
*/
public function setOperands(Collection $operands): void;
/**
* @return Collection
*/
public function getOperands(): Collection;
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Entity\Source\Operation;
use App\Entity\Source\Operation\Attribut\OperandsAttributInterface;
use App\Logic\Operation\OperationInterface as OperationInterfaceOrigine;
interface OperationInterface extends OperandsAttributInterface, OperationInterfaceOrigine
{
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Entity\Source\Primitive;
use App\Entity\Source\AbstractSource;
/**
* @author kevinfrantz
*/
abstract class AbstractPrimitiveSource extends AbstractSource implements PrimitiveSourceInterface
{
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Entity\Source\Primitive\Name;
use App\Entity\Source\Primitive\AbstractPrimitiveSource;
use App\Entity\Attribut\NameAttribut;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @author kevinfrantz
*/
class AbstractNameSource extends AbstractPrimitiveSource implements NameSourceInterface
{
use NameAttribut;
/**
* @ORM\Column(type="string",length=255)
* @Assert\NotBlank()
*
* @var string
*/
protected $name;
public function __construct()
{
parent::__construct();
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Entity\Source\Primitive\Name;
use Doctrine\ORM\Mapping as ORM;
/**
* @author kevinfrantz
* @ORM\Entity()
*/
class FirstNameSource extends AbstractNameSource implements FirstNameSourceInterface
{
}

View File

@@ -0,0 +1,7 @@
<?php
namespace App\Entity\Source\Primitive\Name;
interface FirstNameSourceInterface extends NameSourceInterface
{
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Entity\Source\Primitive\Name;
use App\Entity\Source\Primitive\PrimitiveSourceInterface;
use App\Entity\Attribut\NameAttributInterface;
interface NameSourceInterface extends PrimitiveSourceInterface, NameAttributInterface
{
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Entity\Source\Primitive\Name;
use Doctrine\ORM\Mapping as ORM;
/**
* @author kevinfrantz
* @ORM\Entity()
*/
class NicknameSource extends AbstractNameSource implements NicknameSourceInterface
{
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Entity\Source\Primitive\Name;
/**
* @author kevinfrantz
*/
interface NicknameSourceInterface extends NameSourceInterface
{
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Entity\Source\Primitive\Name;
use Doctrine\ORM\Mapping as ORM;
/**
* @author kevinfrantz
* @ORM\Entity()
*/
class SurnameSource extends AbstractNameSource implements SurnameSourceInterface
{
}

View File

@@ -0,0 +1,7 @@
<?php
namespace App\Entity\Source\Primitive\Name;
interface SurnameSourceInterface extends NameSourceInterface
{
}

View File

@@ -0,0 +1,14 @@
<?php
namespace App\Entity\Source\Primitive;
use App\Entity\Source\SourceInterface;
/**
* Primitive sources contain one attribut, which is not a source.
*
* @author kevinfrantz
*/
interface PrimitiveSourceInterface extends SourceInterface
{
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Entity\Source\Primitive\Text;
use App\Entity\Source\Primitive\AbstractPrimitiveSource;
use App\Entity\Attribut\TextAttribut;
use Doctrine\ORM\Mapping as ORM;
/**
* @author kevinfrantz
* @ORM\Entity
*/
class TextSource extends AbstractPrimitiveSource implements TextSourceInterface
{
use TextAttribut;
/**
* @ORM\Column(type="string")
*
* @var string
*/
protected $text;
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Entity\Source\Primitive\Text;
use App\Entity\Source\Primitive\PrimitiveSourceInterface;
use App\Entity\Attribut\TextAttributInterface;
interface TextSourceInterface extends PrimitiveSourceInterface, TextAttributInterface
{
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Entity\Source;
use Doctrine\ORM\Mapping as ORM;
/**
* This class represents a source with no additional attributes
* Never inhiere from this!
* Use instead AbstractSource!
*
* @author kevinfrantz
* @ORM\Entity
*/
class PureSource extends AbstractSource implements PureSourceInterface
{
public function __construct()
{
parent::__construct();
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Entity\Source;
/**
* @author kevinfrantz
*/
interface PureSourceInterface extends SourceInterface
{
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Entity\Source;
use App\Entity\Attribut\IdAttributInterface;
use App\Entity\EntityInterface;
use App\Entity\Attribut\LawAttributInterface;
use App\Entity\Attribut\SlugAttributInterface;
use App\Entity\Attribut\CreatorRelationAttributInterface;
use App\Entity\Attribut\MemberRelationAttributInterface;
/**
* @author kevinfrantz
*/
interface SourceInterface extends IdAttributInterface, EntityInterface, LawAttributInterface, SlugAttributInterface, CreatorRelationAttributInterface, MemberRelationAttributInterface
{
}