From a857f515d399b4b967d05f6431e7f26b1911dd22 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Thu, 6 Sep 2018 15:14:33 +0200 Subject: [PATCH] Optimized ORM-Structure --- .../src/Entity/Attribut/ChildsAttribut.php | 12 ++++++-- .../src/Entity/Attribut/ParentAttribut.php | 16 ++++++++--- .../src/Entity/Attribut/PasswordAttribut.php | 24 ++++++++++++++++ .../src/Entity/Attribut/UsernameAttribut.php | 25 +++++++++++++++++ application/src/Entity/Node.php | 28 +++---------------- application/src/Entity/User.php | 28 ++++--------------- application/src/Entity/UserInterface.php | 14 ++++++++++ 7 files changed, 95 insertions(+), 52 deletions(-) create mode 100644 application/src/Entity/Attribut/PasswordAttribut.php create mode 100644 application/src/Entity/Attribut/UsernameAttribut.php create mode 100644 application/src/Entity/UserInterface.php diff --git a/application/src/Entity/Attribut/ChildsAttribut.php b/application/src/Entity/Attribut/ChildsAttribut.php index 6583485..376df67 100644 --- a/application/src/Entity/Attribut/ChildsAttribut.php +++ b/application/src/Entity/Attribut/ChildsAttribut.php @@ -2,6 +2,8 @@ namespace App\Entity\Attribut; use Doctrine\Common\Collections\ArrayCollection; +use App\Entity\NodeInterface; + /** * * @author kevinfrantz @@ -9,8 +11,14 @@ use Doctrine\Common\Collections\ArrayCollection; */ trait ChildsAttribut { -/** - * @var ArrayCollection + /** + * Many Nodes have many childs + * @ORM\ManyToMany(targetEntity="Node") + * @ORM\JoinTable(name="nodes_childs", + * joinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")}, + * inverseJoinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")} + * ) + * @var ArrayCollection|NodeInterface[] */ protected $childs; diff --git a/application/src/Entity/Attribut/ParentAttribut.php b/application/src/Entity/Attribut/ParentAttribut.php index 0d70389..af2a50e 100644 --- a/application/src/Entity/Attribut/ParentAttribut.php +++ b/application/src/Entity/Attribut/ParentAttribut.php @@ -2,6 +2,7 @@ namespace App\Entity\Attribut; use Doctrine\Common\Collections\ArrayCollection; +use App\Entity\NodeInterface; /** * @@ -9,17 +10,24 @@ use Doctrine\Common\Collections\ArrayCollection; * */ trait ParentAttribut { - + /** - * @var ArrayCollection + * Many Nodes have many parents + * + * @ORM\ManyToMany(targetEntity="Node") + * @ORM\JoinTable(name="nodes_parents", + * joinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")}, + * inverseJoinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")} + * ) + * @var ArrayCollection|NodeInterface[] */ protected $parents; - + public function getParents(): ArrayCollection { return $this->parents; } - + public function setParents(ArrayCollection $parents): void { $this->parents = $parents; diff --git a/application/src/Entity/Attribut/PasswordAttribut.php b/application/src/Entity/Attribut/PasswordAttribut.php new file mode 100644 index 0000000..3e56611 --- /dev/null +++ b/application/src/Entity/Attribut/PasswordAttribut.php @@ -0,0 +1,24 @@ +password; + } + + public function setPassword(string $password):void{ + $this->password = $password; + } +} + diff --git a/application/src/Entity/Attribut/UsernameAttribut.php b/application/src/Entity/Attribut/UsernameAttribut.php new file mode 100644 index 0000000..73ac756 --- /dev/null +++ b/application/src/Entity/Attribut/UsernameAttribut.php @@ -0,0 +1,25 @@ +username; + } + + public function setUsernames(string $username):void{ + $this->username = $username; + } +} + diff --git a/application/src/Entity/Node.php b/application/src/Entity/Node.php index 99f41f7..a5aff20 100644 --- a/application/src/Entity/Node.php +++ b/application/src/Entity/Node.php @@ -2,7 +2,6 @@ namespace App\Entity; use Doctrine\ORM\Mapping as ORM; -use Doctrine\Common\Collections\ArrayCollection; use App\Entity\Attribut\IdAttribut; use App\Entity\Attribut\SourceAttribut; use App\Entity\Attribut\ParentAttribut; @@ -16,28 +15,9 @@ use App\Entity\Attribut\ChildsAttribut; */ class Node implements NodeInterface { - use IdAttribut,SourceAttribut, ParentAttribut, ChildsAttribut; - - /** - * Many Nodes have many parents - * @ORM\ManyToMany(targetEntity="Node") - * @ORM\JoinTable(name="nodes_parents", - * joinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")}, - * inverseJoinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")} - * ) - * @var ArrayCollection|Node[] - */ - protected $parents; - - /** - * Many Nodes have many childs - * @ORM\ManyToMany(targetEntity="Node") - * @ORM\JoinTable(name="nodes_childs", - * joinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")}, - * inverseJoinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")} - * ) - * @var ArrayCollection|Node[] - */ - protected $childs; + use IdAttribut, + SourceAttribut, + ParentAttribut, + ChildsAttribut; } diff --git a/application/src/Entity/User.php b/application/src/Entity/User.php index bcf608b..8497b8b 100644 --- a/application/src/Entity/User.php +++ b/application/src/Entity/User.php @@ -1,26 +1,20 @@ salt = md5(uniqid('', true)); } - public function getUsername() - { - return $this->username; - } - public function getSalt() { // you *may* need a real salt depending on your encoder @@ -50,11 +39,6 @@ class User extends AbstractSource implements UserInterface, \Serializable return null; } - public function getPassword() - { - return $this->password; - } - public function getRoles() { return array('ROLE_USER'); diff --git a/application/src/Entity/UserInterface.php b/application/src/Entity/UserInterface.php new file mode 100644 index 0000000..e5e99dc --- /dev/null +++ b/application/src/Entity/UserInterface.php @@ -0,0 +1,14 @@ +