public static function getPart($optionValue, $string)
{
$elementType = '';
$string = str_replace('_', '', $string);
$string = preg_replace('/([0-9])/', '', $string);
if (!empty($string)) {
switch ($optionValue) {
case GeneratorOptions::VALUE_END:
$parts = preg_split('/[A-Z]/', ucfirst($string));
$partsCount = count($parts);
if ($partsCount == 0) {
$elementType = $string;
} elseif (!empty($parts[$partsCount - 1])) {
$elementType = substr($string, strrpos($string, implode('', array_slice($parts, -1))) - 1);
} else {
for ($i = $partsCount - 1; $i >= 0; $i--) {
$part = trim($parts[$i]);
if (!empty($part)) {
break;
}
}
$elementType = substr($string, (count($parts) - 2 - $i + 1) * -1);
}
break;
case GeneratorOptions::VALUE_START:
$parts = preg_split('/[A-Z]/', ucfirst($string));
$partsCount = count($parts);
if ($partsCount == 0) {
$elementType = $string;
} elseif (empty($parts[0]) && !empty($parts[1])) {
$elementType = substr($string, 0, strlen($parts[1]) + 1);
} else {
for ($i = 0; $i < $partsCount; $i++) {
$part = trim($parts[$i]);
if (!empty($part)) {
break;
}
}
$elementType = substr($string, 0, $i);
}
break;
default:
break;
}
}
return $elementType;
}