[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 * 15 * This software consists of voluntary contributions made by many individuals 16 * and is licensed under the MIT license. For more information, see 17 * <http://www.doctrine-project.org>. 18 */ 19 20 namespace Doctrine\Common\Inflector; 21 22 use Doctrine\Inflector\Inflector as InflectorObject; 23 use Doctrine\Inflector\InflectorFactory; 24 use Doctrine\Inflector\LanguageInflectorFactory; 25 use Doctrine\Inflector\Rules\Pattern; 26 use Doctrine\Inflector\Rules\Patterns; 27 use Doctrine\Inflector\Rules\Ruleset; 28 use Doctrine\Inflector\Rules\Substitution; 29 use Doctrine\Inflector\Rules\Substitutions; 30 use Doctrine\Inflector\Rules\Transformation; 31 use Doctrine\Inflector\Rules\Transformations; 32 use Doctrine\Inflector\Rules\Word; 33 use InvalidArgumentException; 34 use function array_keys; 35 use function array_map; 36 use function array_unshift; 37 use function array_values; 38 use function sprintf; 39 use function trigger_error; 40 use const E_USER_DEPRECATED; 41 42 /** 43 * @deprecated 44 */ 45 class Inflector 46 { 47 /** 48 * @var LanguageInflectorFactory|null 49 */ 50 private static $factory; 51 52 /** @var InflectorObject|null */ 53 private static $instance; 54 55 private static function getInstance() : InflectorObject 56 { 57 if (self::$factory === null) { 58 self::$factory = self::createFactory(); 59 } 60 61 if (self::$instance === null) { 62 self::$instance = self::$factory->build(); 63 } 64 65 return self::$instance; 66 } 67 68 private static function createFactory() : LanguageInflectorFactory 69 { 70 return InflectorFactory::create(); 71 } 72 73 /** 74 * Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'. 75 * 76 * @deprecated 77 */ 78 public static function tableize(string $word) : string 79 { 80 @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED); 81 82 return self::getInstance()->tableize($word); 83 } 84 85 /** 86 * Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'. 87 */ 88 public static function classify(string $word) : string 89 { 90 @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED); 91 92 return self::getInstance()->classify($word); 93 } 94 95 /** 96 * Camelizes a word. This uses the classify() method and turns the first character to lowercase. 97 * 98 * @deprecated 99 */ 100 public static function camelize(string $word) : string 101 { 102 @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED); 103 104 return self::getInstance()->camelize($word); 105 } 106 107 /** 108 * Uppercases words with configurable delimiters between words. 109 * 110 * Takes a string and capitalizes all of the words, like PHP's built-in 111 * ucwords function. This extends that behavior, however, by allowing the 112 * word delimiters to be configured, rather than only separating on 113 * whitespace. 114 * 115 * Here is an example: 116 * <code> 117 * <?php 118 * $string = 'top-o-the-morning to all_of_you!'; 119 * echo \Doctrine\Common\Inflector\Inflector::ucwords($string); 120 * // Top-O-The-Morning To All_of_you! 121 * 122 * echo \Doctrine\Common\Inflector\Inflector::ucwords($string, '-_ '); 123 * // Top-O-The-Morning To All_Of_You! 124 * ?> 125 * </code> 126 * 127 * @param string $string The string to operate on. 128 * @param string $delimiters A list of word separators. 129 * 130 * @return string The string with all delimiter-separated words capitalized. 131 * 132 * @deprecated 133 */ 134 public static function ucwords(string $string, string $delimiters = " \n\t\r\0\x0B-") : string 135 { 136 @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please use the "ucwords" function instead.', __METHOD__), E_USER_DEPRECATED); 137 138 return ucwords($string, $delimiters); 139 } 140 141 /** 142 * Clears Inflectors inflected value caches, and resets the inflection 143 * rules to the initial values. 144 * 145 * @deprecated 146 */ 147 public static function reset() : void 148 { 149 @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED); 150 151 self::$factory = null; 152 self::$instance = null; 153 } 154 155 /** 156 * Adds custom inflection $rules, of either 'plural' or 'singular' $type. 157 * 158 * ### Usage: 159 * 160 * {{{ 161 * Inflector::rules('plural', array('/^(inflect)or$/i' => '\1ables')); 162 * Inflector::rules('plural', array( 163 * 'rules' => array('/^(inflect)ors$/i' => '\1ables'), 164 * 'uninflected' => array('dontinflectme'), 165 * 'irregular' => array('red' => 'redlings') 166 * )); 167 * }}} 168 * 169 * @param string $type The type of inflection, either 'plural' or 'singular' 170 * @param array<string,mixed>|iterable<string,mixed> $rules An array of rules to be added. 171 * @param boolean $reset If true, will unset default inflections for all 172 * new rules that are being defined in $rules. 173 * 174 * @return void 175 * 176 * @deprecated 177 */ 178 public static function rules(string $type, iterable $rules, bool $reset = false) : void 179 { 180 @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED); 181 182 if (self::$factory === null) { 183 self::$factory = self::createFactory(); 184 } 185 186 self::$instance = null; 187 188 switch ($type) { 189 case 'singular': 190 self::$factory->withSingularRules(self::buildRuleset($rules), $reset); 191 break; 192 case 'plural': 193 self::$factory->withPluralRules(self::buildRuleset($rules), $reset); 194 break; 195 default: 196 throw new InvalidArgumentException(sprintf('Cannot define custom inflection rules for type "%s".', $type)); 197 } 198 } 199 200 /** 201 * @param array<string,mixed>|iterable<string,mixed> $rules An array of rules to be added. 202 */ 203 private static function buildRuleset(iterable $rules) : Ruleset 204 { 205 $regular = []; 206 $irregular = []; 207 $uninflected = []; 208 209 foreach ($rules as $rule => $pattern) { 210 if ( ! is_array($pattern)) { 211 $regular[$rule] = $pattern; 212 213 continue; 214 } 215 216 switch ($rule) { 217 case 'uninflected': 218 $uninflected = $pattern; 219 break; 220 case 'irregular': 221 $irregular = $pattern; 222 break; 223 case 'rules': 224 $regular = $pattern; 225 break; 226 } 227 } 228 229 return new Ruleset( 230 new Transformations(...array_map( 231 static function (string $pattern, string $replacement) : Transformation { 232 return new Transformation(new Pattern($pattern), $replacement); 233 }, 234 array_keys($regular), 235 array_values($regular) 236 )), 237 new Patterns(...array_map( 238 static function (string $pattern) : Pattern { 239 return new Pattern($pattern); 240 }, 241 $uninflected 242 )), 243 new Substitutions(...array_map( 244 static function (string $word, string $to) : Substitution { 245 return new Substitution(new Word($word), new Word($to)); 246 }, 247 array_keys($irregular), 248 array_values($irregular) 249 )) 250 ); 251 } 252 253 /** 254 * Returns a word in plural form. 255 * 256 * @param string $word The word in singular form. 257 * 258 * @return string The word in plural form. 259 * 260 * @deprecated 261 */ 262 public static function pluralize(string $word) : string 263 { 264 @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED); 265 266 return self::getInstance()->pluralize($word); 267 } 268 269 /** 270 * Returns a word in singular form. 271 * 272 * @param string $word The word in plural form. 273 * 274 * @return string The word in singular form. 275 * 276 * @deprecated 277 */ 278 public static function singularize(string $word) : string 279 { 280 @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED); 281 282 return self::getInstance()->singularize($word); 283 } 284 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |