Implemented ActionTemplateNameService

This commit is contained in:
Kevin Frantz 2019-02-18 22:10:28 +01:00
parent a117d16429
commit aa86cfce98
5 changed files with 78 additions and 4 deletions

View File

@ -6,3 +6,4 @@ twig:
globals:
layer_action_map: "@Infinito\\Domain\\LayerManagement\\LayerActionMap"
action_icon_class_map: "@Infinito\\Domain\\TwigManagement\\ActionIconClassMap"
action_template_name_service: "@Infinito\\Domain\\TemplateManagement\\ActionTemplateNameServiceInterface"

View File

@ -44,6 +44,9 @@ services:
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
# Map Interfaces to concrete classes
Infinito\Domain\TemplateManagement\TemplateNameServiceInterface: "@Infinito\\Domain\\TemplateManagement\\TemplateNameService"
# Needed for integration tests
Infinito\Domain\RequestManagement\Entity\RequestedEntityService:
public: true

View File

@ -0,0 +1,36 @@
<?php
namespace Infinito\Domain\TemplateManagement;
/**
* @author kevinfrantz
*/
final class ActionTemplateNameService extends TemplateNameService implements ActionTemplateNameServiceInterface
{
/**
* @var string
*/
private $actionType;
/**
* @return string
*/
protected function getActionType(): string
{
if ($this->actionType) {
return $this->actionType;
}
return $this->requestedActionService->getActionType();
}
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\TemplateManagement\ActionTemplateNameServiceInterface::setActionType()
*/
public function setActionType(?string $actionType): void
{
$this->actionType = $actionType;
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Infinito\Domain\TemplateManagement;
/**
* Allows to manually define the action type.
*
* @author kevinfrantz
*/
interface ActionTemplateNameServiceInterface extends TemplateNameServiceInterface
{
/**
* {@inheritdoc}
*
* @see \Infinito\Attribut\ActionTypeAttributInterface::setActionType()
*/
public function setActionType(?string $actionType): void;
}

View File

@ -7,7 +7,7 @@ use Infinito\Domain\RequestManagement\Action\RequestedActionServiceInterface;
/**
* @author kevinfrantz
*/
final class TemplateNameService implements TemplateNameServiceInterface
class TemplateNameService implements TemplateNameServiceInterface
{
/**
* @var string The namespace which should be ignored
@ -39,6 +39,22 @@ final class TemplateNameService implements TemplateNameServiceInterface
*/
private $requestedActionService;
/**
* @return string
*/
protected function getActionType(): string
{
return $this->requestedActionService->getActionType();
}
/**
* @return string
*/
protected function getClass(): string
{
return $this->requestedActionService->getRequestedEntity()->getClass();
}
/**
* @param RequestedActionServiceInterface $requestedActionService
*/
@ -52,7 +68,7 @@ final class TemplateNameService implements TemplateNameServiceInterface
*/
private function getBasePath(): string
{
$origineClass = $this->requestedActionService->getRequestedEntity()->getClass();
$origineClass = $this->getClass();
$baseReplaced = str_replace(self::BASE_NAMESPACE, self::BASE_ENTITY_TEMPLATE_FOLDER, $origineClass);
$elements = explode('\\', $baseReplaced);
array_pop($elements); //Removes class name
@ -67,7 +83,7 @@ final class TemplateNameService implements TemplateNameServiceInterface
*/
private function getShortName(): string
{
$origineClass = $this->requestedActionService->getRequestedEntity()->getClass();
$origineClass = $this->getClass();
$elements = explode('\\', $origineClass);
$class = $elements[count($elements) - 1];
$lcFirst = lcfirst($class);
@ -82,7 +98,7 @@ final class TemplateNameService implements TemplateNameServiceInterface
*/
private function getActionSuffix(): string
{
return '_'.strtolower($this->requestedActionService->getActionType());
return '_'.strtolower($this->getActionType());
}
/**