mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-03 18:58:01 +00:00 
			
		
		
		
	Implemented AbstractMap and ActionHttpMethodMap
This commit is contained in:
		@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										44
									
								
								application/symfony/src/Domain/MapManagement/AbstractMap.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								application/symfony/src/Domain/MapManagement/AbstractMap.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\MapManagement;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This class offers the basic functions for managing an 2 dimensional map.
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
abstract class AbstractMap implements MapInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string         $index
 | 
			
		||||
     * @param array|string[] $map
 | 
			
		||||
     *
 | 
			
		||||
     * @return array|string[]
 | 
			
		||||
     */
 | 
			
		||||
    protected static function getValuesByIndex(string $index, array $map): array
 | 
			
		||||
    {
 | 
			
		||||
        if (array_key_exists($index, $map)) {
 | 
			
		||||
            return $map[$index];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return [];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string         $value
 | 
			
		||||
     * @param array|string[] $map
 | 
			
		||||
     *
 | 
			
		||||
     * @return array|string[]
 | 
			
		||||
     */
 | 
			
		||||
    protected static function getIndizesByValue(string $value, array $map): array
 | 
			
		||||
    {
 | 
			
		||||
        $result = [];
 | 
			
		||||
        foreach ($map as $index => $values) {
 | 
			
		||||
            if (in_array($value, $values)) {
 | 
			
		||||
                $result[] = $index;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,10 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\MapManagement;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface MapInterface
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,44 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\ResponseManagement;
 | 
			
		||||
 | 
			
		||||
use App\Domain\MapManagement\AbstractMap;
 | 
			
		||||
use App\DBAL\Types\ActionType;
 | 
			
		||||
use Symfony\Component\HttpFoundation\Request;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
final class ActionHttpMethodMap extends AbstractMap implements ActionHttpMethodMapInterface
 | 
			
		||||
{
 | 
			
		||||
    const ACTION_HTTP_METHOD_MAP = [
 | 
			
		||||
        ActionType::READ => [
 | 
			
		||||
            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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,25 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Domain\ResponseManagement;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This class offers a map for ActionTypes to HttpMethods.
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
interface ActionHttpMethodMapInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string $httpMethod
 | 
			
		||||
     *
 | 
			
		||||
     * @return array|string[] The Http-Methods which belong to an action
 | 
			
		||||
     */
 | 
			
		||||
    public static function getActions(string $httpMethod): array;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param string $action
 | 
			
		||||
     *
 | 
			
		||||
     * @return array|string[] The Http-Methods which are possible for an action
 | 
			
		||||
     */
 | 
			
		||||
    public static function getHttpMethods(string $action): array;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user