WsdlToPhp\PackageGenerator\Generator\Utils::getPart PHP Method

getPart() public static method

Gets upper case word admong a string from the end or from the beginning part
public static getPart ( string $optionValue, string $string ) : string
$optionValue string
$string string the string from which we can extract the part
return string
    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;
    }

Usage Example

Esempio n. 1
0
 /**
  * Gets gather name class
  * @param AbstractModel $model the model for which we generate the folder
  * @return string
  */
 private function getGather(AbstractModel $model)
 {
     return Utils::getPart($this->getOptionGatherMethods(), $model->getCleanName());
 }
All Usage Examples Of WsdlToPhp\PackageGenerator\Generator\Utils::getPart