src/Generator/Utils.php
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 (!empty($parts[$partsCount - 1])) {
                        $elementType = mb_substr($string, mb_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 = mb_substr($string, ((count($parts) - 2 - $i) + 1) * -1);
                    }
                    break;
                case GeneratorOptions::VALUE_START:
                    $parts = preg_split('/[A-Z]/', ucfirst($string));
                    $partsCount = count($parts);
                    if (empty($parts[0]) && !empty($parts[1])) {
                        $elementType = mb_substr($string, 0, mb_strlen($parts[1]) + 1);
                    } else {
                        for ($i = 0; $i < $partsCount; $i++) {
                            $part = trim($parts[$i]);
                            if (!empty($part)) {
                                break;
                            }
                        }
                        $elementType = mb_substr($string, 0, $i);
                    }
                    break;
                case GeneratorOptions::VALUE_NONE:
                    $elementType = $string;
                    break;
                default:
                    break;
            }
        }
        return $elementType;
    }
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 (!empty($parts[$partsCount - 1])) {
                        $elementType = mb_substr($string, mb_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 = mb_substr($string, ((count($parts) - 2 - $i) + 1) * -1);
                    }
                    break;
                case GeneratorOptions::VALUE_START:
                    $parts = preg_split('/[A-Z]/', ucfirst($string));
                    $partsCount = count($parts);
                    if (empty($parts[0]) && !empty($parts[1])) {
                        $elementType = mb_substr($string, 0, mb_strlen($parts[1]) + 1);
                    } else {
                        for ($i = 0; $i < $partsCount; $i++) {
                            $part = trim($parts[$i]);
                            if (!empty($part)) {
                                break;
                            }
                        }
                        $elementType = mb_substr($string, 0, $i);
                    }
                    break;
                case GeneratorOptions::VALUE_NONE:
                    $elementType = $string;
                    break;
                default:
                    break;
            }
        }
        return $elementType;
    }
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 ( ! empty ( $ parts [ $ partsCount - 1 ] ) ) { $ elementType = mb_substr ( $ string , mb_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 = mb_substr ( $ string , ( ( count ( $ parts ) - 2 - $ i ) + 1 ) * - 1 ) ; } break ; case GeneratorOptions :: VALUE_START : $ parts = preg_split ( '/[A-Z]/' , ucfirst ( $ string ) ) ; $ partsCount = count ( $ parts ) ; if ( empty ( $ parts [ 0 ] ) && ! empty ( $ parts [ 1 ] ) ) { $ elementType = mb_substr ( $ string , 0 , mb_strlen ( $ parts [ 1 ] ) + 1 ) ; } else { for ( $ i = 0 ; $ i < $ partsCount ; $ i ++ ) { $ part = trim ( $ parts [ $ i ] ) ; if ( ! empty ( $ part ) ) { break ; } } $ elementType = mb_substr ( $ string , 0 , $ i ) ; } break ; case GeneratorOptions :: VALUE_NONE : $ elementType = $ string ; break ; default : break ; } } return $ elementType ; }
Gets upper case word among a string from the end or from the beginning part
@param string $optionValue
@param string $string the string from which we can extract the part
@return string
Gets upper case word among a string from the end or from the beginning part