Optimized template draft

This commit is contained in:
Kevin Frantz
2019-02-25 12:50:26 +01:00
parent d0adc9b42a
commit 2cf9e019e8
22 changed files with 208 additions and 178 deletions

View File

@@ -10,6 +10,12 @@ use Infinito\Domain\RequestManagement\Entity\RequestedEntityServiceInterface;
use Infinito\Exception\NotCorrectInstanceException;
/**
* This class is not ready and not tested!
*
* @todo Implement tests!
* @todo finish class!
* @todo refactor class!
*
* @author kevinfrantz
*/
final class EntityDomService implements EntityDomServiceInterface

View File

@@ -10,9 +10,13 @@ use Infinito\Attribut\ActionTypeAttribut;
use Infinito\DBAL\Types\ActionType;
use Infinito\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
use Infinito\Domain\RequestManagement\Action\RequestedActionServiceInterface;
use Infinito\Domain\SecureManagement\SecureRequestedRightCheckerServiceInterface;
/**
* @author kevinfrantz
*
* @todo Refactor this class
* @todo Test this class
*/
final class MVCRoutineService implements MVCRoutineServiceInterface
{
@@ -48,6 +52,11 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
*/
private $requestedActionService;
/**
* @var SecureRequestedRightCheckerServiceInterface
*/
private $secureRequestedRightCheckerService;
/**
* @return View
*/
@@ -62,13 +71,14 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
/**
* @param ActionHandlerServiceInterface $actionHandlerService
*/
public function __construct(ActionHandlerServiceInterface $actionHandlerService, TemplateNameServiceInterface $templateNameService, ActionTemplateDataStoreServiceInterface $actionTemplateDataStore, RequestedActionFormBuilderServiceInterface $requestedActionFormBuilderService, RequestedActionServiceInterface $requestedActionService)
public function __construct(ActionHandlerServiceInterface $actionHandlerService, TemplateNameServiceInterface $templateNameService, ActionTemplateDataStoreServiceInterface $actionTemplateDataStore, RequestedActionFormBuilderServiceInterface $requestedActionFormBuilderService, RequestedActionServiceInterface $requestedActionService, SecureRequestedRightCheckerServiceInterface $secureRequestedRightCheckerService)
{
$this->actionHandlerService = $actionHandlerService;
$this->templateNameService = $templateNameService;
$this->actionTemplateDataStore = $actionTemplateDataStore;
$this->requestedActionFormBuilderService = $requestedActionFormBuilderService;
$this->requestedActionService = $requestedActionService;
$this->secureRequestedRightCheckerService = $secureRequestedRightCheckerService;
}
/**
@@ -80,17 +90,29 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
public function process(): View
{
if (!$this->actionType) {
//UPDATE
$this->requestedActionService->setActionType(ActionType::CREATE);
$updateForm = $this->requestedActionFormBuilderService->createByService()->getForm()->createView();
$this->actionTemplateDataStore->setData(ActionType::UPDATE, $updateForm);
//READ
$this->requestedActionService->setActionType(ActionType::READ);
$read = $this->actionHandlerService->handle();
$this->actionTemplateDataStore->setData(ActionType::READ, $read);
$view = $this->getView();
if ($this->requestedActionService->hasRequestedEntity()) {
//READ
$this->requestedActionService->setActionType(ActionType::READ);
if ($this->secureRequestedRightCheckerService->check($this->requestedActionService)) {
$read = $this->actionHandlerService->handle();
$this->actionTemplateDataStore->setData(ActionType::READ, $read);
}
$this->requestedActionService->setActionType(ActionType::UPDATE);
//UPDATE
if ($this->secureRequestedRightCheckerService->check($this->requestedActionService)) {
$updateForm = $this->requestedActionFormBuilderService->createByService()->getForm()->createView();
$this->actionTemplateDataStore->setData(ActionType::UPDATE, $updateForm);
}
//DELETE
//EXECUTE
} else {
//CREATE
$this->requestedActionService->setActionType(ActionType::CREATE);
$updateForm = $this->requestedActionFormBuilderService->createByService()->getForm()->createView();
$this->actionTemplateDataStore->setData(ActionType::CREATE, $updateForm);
}
return $view;
return $this->getView();
}
throw new \Exception('Not implemented yet!');
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Infinito\Domain\TwigManagement;
use Infinito\Exception\NotSetException;
use Infinito\DBAL\Types\Meta\Right\LayerType;
/**
* @author kevinfrantz
*/
final class LayerIconClassMap implements LayerIconClassMapInterface
{
/**
* @var array|string[]
*/
const LAYER_ICON_CLASS_MAP = [
LayerType::SOURCE => 'fas fa-tint',
LayerType::LAW => 'fas fa-gavel',
LayerType::RIGHT => 'fas fa-check',
LayerType::HEREDITY => 'fas fa-seedling',
LayerType::MEMBER => 'fas fa-users',
LayerType::CREATOR => 'fas fa-bed',
];
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\TwigManagement\LayerIconClassMapInterface::getIconClass()
*/
public function getIconClass(string $layer): string
{
if (key_exists($layer, self::LAYER_ICON_CLASS_MAP)) {
return self::LAYER_ICON_CLASS_MAP[$layer];
}
throw new NotSetException("The key <<$layer>> is not defined in the map!");
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Infinito\Domain\TwigManagement;
/**
* Maps actions to classes.
*
* @author kevinfrantz
*/
interface LayerIconClassMapInterface
{
/**
* @param string $layer
*
* @return string
*/
public function getIconClass(string $layer): string;
}

View File

@@ -11,7 +11,7 @@ use Infinito\Entity\Source\Primitive\Text\TextSource;
/**
* @author kevinfrantz
*/
final class TextSourceCreateType extends SourceType
class TextSourceCreateType extends SourceType
{
/**
* {@inheritdoc}

View File

@@ -0,0 +1,10 @@
<?php
namespace Infinito\Form\Source\Primitive\Text;
/**
* @author kevinfrantz
*/
final class TextSourceUpdateType extends TextSourceCreateType
{
}

View File

@@ -21,27 +21,52 @@ class Menu
*/
private $factory;
/**
* @param FactoryInterface $factory
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(FactoryInterface $factory, EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
$this->factory = $factory;
}
/**
* @param RequestStack $request
*
* @return ItemInterface
*/
public function sourceNavbar(RequestStack $request): ItemInterface
{
return $this->createMenu(MenuEventType::SOURCE, $request);
}
/**
* @param RequestStack $request
*
* @return ItemInterface
*/
public function nodeSubbar(RequestStack $request): ItemInterface
{
return $this->createMenu(MenuEventType::NODE, $request);
}
/**
* @param RequestStack $request
*
* @return ItemInterface
*/
public function userTopbar(RequestStack $request): ItemInterface
{
return $this->createMenu(MenuEventType::USER, $request);
}
/**
* @param string $type
* @param RequestStack $request
*
* @return ItemInterface
*/
private function createMenu(string $type, RequestStack $request): ItemInterface
{
$menu = $this->createBasicMenuItem();
@@ -50,6 +75,9 @@ class Menu
return $menu;
}
/**
* @return ItemInterface
*/
private function createBasicMenuItem(): ItemInterface
{
return $this->factory->createItem('root', [

View File

@@ -10,6 +10,9 @@ use Infinito\Event\Menu\MenuEvent;
use Infinito\DBAL\Types\MenuEventType;
use Infinito\Domain\FixtureManagement\FixtureSource\ImpressumFixtureSource;
/**
* @author kevinfrantz
*/
class UserMenuSubscriber implements EventSubscriberInterface
{
/**
@@ -22,6 +25,10 @@ class UserMenuSubscriber implements EventSubscriberInterface
*/
private $translator;
/**
* @param TokenStorageInterface $tokenStorage
* @param TranslatorInterface $translator
*/
public function __construct(TokenStorageInterface $tokenStorage, TranslatorInterface $translator)
{
$this->tokenStorage = $tokenStorage;
@@ -42,7 +49,7 @@ class UserMenuSubscriber implements EventSubscriberInterface
]);
$menu->addChild($this->translator->trans('imprint'), [
'uri' => 'rest/api/source/'.strtolower(ImpressumFixtureSource::SLUG).'.html',
'uri' => '/api/rest/source/'.strtolower(ImpressumFixtureSource::SLUG).'.html',
'attributes' => [
'icon' => 'fas fa-address-card',
],
@@ -50,6 +57,9 @@ class UserMenuSubscriber implements EventSubscriberInterface
$this->generateUserDropdown($menu);
}
/**
* @param ItemInterface $menu
*/
private function generateUserDropdown(ItemInterface $menu): void
{
$dropdown = $menu->addChild($this->tokenStorage->getToken()
@@ -91,6 +101,9 @@ class UserMenuSubscriber implements EventSubscriberInterface
]);
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [