Changeset 4554
- Timestamp:
- 06/24/08 04:07:31 (13 months ago)
- Files:
-
- 1 modified
-
branches/0.11/lib/Doctrine/Inflector.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.11/lib/Doctrine/Inflector.php
r4378 r4554 21 21 22 22 /** 23 * Doctrine _Inflector has static methods for inflecting text23 * Doctrine inflector has static methods for inflecting text 24 24 * 25 25 * The methods in these classes are from several different sources collected … … 39 39 { 40 40 /** 41 * pluralize42 *43 * @param string $word English noun to pluralize44 * @return stringPlural noun45 */41 * Pluralize an English noun. Converts 'Category' to 'Categories'. 42 * 43 * @param string $word English noun to pluralize 44 * @return string $word Plural noun 45 */ 46 46 public static function pluralize($word) 47 47 { … … 104 104 105 105 /** 106 * singularize107 *108 * @param string$word English noun to singularize109 * @return stringSingular noun.110 */106 * Singularize an English noun. Converts 'Quizzes' to 'Quiz'. 107 * 108 * @param string $word English noun to singularize 109 * @return string $word Singular noun. 110 */ 111 111 public static function singularize($word) 112 112 { … … 178 178 179 179 /** 180 * variablize 181 * 182 * @param string $word 183 * @return void 184 */ 185 public static function variablize($word) 186 { 187 $word = self::camelize($word); 188 189 return strtolower($word[0]) . substr($word, 1); 190 } 191 192 /** 193 * tableize 194 * 195 * @param string $name 196 * @return void 197 */ 198 public static function tableize($name) 180 * Convert word in to the format for a Doctrine table name. Converts 'ModelName' to 'model_name' 181 * 182 * @param string $word Word to tableize 183 * @return string $word Tableized word 184 */ 185 public static function tableize($word) 199 186 { 200 187 // Would prefer this but it breaks unit tests. Forces the table underscore pattern 201 188 // return self::pluralize(self::underscore($name)); 202 return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $name)); 203 } 204 205 /** 206 * classify 207 * 208 * @param string $word 189 return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $word)); 190 } 191 192 /** 193 * Convert a word in to the format for a Doctrine class name. Converts 'table_name' to 'TableName' 194 * 195 * @param string $word Word to classify 196 * @return string $word Classified word 209 197 */ 210 198 public static function classify($word) … … 214 202 215 203 /** 216 * classifyCallback217 *218 204 * Callback function to classify a classname properly. 219 205 * 220 * @param array $matchesAn array of matches from a pcre_replace call221 * @return string A string with matches 1 and mathces 3 in upper case.206 * @param array $matches An array of matches from a pcre_replace call 207 * @return string $string A string with matches 1 and mathces 3 in upper case. 222 208 */ 223 209 public static function classifyCallback($matches) … … 227 213 228 214 /** 229 * camelize 230 * 231 * @param string $word 232 * @return void 233 */ 234 public static function camelize($word) 235 { 236 if (preg_match_all('/\/(.?)/', $word, $got)) { 237 foreach ($got[1] as $k => $v){ 238 $got[1][$k] = '::' . strtoupper($v); 239 } 240 241 $word = str_replace($got[0], $got[1], $word); 242 } 243 244 return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9^:]+/', ' ', $word))); 245 } 246 247 /** 248 * seemsUtf8 215 * Check if a string has utf7 characters in it 249 216 * 250 217 * By bmorel at ssi dot fr 251 218 * 252 * @param string $str253 * @return void219 * @param string $string 220 * @return boolean $bool 254 221 */ 255 222 public static function seemsUtf8($string) … … 272 239 273 240 /** 274 * unaccent275 * 276 * @param string $string277 * @return void241 * Remove any illegal characters, accents, etc. 242 * 243 * @param string $string String to unaccent 244 * @return string $string Unaccented string 278 245 */ 279 246 public static function unaccent($string) … … 410 377 411 378 /** 412 * urlize413 * 414 * @param string $text415 * @return void379 * Convert any passed string to a url friendly string. Converts 'My first blog post' to 'my-first-blog-post' 380 * 381 * @param string $text Text to urlize 382 * @return string $text Urlized text 416 383 */ 417 384 public static function urlize($text) … … 431 398 return trim($text, '-'); 432 399 } 433 434 /**435 * underscore436 *437 * @param string $word438 * @return void439 */440 public static function underscore($word)441 {442 return strtolower(preg_replace('/[^A-Z^a-z^0-9^\/]+/', '_',443 preg_replace('/([a-z\d])([A-Z])/', '\1_\2',444 preg_replace('/([A-Z]+)([A-Z][a-z])/', '\1_\2',445 preg_replace('/::/', '/', $word)))));446 }447 400 }