mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 17:29:04 +00:00 
			
		
		
		
	Implemented LayerActionMap
This commit is contained in:
		| @@ -0,0 +1,56 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Domain\LayerManagement; | ||||
|  | ||||
| use App\DBAL\Types\Meta\Right\LayerType; | ||||
| use App\DBAL\Types\ActionType; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| final class LayerActionMap implements LayerActionMapInterface | ||||
| { | ||||
|     /** | ||||
|      * @var array Add new combination possibilities to this map! | ||||
|      */ | ||||
|     const LAYER_ACTION_MAP = [ | ||||
|         LayerType::SOURCE => [ | ||||
|             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 []; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,25 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Domain\LayerManagement; | ||||
|  | ||||
| /** | ||||
|  * This LayerActionMap offers the possibility, to see which Action\Layer-Cobinations are possible. | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface LayerActionMapInterface | ||||
| { | ||||
|     /** | ||||
|      * @param string $action | ||||
|      * | ||||
|      * @return array|string[] | ||||
|      */ | ||||
|     public static function getLayers(string $action): array; | ||||
|  | ||||
|     /** | ||||
|      * @param string $layer | ||||
|      * | ||||
|      * @return array|string[] | ||||
|      */ | ||||
|     public static function getActions(string $layer): array; | ||||
| } | ||||
| @@ -0,0 +1,35 @@ | ||||
| <?php | ||||
|  | ||||
| namespace tests\Unit\Domain\LayerManagement; | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
| use App\DBAL\Types\ActionType; | ||||
| use App\Domain\LayerManagement\LayerActionMap; | ||||
| use App\DBAL\Types\Meta\Right\LayerType; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| class LayerActionMapTest extends TestCase | ||||
| { | ||||
|     public function testGetLayersBySource(): void | ||||
|     { | ||||
|         foreach (ActionType::getChoices() as $action) { | ||||
|             $layers = LayerActionMap::getLayers($action); | ||||
|             $this->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'))); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user