本文整理汇总了PHP中inflector::uncountable方法的典型用法代码示例。如果您正苦于以下问题:PHP inflector::uncountable方法的具体用法?PHP inflector::uncountable怎么用?PHP inflector::uncountable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inflector
的用法示例。
在下文中一共展示了inflector::uncountable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: humanizeModelName
public static function humanizeModelName($modelName, $count = 1)
{
if (is_object($modelName)) {
$modelName = get_class($modelName);
}
$modelName = preg_replace('/([A-Z])/', ' $1', self::lcfirst($modelName));
// Remove garbage
$modelName = trim($modelName);
if (is_string($count)) {
// Convert to integer when using a digit string
$count = (int) $count;
}
// Do nothing with singular
if ($count === 1) {
return ucfirst($modelName);
}
// Cache key name
$key = 'plural_' . $modelName . $count;
if (isset(self::$cache[$key])) {
return ucfirst(self::$cache[$key]);
}
if (inflector::uncountable($modelName)) {
return ucfirst(self::$cache[$key] = $modelName);
}
if (empty(self::$irregular)) {
// Cache irregular words
self::$irregular = Kohana::config('inflector.irregular');
}
if (isset(self::$irregular[$modelName])) {
$modelName = self::$irregular[$modelName];
} elseif (preg_match('/[sxz]$/', $modelName) or preg_match('/[^aeioudgkprt]h$/', $modelName)) {
$modelName .= 'es';
} elseif (preg_match('/[^aeiou]y$/', $modelName)) {
// Change "y" to "ies"
$modelName = substr_replace($modelName, 'ies', -1);
} else {
$modelName .= 's';
}
// Set the cache and return
return ucfirst(self::$cache[$key] = $modelName);
}
示例2: plural
/**
* Makes a singular word plural.
*
* @param string word to pluralize
* @return string
*/
public static function plural($str, $count = NULL)
{
// Remove garbage
$str = strtolower(trim($str));
if (is_string($count)) {
// Convert to integer when using a digit string
$count = (int) $count;
}
// Do nothing with singular
if ($count === 1) {
return $str;
}
// Cache key name
$key = 'plural_' . $str . $count;
if (isset(self::$cache[$key])) {
return self::$cache[$key];
}
if (inflector::uncountable($str)) {
return self::$cache[$key] = $str;
}
if (empty(self::$irregular)) {
// Cache irregular words
self::$irregular = Kohana::config('inflector.irregular');
}
if (isset(self::$irregular[$str])) {
$str = self::$irregular[$str];
} elseif (preg_match('/[sxz]$/', $str) or preg_match('/[^aeioudgkprt]h$/', $str)) {
$str .= 'es';
} elseif (preg_match('/[^aeiou]y$/', $str)) {
// Change "y" to "ies"
$str = substr_replace($str, 'ies', -1);
} else {
$str .= 's';
}
// Set the cache and return
return self::$cache[$key] = $str;
}