mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +01:00
Optimized law draft
This commit is contained in:
parent
5f011f632b
commit
b9f483bf7f
@ -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
|
||||
|
25
application/src/DBAL/Types/RightType.php
Normal file
25
application/src/DBAL/Types/RightType.php
Normal 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',
|
||||
];
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
17
application/src/Entity/Attribut/RightsAttributInterface.php
Normal file
17
application/src/Entity/Attribut/RightsAttributInterface.php
Normal 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;
|
||||
}
|
||||
|
26
application/src/Entity/Attribut/RightsAttribute.php
Normal file
26
application/src/Entity/Attribut/RightsAttribute.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
24
application/src/Entity/Attribut/TypeAttribut.php
Normal file
24
application/src/Entity/Attribut/TypeAttribut.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
15
application/src/Entity/Attribut/TypeAttributInterface.php
Normal file
15
application/src/Entity/Attribut/TypeAttributInterface.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
interface TypeAttributInterface
|
||||
{
|
||||
public function setType(string $right):void;
|
||||
|
||||
public function getType():string;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,6 @@ use Entity\Attribut\WhitelistAttributInterface;
|
||||
*/
|
||||
interface PermissionInterface extends BlacklistAttributInterface, WhitelistAttributInterface
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
34
application/src/Entity/Right.php
Normal file
34
application/src/Entity/Right.php
Normal 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
|
||||
{}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user