mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Implemented Draft of MVCRoutineService
This commit is contained in:
@@ -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