XeroPHP\Helpers::singularize PHP Method

singularize() public static method

It only contains a fraction of the rules from its predecessor, so only good for a quick basic singularisation.
public static singularize ( $string ) : mixed
$string
return mixed
    public static function singularize($string)
    {
        $singular = ['/(vert|ind)ices$/i' => "\$1ex", '/(alias)es$/i' => "\$1", '/(x|ch|ss|sh)es$/i' => "\$1", '/(s)eries$/i' => "\$1eries", '/(s)tatus$/i' => "\$1tatus", '/([^aeiouy]|qu)ies$/i' => "\$1y", '/([lr])ves$/i' => "\$1f", '/([ti])a$/i' => "\$1um", '/(us)es$/i' => "\$1", '/(basis)$/i' => "\$1", '/([^s])s$/i' => "\$1"];
        // check for matches using regular expressions
        foreach ($singular as $pattern => $result) {
            if (preg_match($pattern, $string)) {
                return preg_replace($pattern, $result, $string);
            }
        }
        //Else return
        return $string;
    }

Usage Example

Example #1
0
 /**
  * Get the class name for the Model. Purely based on the name property.
  *
  * @param bool $with_ns
  * @return mixed
  */
 public function getClassName($with_ns = false)
 {
     $class_name = Helpers::singularize($this->getName());
     if ($with_ns) {
         return sprintf('%s\\%s', $this->getNamespace(), $class_name);
     } else {
         return $class_name;
     }
 }
All Usage Examples Of XeroPHP\Helpers::singularize