mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-04 03:07:58 +00:00 
			
		
		
		
	Implemented Draft of MVCRoutineService
This commit is contained in:
		@@ -4,7 +4,10 @@ namespace App\Controller;
 | 
			
		||||
 | 
			
		||||
use Symfony\Component\Routing\Annotation\Route;
 | 
			
		||||
use Symfony\Component\HttpFoundation\Response;
 | 
			
		||||
use Doctrine\ORM\EntityManagerInterface;
 | 
			
		||||
use App\Domain\MVCManagement\MVCRoutineServiceInterface;
 | 
			
		||||
use App\Domain\RequestManagement\Action\RequestedActionServiceInterface;
 | 
			
		||||
use App\DBAL\Types\ActionType;
 | 
			
		||||
use App\Domain\FixtureManagement\FixtureSource\ImpressumFixtureSource;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This controller offers the standart routes for the template.
 | 
			
		||||
@@ -19,8 +22,12 @@ final class DefaultController extends AbstractController
 | 
			
		||||
     * @todo Optimize function!
 | 
			
		||||
     * @Route("/imprint.{_format}", defaults={"_format"="json"}, name="imprint")
 | 
			
		||||
     */
 | 
			
		||||
    public function imprint(EntityManagerInterface $entityManager): Response
 | 
			
		||||
    public function imprint(MVCRoutineServiceInterface $mvcRoutineService, RequestedActionServiceInterface $requestedActionService): Response
 | 
			
		||||
    {
 | 
			
		||||
        $requestedActionService->setActionType(ActionType::READ);
 | 
			
		||||
        $requestedActionService->getRequestedEntity()->setSlug(ImpressumFixtureSource::SLUG);
 | 
			
		||||
        $view = $mvcRoutineService->process();
 | 
			
		||||
        $this->handleView($view);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,32 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\ActionManagement;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class ActionHandlerService implements ActionHandlerServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var ActionFactoryServiceInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $actionFactoryService;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param ActionFactoryServiceInterface $actionFactoryService
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(ActionFactoryServiceInterface $actionFactoryService)
 | 
			
		||||
    {
 | 
			
		||||
        $this->actionFactoryService = $actionFactoryService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\ActionManagement\ActionHandlerServiceInterface::handle()
 | 
			
		||||
     */
 | 
			
		||||
    public function handle()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->actionFactoryService->create()->execute();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,18 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\ActionManagement;
 | 
			
		||||
 | 
			
		||||
use App\Entity\EntityInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface ActionHandlerServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Process an action an returns the results.
 | 
			
		||||
     *
 | 
			
		||||
     * @return EntityInterface|EntityInterface[]
 | 
			
		||||
     */
 | 
			
		||||
    public function handle();
 | 
			
		||||
}
 | 
			
		||||
@@ -3,19 +3,63 @@
 | 
			
		||||
namespace App\Domain\MVCManagement;
 | 
			
		||||
 | 
			
		||||
use FOS\RestBundle\View\View;
 | 
			
		||||
use App\Entity\EntityInterface;
 | 
			
		||||
use App\Domain\ActionManagement\ActionHandlerServiceInterface;
 | 
			
		||||
use App\Domain\TemplateManagement\TemplateNameServiceInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class MVCRoutineService implements MVCRoutineServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var ActionHandlerServiceInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $actionHandlerService;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var TemplateNameServiceInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $templateNameService;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param EntityInterface[]|EntityInterface|null $result
 | 
			
		||||
     *
 | 
			
		||||
     * @return array Well formated data for view
 | 
			
		||||
     */
 | 
			
		||||
    private function getViewData($result): array
 | 
			
		||||
    {
 | 
			
		||||
        switch (gettype($result)) {
 | 
			
		||||
            case 'object':
 | 
			
		||||
                return ['entity' => $this->result];
 | 
			
		||||
            case 'array':
 | 
			
		||||
                return ['enitits' => $this->result];
 | 
			
		||||
            case 'null':
 | 
			
		||||
                return [];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param ActionHandlerServiceInterface $actionHandlerService
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(ActionHandlerServiceInterface $actionHandlerService, TemplateNameServiceInterface $templateNameService)
 | 
			
		||||
    {
 | 
			
		||||
        $this->actionHandlerService = $actionHandlerService;
 | 
			
		||||
        $this->templateNameService = $templateNameService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\MVCManagement\MVCRoutineServiceInterface::process()
 | 
			
		||||
     */
 | 
			
		||||
    public function process(): void
 | 
			
		||||
    public function process(): View
 | 
			
		||||
    {
 | 
			
		||||
        $result = $this->actionHandlerService->handle();
 | 
			
		||||
        $data = $this->getViewData($result);
 | 
			
		||||
        $view = $this->getView($data);
 | 
			
		||||
 | 
			
		||||
        return $view;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -23,7 +67,12 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\MVCManagement\MVCRoutineServiceInterface::getView()
 | 
			
		||||
     */
 | 
			
		||||
    public function getView(): View
 | 
			
		||||
    public function getView(array $data): View
 | 
			
		||||
    {
 | 
			
		||||
        $view = View::create();
 | 
			
		||||
        $view->setTemplate($this->templateNameService->getMoleculeTemplateName());
 | 
			
		||||
        $view->setData($data);
 | 
			
		||||
 | 
			
		||||
        return $view;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -12,12 +12,9 @@ use FOS\RestBundle\View\View;
 | 
			
		||||
interface MVCRoutineServiceInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Process the injected services.
 | 
			
		||||
     */
 | 
			
		||||
    public function process(): void;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Process through the layers.
 | 
			
		||||
     *
 | 
			
		||||
     * @return View
 | 
			
		||||
     */
 | 
			
		||||
    public function getView(): View;
 | 
			
		||||
    public function process(): View;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user