mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 17:29:04 +00:00 
			
		
		
		
	Implemented ActionTemplateNameService
This commit is contained in:
		| @@ -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" | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
| } | ||||
| @@ -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; | ||||
| } | ||||
| @@ -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()); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
		Reference in New Issue
	
	Block a user