In between commit implementing crud draft

This commit is contained in:
Kevin Frantz
2019-01-08 22:06:25 +01:00
parent 814fa978e0
commit 06540ce030
24 changed files with 237 additions and 126 deletions

View File

@@ -1,10 +0,0 @@
<?php
namespace App\Domain\SecureCRUDManagement\CRUD;
/**
* @author kevinfrantz
*/
abstract class AbstractSecureCRUD implements SecureCRUDInterface
{
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Domain\SecureCRUDManagement\CRUD;
use App\Domain\SecureCRUDManagement\AbstractSecureCRUDService as AbstractSecureCRUDServiceParent;
/**
* @author kevinfrantz
*/
abstract class AbstractSecureCRUDService extends AbstractSecureCRUDServiceParent implements SecureCRUDServiceInterface
{
}

View File

@@ -1,12 +0,0 @@
<?php
namespace App\Domain\SecureCRUDManagement\CRUD\Create;
use App\Domain\SecureCRUDManagement\CRUD\AbstractSecureCRUD;
/**
* @author kevinfrantz
*/
abstract class AbstractSecureCreate extends AbstractSecureCRUD implements SecureCreateInterface
{
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Domain\SecureCRUDManagement\CRUD\Create;
use App\Domain\SecureCRUDManagement\CRUD\AbstractSecureCRUDService;
/**
* @author kevinfrantz
*/
abstract class AbstractSecureCreateService extends AbstractSecureCRUDService implements SecureCreateServiceInterface
{
}

View File

@@ -3,14 +3,14 @@
namespace App\Domain\SecureCRUDManagement\CRUD\Create;
use App\Entity\EntityInterface;
use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDInterface;
use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDServiceInterface;
/**
* @todo Implement!
*
* @author kevinfrantz
*/
interface SecureCreateInterface extends SecureCRUDInterface
interface SecureCreateServiceInterface extends SecureCRUDServiceInterface
{
/**
* @return EntityInterface The created entity

View File

@@ -7,7 +7,7 @@ use App\Entity\EntityInterface;
/**
* @author kevinfrantz
*/
final class SecureHeredityCreate extends AbstractSecureCreate
final class SecureHeredityCreateService extends AbstractSecureCreateService
{
/**
* @todo Implement

View File

@@ -7,7 +7,7 @@ use App\Entity\EntityInterface;
/**
* @author kevinfrantz
*/
final class SecureMemberCreate extends AbstractSecureCreate
final class SecureMemberCreateService extends AbstractSecureCreateService
{
public function create(): EntityInterface
{

View File

@@ -7,7 +7,7 @@ use App\Entity\EntityInterface;
/**
* @author kevinfrantz
*/
final class SecureRightCreate extends AbstractSecureCreate
final class SecureRightCreateService extends AbstractSecureCreateService
{
/**
* @todo Implement!

View File

@@ -10,12 +10,10 @@ use App\Entity\Source\Primitive\Text\TextSource;
*
* @todo Implement!
*/
final class SecureSourceCreate extends AbstractSecureCreate
final class SecureSourceCreateService extends AbstractSecureCreateService
{
/**
* {@inheritdoc}
*
* @see \App\Domain\SecureCRUDManagement\CRUD\Create\SecureCreatorInterface::create()
* @return EntityInterface
*/
public function create(): EntityInterface
{

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
use App\Domain\SecureCRUDManagement\CRUD\AbstractSecureCRUDService;
/**
* @author kevinfrantz
*/
abstract class AbstractSecureReadService extends AbstractSecureCRUDService implements SecureReadServiceInterface
{
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
use App\Entity\EntityInterface;
use App\Entity\Meta\RightInterface;
/**
* @author kevinfrantz
*/
final class SecureLawReadService extends AbstractSecureReadService
{
/**
* {@inheritdoc}
*
* @see \App\Domain\SecureCRUDManagement\CRUD\Read\SecureReadServiceInterface::read()
*/
public function read(RightInterface $requestedRight): EntityInterface
{
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
use App\Entity\EntityInterface;
use App\Entity\Meta\RightInterface;
/**
* @author kevinfrantz
*/
class SecureMemberReadService extends AbstractSecureReadService
{
/**
* {@inheritdoc}
*
* @see \App\Domain\SecureCRUDManagement\CRUD\Read\SecureReadServiceInterface::read()
*/
public function read(RightInterface $requestedRight): EntityInterface
{
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
use App\Domain\SecureCRUDManagement\CRUD\SecureCRUDServiceInterface;
use App\Entity\EntityInterface;
use App\Entity\Meta\RightInterface;
/**
* @author kevinfrantz
*/
interface SecureReadServiceInterface extends SecureCRUDServiceInterface
{
/**
* @param RightInterface $requestedRight
*
* @return EntityInterface
*/
public function read(RightInterface $requestedRight): EntityInterface;
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
use App\Entity\EntityInterface;
use App\Entity\Meta\RightInterface;
/**
* @author kevinfrantz
*/
final class SecureRightReadService extends AbstractSecureReadService
{
/**
* {@inheritdoc}
*
* @see \App\Domain\SecureCRUDManagement\CRUD\Read\SecureReadServiceInterface::read()
*/
public function read(RightInterface $requestedRight): EntityInterface
{
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
use App\Entity\Source\SourceInterface;
use App\Entity\Meta\RightInterface;
use Doctrine\Common\Persistence\ObjectRepository;
use App\Domain\SecureManagement\SecureSourceChecker;
use App\Exception\SourceAccessDenied;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Source\AbstractSource;
use App\Domain\SecureCRUDManagement\CRUD\AbstractSecureCRUDService;
use App\Entity\EntityInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;
/**
* @author kevinfrantz
*/
final class SecureSourceReadService extends AbstractSecureCRUDService //implements SecureSourceReadServiceInterface
{
/**
* @todo It would be better to specify the type
*
* @var ObjectRepository
*/
private $sourceRepository;
/**
* @param SourceInterface $source
*
* @return RightInterface
*/
private function getClonedRightWithModifiedSource(SourceInterface $source, RightInterface $requestedRight): RightInterface
{
$requestedRight = clone $requestedRight;
$requestedRight->setSource($source);
return $requestedRight;
}
/**
* @return SourceInterface
*/
private function loadSource(): SourceInterface
{
try {
return $this->sourceRepository->find($this->requestedRight->getSource()->getId());
} catch (\Error $error) {
return $this->sourceRepository->findOneBySlug($this->requestedRight->getSource()->getSlug());
}
}
/**
* {@inheritdoc}
*
* @see \App\Domain\SecureCRUDManagement\AbstractSecureCRUDService::__construct()
*/
public function __construct(RequestStack $requestStack, Security $security, EntityManagerInterface $entityManager)
{
$this->sourceRepository = $entityManager->getRepository(AbstractSource::class);
parent::__construct($requestStack, $security, $entityManager);
}
/**
* @param RightInterface $requestedRight
*
* @return EntityInterface
*/
public function read(RightInterface $requestedRight): EntityInterface
{
$source = $this->loadSource();
$requestedRight = $this->getClonedRightWithModifiedSource($source, $requestedRight);
$secureSourceChecker = new SecureSourceChecker($source);
if ($secureSourceChecker->hasPermission($requestedRight)) {
return $source;
}
throw new SourceAccessDenied();
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Domain\SecureCRUDManagement\CRUD\Read;
/**
* @author kevinfrantz
*/
interface SecureSourceReadServiceInterface extends SecureReadServiceInterface
{
}

View File

@@ -7,6 +7,6 @@ namespace App\Domain\SecureCRUDManagement\CRUD;
*
* @author kevinfrantz
*/
interface SecureCRUDInterface
interface SecureCRUDServiceInterface
{
}