Implemented injection of RequestedEntityService to RequestedRightService

This commit is contained in:
Kevin Frantz 2019-02-13 16:26:32 +01:00
parent 6563a9fb5a
commit aafde4c0f9
9 changed files with 408 additions and 337 deletions

View File

@ -28,6 +28,14 @@ abstract class AbstractAction extends AbstractActionConstructor implements Actio
*/
abstract protected function proccess();
/**
* This function can be implemented in the child classes for preparation.
*/
protected function prepare(): void
{
return;
}
/**
* @throws \Exception
*
@ -37,6 +45,7 @@ abstract class AbstractAction extends AbstractActionConstructor implements Actio
*/
final public function execute()
{
$this->prepare();
if ($this->isSecure()) {
if ($this->isValid()) {
return $this->proccess();

View File

@ -5,6 +5,7 @@ namespace App\Domain\ActionManagement\Create;
use App\Domain\SourceManagement\SourceClassInformationService;
use App\Form\Source\SourceType;
use App\Entity\Source\AbstractSource;
use Symfony\Component\Form\Form;
/**
* @author kevinfrantz
@ -23,15 +24,36 @@ final class CreateSourceAction extends AbstractCreateAction
*/
private $sourceClass;
/**
* @var Form
*/
private $form;
private function setSourceClass(): void
{
$request = $this->actionService->getRequest();
$this->sourceClass = $request->get(SourceType::CLASS_PARAMETER_NAME, self::DEFAULT_CLASS);
}
private function prepare(): void
private function setFormClass(): void
{
$this->form = $this->actionService->getCurrentFormBuilder()->getForm();
}
private function handleRequest(): void
{
$this->form->handleRequest($this->actionService->getRequest());
}
/**
* {@inheritdoc}
*
* @see \App\Domain\ActionManagement\AbstractAction::prepare()
*/
protected function prepare(): void
{
$this->setSourceClass();
$this->setFormClass();
}
/**
@ -41,7 +63,7 @@ final class CreateSourceAction extends AbstractCreateAction
*/
protected function isValid(): bool
{
return $this->actionService->getCurrentFormBuilder()->getForm()->isValid();
return $this->form->isValid();
}
/**

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 296 KiB

After

Width:  |  Height:  |  Size: 297 KiB

View File

@ -11,6 +11,7 @@ use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\Attribut\RequestedEntityAttribut;
use App\Entity\Meta\MetaInterface;
use App\Exception\NotCorrectInstanceException;
use App\Domain\RequestManagement\Entity\RequestedEntity;
/**
* @author kevinfrantz
@ -56,6 +57,16 @@ class RequestedRight implements RequestedRightInterface
throw new PreconditionFailedException(get_class($this->requestedEntity).' needs to have a defined attribut id or slug!');
}
/**
* @param RequestedEntity|null $requestedEntity
*/
public function __construct(?RequestedEntity $requestedEntity = null)
{
if ($requestedEntity) {
$this->setRequestedEntity($requestedEntity);
}
}
/**
* Uses some kind of Lazy loading.
*

View File

@ -2,6 +2,8 @@
namespace App\Domain\RequestManagement\Right;
use App\Domain\RequestManagement\Entity\RequestedEntityServiceInterface;
/**
* Allows to use a right as a Service.
*
@ -9,4 +11,11 @@ namespace App\Domain\RequestManagement\Right;
*/
final class RequestedRightService extends RequestedRight implements RequestedRightServiceInterface
{
/**
* @param RequestedEntityServiceInterface $requestedEntityService
*/
public function __construct(RequestedEntityServiceInterface $requestedEntityService)
{
parent::__construct($requestedEntityService);
}
}

View File

@ -18,7 +18,10 @@ use App\DBAL\Types\ActionType;
use App\Domain\RequestManagement\User\RequestedUserService;
use App\Domain\UserManagement\UserSourceDirectorService;
use Symfony\Component\Security\Core\Security;
use App\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
use Symfony\Component\HttpFoundation\Request;
use App\Domain\FormManagement\RequestedActionFormBuilderService;
use App\Domain\FormManagement\FormClassNameService;
use App\Domain\RequestManagement\Entity\RequestedEntityService;
/**
* @todo Implement test and logic!!!!!
@ -42,20 +45,30 @@ class CreateSourceActionIntegrationTest extends KernelTestCase
*/
private $requestedActionService;
/**
* @var Request
*/
private $request;
public function setUp(): void
{
self::bootKernel();
$formFactory = self::$container->get('form.factory');
$entityManager = static::$kernel->getContainer()
->get('doctrine')
->getManager();
$security = $this->createMock(Security::class);
$userSourceDirectorService = new UserSourceDirectorService($entityManager, $security);
$requestedRightService = new RequestedRightService();
$requestedEntityService = new RequestedEntityService();
$requestedRightService = new RequestedRightService($requestedEntityService);
$requestedUserService = new RequestedUserService($userSourceDirectorService, $requestedRightService);
$this->requestedActionService = new RequestedActionService($requestedUserService);
$this->requestedActionService->setActionType(ActionType::CREATE);
$entityFormBuilderService = $this->createMock(RequestedActionFormBuilderServiceInterface::class);
$formClassNameService = new FormClassNameService();
$entityFormBuilderService = new RequestedActionFormBuilderService($formFactory, $formClassNameService, $this->requestedActionService);
$this->request = new Request();
$requestStack = $this->createMock(RequestStack::class);
$requestStack->method('getCurrentRequest')->willReturn($this->request);
$layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
$secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerInterface::class);
$this->actionService = new ActionService($this->requestedActionService, $secureRequestedRightChecker, $requestStack, $layerRepositoryFactoryService, $entityFormBuilderService, $entityManager);

View File

@ -54,7 +54,7 @@ class RequestedActionFormBuilderServiceIntegrationTest extends KernelTestCase
$formClassNameService = new FormClassNameService();
$layerRepositoryFactoryService = new LayerRepositoryFactoryService($entityManager);
$this->requestedEntity = new RequestedEntityService($layerRepositoryFactoryService);
$requestedRightService = new RequestedRightService();
$requestedRightService = new RequestedRightService($this->requestedEntity);
$requestedRightService->setRequestedEntity($this->requestedEntity);
$requestedUserService = new RequestedUserService($userSourceDirectorService, $requestedRightService);
$this->requestedActionService = new RequestedActionService($requestedUserService);

View File

@ -11,7 +11,6 @@ use App\Entity\Source\AbstractSource;
use App\Domain\UserManagement\UserSourceDirectorInterface;
use App\Domain\RequestManagement\Right\RequestedRightInterface;
use App\Domain\RequestManagement\Right\RequestedRight;
use App\Repository\Source\SourceRepositoryInterface;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\DBAL\Types\SystemSlugType;
use App\Exception\SetNotPossibleException;
@ -66,8 +65,7 @@ class AbstractRequestedRightFacadeTest extends TestCase
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
$requestedEntity->method('getSlug')->willReturn(SystemSlugType::IMPRINT);
$requestedEntity->method('hasSlug')->willReturn(true);
$sourceRepository = $this->createMock(SourceRepositoryInterface::class);
$requestedRight = new RequestedRight($sourceRepository);
$requestedRight = new RequestedRight();
$requestedRightFacade = $this->getRequestedRightFacade($requestedRight);
$this->assertNull($requestedRightFacade->setLayer($layer));
$this->assertNull($requestedRightFacade->setCrud($type));