Пример #1
0
 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);
 }
 /**
  * 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;
 }