Renamed domain MapManagement to Map

This commit is contained in:
Kevin Frantz
2019-05-30 16:20:42 +02:00
parent fd4093f270
commit a5801ec6e8
7 changed files with 8 additions and 8 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace Infinito\Domain\Map;
/**
* 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;
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Infinito\Domain\Map;
use Infinito\DBAL\Types\ActionType;
use Symfony\Component\HttpFoundation\Request;
/**
* @author kevinfrantz
*/
final class ActionHttpMethodMap extends AbstractMap implements ActionHttpMethodMapInterface
{
/**
* @var array
*/
const ACTION_HTTP_METHOD_MAP = [
ActionType::READ => [
Request::METHOD_GET,
],
ActionType::CREATE => [
Request::METHOD_POST,
Request::METHOD_HEAD,
],
ActionType::UPDATE => [
Request::METHOD_PUT,
Request::METHOD_PATCH,
],
ActionType::DELETE => [
Request::METHOD_DELETE,
],
ActionType::EXECUTE => [
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);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Infinito\Domain\Map;
/**
* 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;
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Infinito\Domain\Map;
/**
* @author kevinfrantz
*/
interface MapInterface
{
}