mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Implemented OptionalGetParameterService
This commit is contained in:
@@ -93,17 +93,17 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
|
||||
if (!$this->actionType) {
|
||||
if ($this->requestedActionService->hasRequestedEntity() && $this->requestedActionService->getRequestedEntity()->hasIdentity()) {
|
||||
//READ VIEW
|
||||
$this->requestedActionService->setActionType(ActionType::READ);
|
||||
// $this->requestedActionService->setActionType(ActionType::READ);
|
||||
if ($this->secureRequestedRightCheckerService->check($this->requestedActionService)) {
|
||||
$read = $this->actionHandlerService->handle();
|
||||
$this->actionTemplateDataStore->setData(ActionType::READ, $read);
|
||||
}
|
||||
$this->requestedActionService->setActionType(ActionType::UPDATE);
|
||||
// $this->requestedActionService->setActionType(ActionType::UPDATE);
|
||||
//UPDATE VIEW
|
||||
if ($this->secureRequestedRightCheckerService->check($this->requestedActionService)) {
|
||||
$updateForm = $this->requestedActionFormBuilderService->createByService()->getForm()->createView();
|
||||
$this->actionTemplateDataStore->setData(ActionType::UPDATE, $updateForm);
|
||||
}
|
||||
// if ($this->secureRequestedRightCheckerService->check($this->requestedActionService)) {
|
||||
// $updateForm = $this->requestedActionFormBuilderService->createByService()->getForm()->createView();
|
||||
// $this->actionTemplateDataStore->setData(ActionType::UPDATE, $updateForm);
|
||||
// }
|
||||
//DELETE VIEW
|
||||
//EXECUTE VIEW
|
||||
} else {
|
||||
|
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\ParameterManagement;
|
||||
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Infinito\Exception\UnvalidParameterException;
|
||||
use Infinito\Exception\NotDefinedException;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class OptionalGetParameterService implements OptionalGetParameterServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
private $currentRequest;
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @throws UnvalidParameterException If the parameter is not valid
|
||||
*/
|
||||
private function validateParameter(string $key): void
|
||||
{
|
||||
if (in_array($key, self::OPTIONAL_PARAMETERS)) {
|
||||
return;
|
||||
}
|
||||
throw new UnvalidParameterException("Parameter <<$key>> isn't valid.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RequestStack $requestStack
|
||||
*/
|
||||
private function setCurrentRequest(RequestStack $requestStack): void
|
||||
{
|
||||
$this->currentRequest = $requestStack->getCurrentRequest();
|
||||
}
|
||||
|
||||
private function validateCurrentRequestKeys(): void
|
||||
{
|
||||
foreach ($this->currentRequest->query->keys() as $key) {
|
||||
$this->validateParameter($key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RequestStack $requestStack
|
||||
*/
|
||||
public function __construct(RequestStack $requestStack)
|
||||
{
|
||||
$this->setCurrentRequest($requestStack);
|
||||
$this->validateCurrentRequestKeys();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\ParameterManagement\OptionalGetParameterServiceInterface::hasParameter()
|
||||
*/
|
||||
public function hasParameter(string $key): bool
|
||||
{
|
||||
$this->validateParameter($key);
|
||||
|
||||
return $this->currentRequest->query->has($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\ParameterManagement\OptionalGetParameterServiceInterface::getParameter()
|
||||
*/
|
||||
public function getParameter(string $key)
|
||||
{
|
||||
$this->validateParameter($key);
|
||||
if ($this->hasParameter($key)) {
|
||||
return $this->currentRequest->get($key);
|
||||
}
|
||||
throw new NotDefinedException("The parameter <<$key>> is not defined!");
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\ParameterManagement;
|
||||
|
||||
/**
|
||||
* This interface offers a service to manage all optional get parameters.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface OptionalGetParameterServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const VERSION_PARAMETER = 'version';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const EXECUTE_PARAMETER = 'execute';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const VIEW_PARAMETER = 'view';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const CLASS_PARAMETER = 'class';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const FRAME_PARAMETER = 'frame';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const SCHEMA_PARAMETER = 'schema';
|
||||
|
||||
/**
|
||||
* @var array|string[]
|
||||
*/
|
||||
const OPTIONAL_PARAMETERS = [
|
||||
self::VERSION_PARAMETER,
|
||||
self::VIEW_PARAMETER,
|
||||
self::CLASS_PARAMETER,
|
||||
self::FRAME_PARAMETER,
|
||||
self::SCHEMA_PARAMETER,
|
||||
self::EXECUTE_PARAMETER,
|
||||
];
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool True if the version parameter in the request is set
|
||||
*/
|
||||
public function hasParameter(string $key): bool;
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParameter(string $key);
|
||||
}
|
Reference in New Issue
Block a user