Solved parameter bug

This commit is contained in:
Kevin Frantz 2019-03-29 20:04:34 +01:00
parent 5cbbcb3681
commit 2d51d7647c
5 changed files with 57 additions and 21 deletions

View File

@ -26,6 +26,16 @@ use Infinito\Attribut\ClassAttributInterface;
*/
final class LayerController extends AbstractAPIController
{
/**
* @var string
*/
const IDENTITY_PARAMETER_KEY = 'identity';
/**
* @var string
*/
const LAYER_PARAMETER_KEY = 'layer';
/**
* @Route(
* ".{_format}",

View File

@ -9,4 +9,13 @@ use FOS\RestBundle\Controller\AbstractFOSRestController;
*/
abstract class AbstractController extends AbstractFOSRestController
{
/**
* @var string
*/
const FORMAT_PARAMETER_KEY = '_format';
/**
* @var string
*/
const LOCALE_PARAMETER_KEY = '_locale';
}

View File

@ -9,6 +9,7 @@ use Symfony\Component\Translation\TranslatorInterface;
use Infinito\DBAL\Types\RESTResponseType;
use Symfony\Component\HttpFoundation\Request;
use FOS\RestBundle\Request\ParameterBag;
use Infinito\Controller\AbstractController;
/**
* This class is just a result of refactoring. Feel free to replace it.
@ -88,7 +89,7 @@ abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface
*
* @return ParameterBag
*/
private function getRequestAttributs(Event $event): array
protected function getRequestAttributs(Event $event): array
{
return $this->getCurrentRequest($event)->attributes->get('_route_params') ?? [];
}
@ -102,24 +103,8 @@ abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface
private function getRequestAttributsSubstitutedFormat(Event $event, string $format): array
{
$attributs = $this->getRequestAttributs($event);
$attributs['_format'] = $format;
$attributs[AbstractController::FORMAT_PARAMETER_KEY] = $format;
return $attributs;
}
/**
* @param Event $event
*
* @return bool
*/
protected function shouldShowFormatSelection(Event $event): bool
{
foreach (['identity', 'layer'] as $attribut) {
if (!key_exists($attribut, $this->getRequestAttributs($event))) {
return false;
}
}
return true;
}
}

View File

@ -10,6 +10,10 @@ use Infinito\Event\Menu\MenuEvent;
use Infinito\DBAL\Types\MenuEventType;
use Infinito\Domain\FixtureManagement\FixtureSource\ImpressumFixtureSource;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\EventDispatcher\Event;
use Infinito\DBAL\Types\RESTResponseType;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\Controller\API\Rest\LayerController;
/**
* @author kevinfrantz
@ -21,6 +25,11 @@ class UserMenuSubscriber extends AbstractEntityMenuSubscriber implements EventSu
*/
const LAYER_GET_ROUTE = 'infinito_api_rest_layer_read';
/**
* @var string
*/
const LAYER_CREATE_ROUTE = 'infinito_api_rest_layer_create';
/**
* @var TokenStorageInterface
*/
@ -50,7 +59,12 @@ class UserMenuSubscriber extends AbstractEntityMenuSubscriber implements EventSu
]);
$menu->addChild($this->trans('imprint'), [
'uri' => '/api/rest/source/'.strtolower(ImpressumFixtureSource::SLUG).'.html',
'route' => self::LAYER_GET_ROUTE,
'routeParameters' => [
'identity' => ImpressumFixtureSource::SLUG,
'_format' => RESTResponseType::HTML,
'layer' => LayerType::SOURCE,
],
'attributes' => [
'icon' => 'fas fa-address-card',
],
@ -141,4 +155,21 @@ class UserMenuSubscriber extends AbstractEntityMenuSubscriber implements EventSu
MenuEventType::USER => 'onUserMenuConfigure',
];
}
/**
* @param Event $event
*
* @return bool
*/
private function shouldShowFormatSelection(Event $event): bool
{
foreach ([LayerController::IDENTITY_PARAMETER_KEY, LayerController::LAYER_PARAMETER_KEY] as $key) {
$attributs = $this->getRequestAttributs($event);
if (!key_exists($key, $attributs) || '' === $attributs[$key]) {
return false;
}
}
return true;
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Tests\Integration\Controller;
namespace Tests\Functional;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
@ -8,7 +8,7 @@ use Symfony\Component\HttpFoundation\Request;
/**
* @author kevinfrantz
*/
class RoutesGetStatusIntegrationTest extends KernelTestCase
class RoutesReachableFunctionTest extends KernelTestCase
{
const GET_URLS_STATUS = [
'login' => 200,
@ -16,6 +16,7 @@ class RoutesGetStatusIntegrationTest extends KernelTestCase
'logout' => 302,
'profile/edit' => 302,
'spa' => 302,
'api/rest/source.html' => 200,
];
/**