mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-04 03:07:58 +00:00 
			
		
		
		
	Optimized Template Management and implemented TemplateNameService
This commit is contained in:
		@@ -12,6 +12,8 @@ use App\Domain\PathManagement\NamespacePathMap;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *
 | 
			
		||||
 * @deprecated
 | 
			
		||||
 */
 | 
			
		||||
class EntityMetaInformation implements EntityMetaInformationInterface
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,8 @@ use App\Domain\PathManagement\NamespacePathMapInterface;
 | 
			
		||||
/**
 | 
			
		||||
 * Offers some meta information about an entity.
 | 
			
		||||
 *
 | 
			
		||||
 * @deprecated
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface EntityMetaInformationInterface
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,29 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\MVCManagement;
 | 
			
		||||
 | 
			
		||||
use FOS\RestBundle\View\View;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class MVCRoutineService implements MVCRoutineServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\MVCManagement\MVCRoutineServiceInterface::process()
 | 
			
		||||
     */
 | 
			
		||||
    public function process(): void
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\MVCManagement\MVCRoutineServiceInterface::getView()
 | 
			
		||||
     */
 | 
			
		||||
    public function getView(): View
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,23 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\MVCManagement;
 | 
			
		||||
 | 
			
		||||
use FOS\RestBundle\View\View;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This interface offers the options to process an MVC routine.
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface MVCRoutineServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Process the injected services.
 | 
			
		||||
     */
 | 
			
		||||
    public function process(): void;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return View
 | 
			
		||||
     */
 | 
			
		||||
    public function getView(): View;
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,107 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\TemplateManagement;
 | 
			
		||||
 | 
			
		||||
