当前位置: 首页>>代码示例>>PHP>>正文


PHP inflector::irregular方法代码示例

本文整理汇总了PHP中inflector::irregular方法的典型用法代码示例。如果您正苦于以下问题:PHP inflector::irregular方法的具体用法?PHP inflector::irregular怎么用?PHP inflector::irregular使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inflector的用法示例。


在下文中一共展示了inflector::irregular方法的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);
 }
开发者ID:swk,项目名称:bluebox,代码行数:41,代码来源:Bluebox_inflector.php

示例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(inflector::$cache[$key])) {
         return inflector::$cache[$key];
     }
     if (inflector::uncountable($str)) {
         return inflector::$cache[$key] = $str;
     }
     if (empty(inflector::$irregular)) {
         // Cache irregular words
         inflector::$irregular = Kohana::config('inflector.irregular');
     }
     if (isset(inflector::$irregular[$str])) {
         $str = inflector::$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 inflector::$cache[$key] = $str;
 }
开发者ID:AsteriaGamer,项目名称:steamdriven-kohana,代码行数:43,代码来源:MY_inflector.php


注:本文中的inflector::irregular方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。