In between commit implementing security layer

This commit is contained in:
Kevin Frantz 2018-09-22 02:12:03 +02:00
parent bbcf369347
commit d255623f85
8 changed files with 129 additions and 38 deletions

View File

@ -0,0 +1,28 @@
<?php
namespace Creator\Factory;
use App\Entity\SourceInterface;
/**
* @author kevinfrantz
*/
class AbstractSourceFactory
{
/**
* @var SourceInterface
*/
protected $source;
public function __construct(SourceInterface $source)
{
$this->source = $source;
}
protected function getSourceClassShortName(): string
{
$reflection = new \ReflectionClass($this->source);
return $reflection->getShortName();
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace App\Creator\Factory\Facade\Security;
use App\Structur\Facade\Security\Source\interfaces\SourceFacadeInterface;
/**
* @author kevinfrantz
*/
final class SourceFacadeFactory
{
public function getSourceFacade(): SourceFacadeInterface
{
$className = $this->getSourceFacadeClassName();
return new $className();
}
private function getSourceFacadeClassName(): string
{
return 'App\Structur\Facade\Security\Source\\'.$this->getSourceFacadeClassName().'Facade';
}
}

View File

@ -2,25 +2,15 @@
namespace App\Creator\Factory\Form\Source; namespace App\Creator\Factory\Form\Source;
use App\Entity\SourceInterface; use Creator\Factory\AbstractSourceFactory;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
class SourceFormFactory final class SourceFormFactory extends AbstractSourceFactory
{ {
const FORM_NAMESPACE = 'App\Form\\'; const FORM_NAMESPACE = 'App\Form\\';
/**
* @var SourceInterface
*/
private $source;
public function __construct(SourceInterface $source)
{
$this->source = $source;
}
public function getNamespace(): string public function getNamespace(): string
{ {
return self::FORM_NAMESPACE.$this->getName(); return self::FORM_NAMESPACE.$this->getName();
@ -28,8 +18,6 @@ class SourceFormFactory
protected function getName(): string protected function getName(): string
{ {
$reflectionClass = new \ReflectionClass($this->source); return $this->getSourceClassShortName().'Type';
return $reflectionClass->getShortName().'Type';
} }
} }

View File

@ -4,21 +4,17 @@ namespace App\Creator\Factory\Template\Source;
use App\Entity\SourceInterface; use App\Entity\SourceInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Creator\Factory\AbstractSourceFactory;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
class SourceTemplateFactory class SourceTemplateFactory extends AbstractSourceFactory
{ {
const SOURCE_TEMPLATE_ROOT = 'source'; const SOURCE_TEMPLATE_ROOT = 'source';
const VIEW_FOLDER = 'view'; const VIEW_FOLDER = 'view';
/**
* @var SourceInterface
*/
protected $source;
/** /**
* @var Request * @var Request
*/ */
@ -29,7 +25,7 @@ class SourceTemplateFactory
*/ */
public function __construct(SourceInterface $source, Request $request) public function __construct(SourceInterface $source, Request $request)
{ {
$this->source = $source; parent::__construct($source);
$this->request = $request; $this->request = $request;
} }
@ -40,9 +36,7 @@ class SourceTemplateFactory
protected function generateName(): string protected function generateName(): string
{ {
$reflection = new \ReflectionClass($this->source); $lowerName = strtolower($this->getSourceClassShortName());
$shortName = $reflection->getShortName();
$lowerName = strtolower($shortName);
return str_replace('source', '', $lowerName); return str_replace('source', '', $lowerName);
} }

View File

@ -5,7 +5,7 @@ namespace App\Creator\Factory\Template\Source;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
class SourceTemplateFormFactory extends SourceTemplateFactory final class SourceTemplateFormFactory extends SourceTemplateFactory
{ {
const FORM_FOLDER = 'form'; const FORM_FOLDER = 'form';

View File

@ -1,27 +1,25 @@
<?php <?php
namespace App\Structur\Facade\Security;
namespace App\Structur\Facade\Security\Source;
use App\Entity\NodeInterface; use App\Entity\NodeInterface;
use App\Entity\SourceInterface; use App\Entity\SourceInterface;
use App\Entity\User; use App\Entity\User;
use App\DBAL\Types\RightType; use App\DBAL\Types\RightType;
use App\DBAL\Types\LayerType; use App\DBAL\Types\LayerType;
use App\Structur\Facade\Security\Source\interfaces\SourceFacadeInterface;
/** /**
*
* @author kevinfrantz * @author kevinfrantz
*
*/ */
abstract class AbstractSourceFasade implements SourceInterface abstract class AbstractSourceFacade implements SourceFacadeInterface
{ {
/** /**
*
* @var User * @var User
*/ */
protected static $user; protected static $user;
/** /**
*
* @var SourceInterface * @var SourceInterface
*/ */
protected $source; protected $source;
@ -30,7 +28,7 @@ abstract class AbstractSourceFasade implements SourceInterface
{ {
self::$user = $user; self::$user = $user;
} }
public function __construct(SourceInterface $source) public function __construct(SourceInterface $source)
{ {
$this->source = $source; $this->source = $source;
@ -48,24 +46,27 @@ abstract class AbstractSourceFasade implements SourceInterface
public function getId(): int public function getId(): int
{ {
if($this->isGranted(RightType::READ)){ if ($this->isGranted(RightType::READ)) {
return $source->getId(); return $source->getId();
} }
} }
public function getNode(): NodeInterface public function getNode(): NodeInterface
{ {
if($this->isGranted(RightType::READ,LayerType::NODE)){ if ($this->isGranted(RightType::READ, LayerType::NODE)) {
return $source->getId(); return $source->getNode();
} }
} }
protected function isGranted(string $right,string $layer): bool protected function isGranted(string $right, string $layer): bool
{ {
return $this->getNode() return $this->getNode()
->getLaw() ->getLaw()
->isGranted(self::$user->getSource() ->isGranted(self::$user->getSource()
->getNode(), self::$layer, $right); ->getNode(), self::$layer, $right);
} }
}
protected function lazyLoadSourceFacade(SourceInterface $source)
{
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace App\Structur\Facade\Security\Source;
use App\Entity\NameSourceInterface;
use App\Entity\User;
use App\Entity\UserSourceInterface;
use App\DBAL\Types\RightType;
use App\DBAL\Types\LayerType;
/**
* @author kevinfrantz
*/
class UserSourceFacade extends AbstractSourceFacade implements UserSourceInterface
{
/**
* @var UserSourceInterface
*/
protected $source;
public function setNameSource(NameSourceInterface $nameSource): void
{
throw new \Exception('The name source cant be changed!');
}
public function getNameSource(): NameSourceInterface
{
if ($this->isNameSourceGranted(RightType::READ, LayerType::SOURCE)) {
//FILL! :)
}
}
private function isNameSourceGranted(string $right, string $layer): bool
{
$nameSource = $this->source->getNameSource();
$law = $nameSource->getNode()->getLaw();
$userSourceNode = $this->source->getNode();
return $this->isGranted($right, $layer) && $law->isGranted($userSourceNode, $layer, $right);
}
public function getUser(): User
{
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Structur\Facade\Security\Source\interfaces;
use App\Entity\SourceInterface;
/**
* @author kevinfrantz
*/
interface SourceFacadeInterface extends SourceInterface
{
}