use App\Domain\RequestManagement\Action\RequestedActionServiceInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class TemplateNameService implements TemplateNameServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string The namespace which should be ignored
 | 
			
		||||
     */
 | 
			
		||||
    const BASE_NAMESPACE = 'App\\Entity';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string the basic entry point for templates
 | 
			
		||||
     */
 | 
			
		||||
    const BASE_ENTITY_TEMPLATE_FOLDER = 'entity';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string
 | 
			
		||||
     */
 | 
			
		||||
    const MOLECULE_PRAEFFIX = '';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string
 | 
			
		||||
     */
 | 
			
		||||
    const ATOM_PRAEFFIX = '_';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var string
 | 
			
		||||
     */
 | 
			
		||||
    const TWIG_SUFFIX = '.html.twig';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var RequestedActionServiceInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $requestedActionService;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param RequestedActionServiceInterface $requestedActionService
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(RequestedActionServiceInterface $requestedActionService)
 | 
			
		||||
    {
 | 
			
		||||
        $this->requestedActionService = $requestedActionService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return string
 | 
			
		||||
     */
 | 
			
		||||
    private function getBasePath(): string
 | 
			
		||||
    {
 | 
			
		||||
        $origineClass = $this->requestedActionService->getRequestedEntity()->getClass();
 | 
			
		||||
        $baseReplaced = str_replace(self::BASE_NAMESPACE, self::BASE_ENTITY_TEMPLATE_FOLDER, $origineClass);
 | 
			
		||||
        $elements = explode('\\', $baseReplaced);
 | 
			
		||||
        array_pop($elements); //Removes class name
 | 
			
		||||
        $templatePath = implode('/', $elements);
 | 
			
		||||
        $lowerCasePath = strtolower($templatePath);
 | 
			
		||||
 | 
			
		||||
        return $lowerCasePath.'/';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return string the short class name in lower cases
 | 
			
		||||
     */
 | 
			
		||||
    private function getShortName(): string
 | 
			
		||||
    {
 | 
			
		||||
        $origineClass = $this->requestedActionService->getRequestedEntity()->getClass();
 | 
			
		||||
        $elements = explode('\\', $origineClass);
 | 
			
		||||
        $class = $elements[count($elements) - 1];
 | 
			
		||||
        $lcFirst = lcfirst($class);
 | 
			
		||||
        $bigLettersSubstituted = preg_replace('/([A-Z])/', '_$1', $lcFirst);
 | 
			
		||||
        $lowerCase = strtolower($bigLettersSubstituted);
 | 
			
		||||
 | 
			
		||||
        return $lowerCase;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return string
 | 
			
		||||
     */
 | 
			
		||||
    private function getActionSuffix(): string
 | 
			
		||||
    {
 | 
			
		||||
        return '_'.strtolower($this->requestedActionService->getActionType());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string $type
 | 
			
		||||
     *
 | 
			
		||||
     * @return string
 | 
			
		||||
     */
 | 
			
		||||
    private function getTemplatePath(?string $type): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->getBasePath().$type.$this->getShortName().$this->getActionSuffix().self::TWIG_SUFFIX;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getAtomTemplateName(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->getTemplatePath(self::ATOM_PRAEFFIX);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getMoleculeTemplateName(): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->getTemplatePath(self::MOLECULE_PRAEFFIX);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,19 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\TemplateManagement;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface TemplateNameServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @return string A template inclusiv frame. (Standalone)
 | 
			
		||||
     */
 | 
			
		||||
    public function getMoleculeTemplateName(): string;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return string a template without a frame
 | 
			
		||||
     */
 | 
			
		||||
    public function getAtomTemplateName(): string;
 | 
			
		||||
}
 | 
			
		||||
@@ -6,6 +6,9 @@ use App\DBAL\Types\RESTResponseType;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *
 | 
			
		||||
 * @deprecated
 | 
			
		||||
 * @see TemplatePathService
 | 
			
		||||
 */
 | 
			
		||||
final class TemplatePathInformation implements TemplatePathInformationInterface
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,9 @@ use App\DBAL\Types\RESTResponseType;
 | 
			
		||||
 * Manages all informations which are needed to process templates.
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *
 | 
			
		||||
 * @deprecated
 | 
			
		||||
 * @see TemplatePathServiceInterface
 | 
			
		||||
 */
 | 
			
		||||
interface TemplatePathInformationInterface extends ReloadTypeInterface
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -3,10 +3,10 @@
 | 
			
		||||
namespace App\Domain\ViewManagement;
 | 
			
		||||
 | 
			
		||||
use FOS\RestBundle\View\View;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\Factory\SecureCRUDFactoryService;
 | 
			
		||||
use App\Domain\SecureCRUDManagement\Factory\SecureCRUDFactoryServiceInterface;
 | 
			
		||||
use App\Domain\RequestManagement\User\RequestedUserInterface;
 | 
			
		||||
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
 | 
			
		||||
use App\Domain\RequestManagement\Action\RequestedActionInterface;
 | 
			
		||||
use App\Domain\ActionManagement\ActionServiceInterface;
 | 
			
		||||
use App\Domain\ActionManagement\ActionFactoryServiceInterface;
 | 
			
		||||
use App\Domain\ActionManagement\ActionFactoryService;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
@@ -19,36 +19,23 @@ class ViewBuilder implements ViewBuilderInterface
 | 
			
		||||
    protected $view;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var SecureCRUDFactoryServiceInterface
 | 
			
		||||
     * @var RequestedActionInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected $secureCrudFactoryService;
 | 
			
		||||
    protected $actionService;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var RequestedEntityInterface
 | 
			
		||||
     * @var ActionFactoryServiceInterface
 | 
			
		||||
     */
 | 
			
		||||
    protected $requestedEntity;
 | 
			
		||||
    protected $actionFactoryService;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var RequestedUserInterface
 | 
			
		||||
     * @param ActionServiceInterface        $actionService
 | 
			
		||||
     * @param ActionFactoryServiceInterface $actionFactoryService
 | 
			
		||||
     */
 | 
			
		||||
    protected $requestedUser;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param RequestedUserInterface   $requestedUserRight
 | 
			
		||||
     * @param SecureCRUDFactoryService $secureCrudFactoryService
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(RequestedUserInterface $requestedUserRight, SecureCRUDFactoryService $secureCrudFactoryService, RequestedEntityInterface $requestedEntity)
 | 
			
		||||
    public function __construct(ActionServiceInterface $actionService, ActionFactoryServiceInterface $actionFactoryService)
 | 
			
		||||
    {
 | 
			
		||||
        $this->view = new View();
 | 
			
		||||
        $this->requestedUser = $requestedUserRight;
 | 
			
		||||
        $this->secureCrudFactoryService = $secureCrudFactoryService;
 | 
			
		||||
        $this->requestedEntity = $requestedEntity;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function process()
 | 
			
		||||
    {
 | 
			
		||||
        $secureCrudService = $this->secureCrudFactoryService->create($this->requestedUser);
 | 
			
		||||
        $entity = $secureCrudService->process($this->requestedEntity);
 | 
			
		||||
        $this->actionService = $actionService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -57,4 +44,24 @@ class ViewBuilder implements ViewBuilderInterface
 | 
			
		||||
    public function getView(): View
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\ViewManagement\ViewBuilderInterface::getActionService()
 | 
			
		||||
     */
 | 
			
		||||
    public function getActionService(): ActionServiceInterface
 | 
			
		||||
    {
 | 
			
		||||
        return $this->actionService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\ViewManagement\ViewBuilderInterface::build()
 | 
			
		||||
     */
 | 
			
		||||
    public function build(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->view->create();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
namespace App\Domain\ViewManagement;
 | 
			
		||||
 | 
			
		||||
use FOS\RestBundle\View\View;
 | 
			
		||||
use App\Domain\ActionManagement\ActionServiceInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
@@ -13,4 +14,14 @@ interface ViewBuilderInterface
 | 
			
		||||
     * @return View
 | 
			
		||||
     */
 | 
			
		||||
    public function getView(): View;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return ActionServiceInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function getActionService(): ActionServiceInterface;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Builds the view.
 | 
			
		||||
     */
 | 
			
		||||
    public function build(): void;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user