Optimized law draft

This commit is contained in:
Kevin Frantz 2018-09-13 15:55:48 +02:00
parent 5f011f632b
commit b9f483bf7f
13 changed files with 206 additions and 12 deletions

View File

@ -14,8 +14,9 @@ doctrine:
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
types:
RightType: App\DBAL\Types\RightType
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore

View File

@ -0,0 +1,25 @@
<?php
namespace App\DBAL\Types;
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
/**
*
* @author kevinfrantz
*
*/
final class RightType extends AbstractEnumType
{
public const ADMINISTRATION = 'administration';
public const READ = 'read';
public const WRITE = 'write';
protected static $choices = [
self::ADMINISTRATION => 'administration',
self::READ => 'read',
self::WRITE=>'write',
];
}

View File

@ -1,6 +1,8 @@
<?php
namespace Entity\Attribut;
use App\Entity\RightInterface;
/**
*
* @author kevinfrantz
@ -8,8 +10,8 @@ namespace Entity\Attribut;
*/
interface RightAttributInterface
{
public function setRight(string $right):void;
public function setRight(RightInterface $right):void;
public function getRight():string;
public function getRight():RightInterface;
}

View File

@ -0,0 +1,17 @@
<?php
namespace Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
* @author kevinfrantz
*
*/
interface RightsAttributInterface
{
public function setRights(ArrayCollection $rights):void;
public function getRights():ArrayCollection;
}

View File

@ -0,0 +1,26 @@
<?php
namespace Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
* @author kevinfrantz
*
*/
trait RightsAttribute {
/**
* @var ArrayCollection
*/
protected $rights;
public function setRights(ArrayCollection $rights):void{
$this->rights = $rights;
}
public function getRights():ArrayCollection{
return $this->rights;
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity\Attribut;
/**
*
* @author kevinfrantz
*
*/
trait TypeAttribut {
/**
*
* @var string
*/
protected $type;
public function setType(string $right):void{
$this->type = $type;
}
public function getType():string{
return $this->type;
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Entity\Attribut;
/**
*
* @author kevinfrantz
*
*/
interface TypeAttributInterface
{
public function setType(string $right):void;
public function getType():string;
}

View File

@ -1,15 +1,42 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\NodeAttribut;
use Doctrine\ORM\Mapping as ORM;
use Entity\Attribut\RightsAttribute;
use Doctrine\Common\Collections\ArrayCollection;
use App\DBAL\Types\RightType;
/**
*
* @author kevinfrantz
*
* @ORM\Table(name="law")
* @ORM\Entity(repositoryClass="App\Repository\LawRepository")
*/
class Law implements LawInterface
class Law extends AbstractEntity implements LawInterface
{
use NodeAttribut;
use RightsAttribute;
/**
*
* @ORM\OneToMany(targetEntity="Right", mappedBy="id", cascade={"persist", "remove"})
* @var ArrayCollection
*/
protected $rights;
public function __construct()
{
parent::__contruct();
$this->initAllRights();
}
private function initAllRights(): void
{
foreach (RightType::getChoices() as $key=>$value){
$right = new Right();
$right->setType($value);
$this->rights->set($key, $right);
}
}
}

View File

@ -1,14 +1,15 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\NodeAttributInterface;
use Entity\Attribut\RightsAttributInterface;
/**
*
* @author kevinfrantz
*
*/
interface LawInterface extends NodeAttributInterface
interface LawInterface extends RightsAttributInterface
{
}

View File

@ -22,7 +22,22 @@ class Node extends AbstractEntity implements NodeInterface
LawAttribut,
ChildsAttribut;
/**
* @ORM\OneToOne(targetEntity="AbstractSource",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="source_id", referencedColumnName="id")
* @var SourceInterface
*/
protected $source;
/**
* @ORM\OneToOne(targetEntity="Law",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="law_id", referencedColumnName="id")
* @var LawInterface
*/
protected $law;
public function __construct(){
$this->law = new Law();
$this->law->setNode($this);
}
}

View File

@ -11,5 +11,6 @@ use Entity\Attribut\WhitelistAttributInterface;
*/
interface PermissionInterface extends BlacklistAttributInterface, WhitelistAttributInterface
{
}

View File

@ -0,0 +1,34 @@
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attribut\TypeAttribut;
use App\DBAL\Types\RightType;
use Doctrine\ORM\Mapping as ORM;
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
/**
*
* @author kevinfrantz
* @ORM\Table(name="right")
* @ORM\Entity(repositoryClass="App\Repository\RightRepository")
*/
class Right extends AbstractEntity implements RightInterface
{
use TypeAttribut;
/**
* @ORM\Column(name="type", type="RightType", nullable=false)
* @DoctrineAssert\Enum(entity="App\DBAL\Types\RightType")
* @var string
*/
protected $type;
public function isGranted(NodeInterface $node): bool
{}
public function setPermissions(ArrayCollection $permissions): void
{}
}

View File

@ -1,12 +1,18 @@
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attribut\TypeAttributInterface;
/**
*
* @author kevinfrantz
*
*/
interface RightInterface
interface RightInterface extends TypeAttributInterface
{
}
public function isGranted(NodeInterface $node): bool;
public function setPermissions(ArrayCollection $permissions):void;
}