[ Index ] |
|
Code source de PHPonTrax 2.6.6-svn |
1 <?php 2 /** 3 * File containing the Inflections class and default inflections 4 * 5 * (PHP 5) 6 * 7 * @package PHPonTrax 8 * @version $Id: inflector.php 195 2006-04-03 22:27:26Z haas $ 9 * @copyright (c) 2005 John Peterson 10 * 11 * Permission is hereby granted, free of charge, to any person obtaining 12 * a copy of this software and associated documentation files (the 13 * "Software"), to deal in the Software without restriction, including 14 * without limitation the rights to use, copy, modify, merge, publish, 15 * distribute, sublicense, and/or sell copies of the Software, and to 16 * permit persons to whom the Software is furnished to do so, subject to 17 * the following conditions: 18 * 19 * The above copyright notice and this permission notice shall be 20 * included in all copies or substantial portions of the Software. 21 * 22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 26 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 27 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 28 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 */ 30 31 32 # Start Default Inflections 33 34 Inflections::plural('/$/', 's'); 35 Inflections::plural('/s$/i', 's'); 36 Inflections::plural('/(ax|test)is$/i', '\1es'); 37 Inflections::plural('/(octop|vir)us$/i', '\1i'); 38 Inflections::plural('/(alias|status)$/i', '\1es'); 39 Inflections::plural('/(bu)s$/i', '\1ses'); 40 Inflections::plural('/(buffal|tomat)o$/i', '\1oes'); 41 Inflections::plural('/([ti])um$/i', '\1a'); 42 Inflections::plural('/sis$/i', 'ses'); 43 Inflections::plural('/(?:([^f])fe|([lr])f)$/i', '\1\2ves'); 44 Inflections::plural('/(hive)$/i', '\1s'); 45 Inflections::plural('/([^aeiouy]|qu)y$/i', '\1ies'); 46 Inflections::plural('/([^aeiouy]|qu)ies$/i', '\1y'); 47 Inflections::plural('/(x|ch|ss|sh)$/i', '\1es'); 48 Inflections::plural('/(matr|vert|ind)ix|ex$/i', '\1ices'); 49 Inflections::plural('/([m|l])ouse$/i', '\1ice'); 50 Inflections::plural('/^(ox)$/i', '\1en'); 51 Inflections::plural('/(quiz)$/i', '\1zes'); 52 53 Inflections::singular('/s$/i', ''); 54 Inflections::singular('/(n)ews$/i', '\1ews'); 55 Inflections::singular('/([ti])a$/i', '\1um'); 56 Inflections::singular('/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i', '\1\2sis'); 57 Inflections::singular('/(^analy)ses$/i', '\1sis'); 58 Inflections::singular('/([^f])ves$/i', '\1fe'); 59 Inflections::singular('/(hive)s$/i', '\1'); 60 Inflections::singular('/(tive)s$/i', '\1'); 61 Inflections::singular('/([lr])ves$/i', '\1f'); 62 Inflections::singular('/([^aeiouy]|qu)ies$/i', '\1y'); 63 Inflections::singular('/(s)eries$/i', '\1eries'); 64 Inflections::singular('/(m)ovies$/i', '\1ovie'); 65 Inflections::singular('/(x|ch|ss|sh)es$/i', '\1'); 66 Inflections::singular('/([m|l])ice$/i', '\1ouse'); 67 Inflections::singular('/(bus)es$/i', '\1'); 68 Inflections::singular('/(o)es$/i', '\1'); 69 Inflections::singular('/(shoe)s$/i', '\1'); 70 Inflections::singular('/(cris|ax|test)es$/i', '\1is'); 71 Inflections::singular('/([octop|vir])i$/i', '\1us'); 72 Inflections::singular('/(alias|status)es$/i', '\1'); 73 Inflections::singular('/^(ox)en/i', '\1'); 74 Inflections::singular('/(vert|ind)ices$/i', '\1ex'); 75 Inflections::singular('/(matr)ices$/i', '\1ix'); 76 Inflections::singular('/(quiz)zes$/i', '\1'); 77 78 Inflections::irregular('person', 'people'); 79 Inflections::irregular('man', 'men'); 80 Inflections::irregular('child', 'children'); 81 Inflections::irregular('sex', 'sexes'); 82 Inflections::irregular('move', 'moves'); 83 84 Inflections::uncountable('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); 85 86 # End Default Inflections 87 88 89 /** 90 * Implement the Trax naming convention 91 * 92 * Inflections is never instantiated. 93 */ 94 class Inflections { 95 96 public static $plurals = array(); 97 98 public static $singulars = array(); 99 100 public static $uncountables = array(); 101 102 # Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression. 103 # The replacement should always be a string that may include references to the matched data from the rule. 104 function plural($rule, $replacement) { 105 array_unshift(self::$plurals, array("rule" => $rule, "replacement" => $replacement)); 106 } 107 108 # Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression. 109 # The replacement should always be a string that may include references to the matched data from the rule. 110 function singular($rule, $replacement) { 111 array_unshift(self::$singulars, array("rule" => $rule, "replacement" => $replacement)); 112 } 113 114 # Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used 115 # for strings, not regular expressions. You simply pass the irregular in singular and plural form. 116 # 117 # Examples: 118 # Inflections::irregular('octopus', 'octopi') 119 # Inflections::irregular('person', 'people') 120 function irregular($singular, $plural) { 121 self::plural('/('.preg_quote(substr($singular,0,1)).')'.preg_quote(substr($singular,1)).'$/i', '\1'.preg_quote(substr($plural,1))); 122 self::singular('/('.preg_quote(substr($plural,0,1)).')'.preg_quote(substr($plural,1)).'$/i', '\1'.preg_quote(substr($singular,1))); 123 } 124 125 # Add uncountable words that shouldn't be attempted inflected. 126 # 127 # Examples: 128 # Inflections::uncountable("money") 129 # Inflections::uncountable("money", "information") 130 # Inflections::uncountable(array("money", "information", "rice")) 131 function uncountable() { 132 $args = func_get_args(); 133 if(is_array($args[0])) { 134 $args = $args[0]; 135 } 136 foreach($args as $word) { 137 self::$uncountables[] = $word; 138 } 139 } 140 141 # Clears the loaded inflections within a given scope (functionault is :all). Give the scope as a symbol of the inflection type, 142 # the options are: "plurals", "singulars", "uncountables" 143 # 144 # Examples: 145 # Inflections::clear("all") 146 # Inflections::clear("plurals") 147 function clear($scope = "all") { 148 if($scope == "all") { 149 self::$plurals = self::$singulars = self::$uncountables = array(); 150 } else { 151 self::$$scope = array(); 152 } 153 } 154 155 } 156 157 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 20:04:38 2007 | par Balluche grâce à PHPXref 0.7 |