diff --git a/application/symfony/src/Domain/LayerManagement/LayerActionMap.php b/application/symfony/src/Domain/LayerManagement/LayerActionMap.php new file mode 100644 index 0000000..ec7f2f6 --- /dev/null +++ b/application/symfony/src/Domain/LayerManagement/LayerActionMap.php @@ -0,0 +1,56 @@ + [ + ActionType::READ, + ActionType::CREATE, + ActionType::UPDATE, + ActionType::DELETE, + ActionType::LIST, + ], + ]; + + /** + * {@inheritdoc} + * + * @see \App\Domain\LayerManagement\LayerActionMapInterface::getLayers() + */ + 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; + } + + /** + * {@inheritdoc} + * + * @see \App\Domain\LayerManagement\LayerActionMapInterface::getActions() + */ + public static function getActions(string $layer): array + { + if (array_key_exists($layer, self::LAYER_ACTION_MAP)) { + return self::LAYER_ACTION_MAP[$layer]; + } + + return []; + } +} diff --git a/application/symfony/src/Domain/LayerManagement/LayerActionMapInterface.php b/application/symfony/src/Domain/LayerManagement/LayerActionMapInterface.php new file mode 100644 index 0000000..df99237 --- /dev/null +++ b/application/symfony/src/Domain/LayerManagement/LayerActionMapInterface.php @@ -0,0 +1,25 @@ +assertArraySubset([LayerType::SOURCE], $layers); + } + } + + public function testGetActionsBySource(): void + { + $actions = LayerActionMap::getActions(LayerType::SOURCE); + foreach (ActionType::getChoices() as $action) { + $this->assertTrue(in_array($action, $actions)); + } + } + + public function testEmptyGetActionsBySource(): void + { + $this->assertEquals(0, count(LayerActionMap::getActions('blablabla'))); + } +}