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
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 2
0
 /**
  * @return string
  */
 public function getNameSingular()
 {
     return \XeroPHP\Helpers::singularize($this->getName());
 }
Ejemplo n.º 3
0
 /**
  * Search for an entity based on a term. Search by class name, FQ class name - both as-is, plural and singular
  *
  * Crude.
  *
  * @param $key
  * @param string $namespace_hint
  * @return null
  */
 public function searchByKey($key, $namespace_hint = '')
 {
     if (!$this->isIndexed()) {
         $this->buildSearchIndex();
     }
     //Yuck
     $plural_key = Helpers::pluralize($key);
     $singular_key = Helpers::singularize($key);
     $ns_key = sprintf('%s\\%s', $namespace_hint, $key);
     $plural_ns_key = Helpers::pluralize($ns_key);
     $singular_ns_key = Helpers::singularize($ns_key);
     if (isset($this->search_keys[$ns_key])) {
         return $this->search_keys[$ns_key];
     } elseif (isset($this->search_keys[$plural_ns_key])) {
         return $this->search_keys[$plural_ns_key];
     } elseif (isset($this->search_keys[$singular_ns_key])) {
         return $this->search_keys[$singular_ns_key];
     } elseif (isset($this->search_keys[$key])) {
         return $this->search_keys[$key];
     } elseif (isset($this->search_keys[$plural_key])) {
         return $this->search_keys[$plural_key];
     } elseif (isset($this->search_keys[$singular_key])) {
         return $this->search_keys[$singular_key];
     } else {
         return null;
     }
 }
Ejemplo n.º 4
0
 /**
  * Get the prefix for the constant name generation and strip out 'Types'
  * eg. XERO_USER_ROLE
  *
  * @return mixed
  */
 public function getConstantPrefix()
 {
     $sane_name = preg_replace('/\\([\\w\\s]+\\)/', '', $this->raw_name);
     return \XeroPHP\Helpers::singularize(preg_replace('/(\\b(code)s?)/i', '', trim($sane_name)));
 }