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 | ||
Résultat | mixed |
/** * 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; } }
/** * @return string */ public function getNameSingular() { return \XeroPHP\Helpers::singularize($this->getName()); }
/** * 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; } }
/** * 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))); }