Renamed domain LayerManagement to Layer

This commit is contained in:
Kevin Frantz
2019-05-30 16:18:10 +02:00
parent 592f7551a3
commit fd4093f270
14 changed files with 18 additions and 18 deletions

View File

@@ -0,0 +1,77 @@
<?php
namespace Infinito\Domain\Layer;
use Infinito\DBAL\Types\Meta\Right\LayerType;
/**
* @author kevinfrantz
*
* @todo for performance reasons it could be helpfull to implement lazy loading in the future
*/
final class LayerInterfaceMap implements LayerInterfaceMapInterface
{
/**
* @var string The abstract class prefix, which will be removed from the interface name
*/
const ABSTRACT_CLASS_PREFIX = 'Abstract';
/**
* @var string The suffix which will be added to the interface name
*/
const INTERFACE_SUFFIX = 'Interface';
/**
* @param string $shortClass
*
* @return string
*/
private static function filterAbstractClassName(string $shortClass): string
{
if (self::ABSTRACT_CLASS_PREFIX === substr($shortClass, 0, strlen(self::ABSTRACT_CLASS_PREFIX))) {
return substr($shortClass, strlen(self::ABSTRACT_CLASS_PREFIX));
}
return $shortClass;
}
/**
* @param string $class
*
* @return string
*/
private static function addInterfaceSuffix(string $class): string
{
return $class.self::INTERFACE_SUFFIX;
}
/**
* @param string $layer
*
* @return string
*/
public static function getInterface(string $layer): string
{
$className = LayerClassMap::getClass($layer);
$elements = explode('\\', $className);
$shortClass = $elements[count($elements) - 1];
$filteredAbstractClass = self::filterAbstractClassName($shortClass);
$elements[count($elements) - 1] = self::addInterfaceSuffix($filteredAbstractClass);
$interfaceName = implode('\\', $elements);
return $interfaceName;
}
/**
* @return array
*/
public static function getAllInterfaces(): array
{
$allInterfaces = [];
foreach (LayerType::getValues() as $layer) {
$allInterfaces[$layer] = self::getInterface($layer);
}
return $allInterfaces;
}
}