From 8e2d79d23695fd2b75272a477b315fd0054c6bf3 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Tue, 29 Jan 2019 20:02:36 +0100 Subject: [PATCH] Implemented AbstractMap and ActionHttpMethodMap --- .../Domain/LayerManagement/LayerActionMap.php | 18 ++------ .../src/Domain/MapManagement/AbstractMap.php | 44 +++++++++++++++++++ .../src/Domain/MapManagement/MapInterface.php | 10 +++++ .../ActionHttpMethodMap.php | 44 +++++++++++++++++++ .../ActionHttpMethodMapInterface.php | 25 +++++++++++ 5 files changed, 127 insertions(+), 14 deletions(-) create mode 100644 application/symfony/src/Domain/MapManagement/AbstractMap.php create mode 100644 application/symfony/src/Domain/MapManagement/MapInterface.php create mode 100644 application/symfony/src/Domain/ResponseManagement/ActionHttpMethodMap.php create mode 100644 application/symfony/src/Domain/ResponseManagement/ActionHttpMethodMapInterface.php diff --git a/application/symfony/src/Domain/LayerManagement/LayerActionMap.php b/application/symfony/src/Domain/LayerManagement/LayerActionMap.php index 5895c64..02d9807 100644 --- a/application/symfony/src/Domain/LayerManagement/LayerActionMap.php +++ b/application/symfony/src/Domain/LayerManagement/LayerActionMap.php @@ -4,11 +4,12 @@ namespace App\Domain\LayerManagement; use App\DBAL\Types\Meta\Right\LayerType; use App\DBAL\Types\ActionType; +use App\Domain\MapManagement\AbstractMap; /** * @author kevinfrantz */ -final class LayerActionMap implements LayerActionMapInterface +final class LayerActionMap extends AbstractMap implements LayerActionMapInterface { /** * @var array Add new combination possibilities to this map! @@ -30,14 +31,7 @@ final class LayerActionMap implements LayerActionMapInterface */ public static function getLayers(string $action): array { - $layers = []; - foreach (self::LAYER_ACTION_MAP as $layer => $actions) { - if (in_array($action, $actions)) { - $layers[] = $layer; - } - } - - return $layers; + return parent::getIndizesByValue($action, self::LAYER_ACTION_MAP); } /** @@ -47,10 +41,6 @@ final class LayerActionMap implements LayerActionMapInterface */ public static function getActions(string $layer): array { - if (array_key_exists($layer, self::LAYER_ACTION_MAP)) { - return self::LAYER_ACTION_MAP[$layer]; - } - - return []; + return parent::getValuesByIndex($layer, self::LAYER_ACTION_MAP); } } diff --git a/application/symfony/src/Domain/MapManagement/AbstractMap.php b/application/symfony/src/Domain/MapManagement/AbstractMap.php new file mode 100644 index 0000000..366d25f --- /dev/null +++ b/application/symfony/src/Domain/MapManagement/AbstractMap.php @@ -0,0 +1,44 @@ + $values) { + if (in_array($value, $values)) { + $result[] = $index; + } + } + + return $result; + } +} diff --git a/application/symfony/src/Domain/MapManagement/MapInterface.php b/application/symfony/src/Domain/MapManagement/MapInterface.php new file mode 100644 index 0000000..8c442d9 --- /dev/null +++ b/application/symfony/src/Domain/MapManagement/MapInterface.php @@ -0,0 +1,10 @@ + [ + Request::METHOD_GET, + ], + ActionType::CREATE => [ + Request::METHOD_POST, + Request::METHOD_GET, + ], + ActionType::UPDATE => [ + Request::METHOD_PUT, + Request::METHOD_GET, + ], + ActionType::DELETE => [ + Request::METHOD_GET, + Request::METHOD_DELETE, + ], + ActionType::THREAD => [ + Request::METHOD_GET, + ], + ]; + + public static function getActions(string $httpMethod): array + { + return parent::getIndizesByValue($httpMethod, self::ACTION_HTTP_METHOD_MAP); + } + + public static function getHttpMethods(string $action): array + { + return parent::getValuesByIndex($action, self::ACTION_HTTP_METHOD_MAP); + } +} diff --git a/application/symfony/src/Domain/ResponseManagement/ActionHttpMethodMapInterface.php b/application/symfony/src/Domain/ResponseManagement/ActionHttpMethodMapInterface.php new file mode 100644 index 0000000..6756841 --- /dev/null +++ b/application/symfony/src/Domain/ResponseManagement/ActionHttpMethodMapInterface.php @@ -0,0 +1,25 @@ +