pax_global_header00006660000000000000000000000064135624342530014521gustar00rootroot0000000000000052 comment=30f10dcc2f78e5034da835fc842b63758e493995 php-doctrine-inflector-1.3.1/000077500000000000000000000000001356243425300161025ustar00rootroot00000000000000php-doctrine-inflector-1.3.1/.gitignore000066400000000000000000000000601356243425300200660ustar00rootroot00000000000000vendor/ composer.lock composer.phar phpunit.xml php-doctrine-inflector-1.3.1/.travis.yml000066400000000000000000000002541356243425300202140ustar00rootroot00000000000000language: php sudo: false cache: directory: - $HOME/.composer/cache php: - 7.1 - 7.2 - 7.3 install: - composer install -n script: - vendor/bin/phpunit php-doctrine-inflector-1.3.1/LICENSE000066400000000000000000000020511356243425300171050ustar00rootroot00000000000000Copyright (c) 2006-2015 Doctrine Project Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. php-doctrine-inflector-1.3.1/README.md000066400000000000000000000004371356243425300173650ustar00rootroot00000000000000# Doctrine Inflector Doctrine Inflector is a small library that can perform string manipulations with regard to upper-/lowercase and singular/plural forms of words. [![Build Status](https://travis-ci.org/doctrine/inflector.svg?branch=master)](https://travis-ci.org/doctrine/inflector) php-doctrine-inflector-1.3.1/composer.json000066400000000000000000000021431356243425300206240ustar00rootroot00000000000000{ "name": "doctrine/inflector", "type": "library", "description": "Common String Manipulations with regard to casing and singular/plural rules.", "keywords": ["string", "inflection", "singularize", "pluralize"], "homepage": "http://www.doctrine-project.org", "license": "MIT", "authors": [ {"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"}, {"name": "Roman Borschel", "email": "roman@code-factory.org"}, {"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"}, {"name": "Jonathan Wage", "email": "jonwage@gmail.com"}, {"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"} ], "require": { "php": "^7.1" }, "require-dev": { "phpunit/phpunit": "^6.2" }, "autoload": { "psr-4": { "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector" } }, "autoload-dev": { "psr-4": { "Doctrine\\Tests\\Common\\Inflector\\": "tests/Doctrine/Tests/Common/Inflector" } }, "extra": { "branch-alias": { "dev-master": "1.3.x-dev" } } } php-doctrine-inflector-1.3.1/docs/000077500000000000000000000000001356243425300170325ustar00rootroot00000000000000php-doctrine-inflector-1.3.1/docs/en/000077500000000000000000000000001356243425300174345ustar00rootroot00000000000000php-doctrine-inflector-1.3.1/docs/en/index.rst000066400000000000000000000053061356243425300213010ustar00rootroot00000000000000Introduction ============ The Doctrine Inflector has static methods for inflecting text. The features include pluralization, singularization, converting between camelCase and under_score and capitalizing words. All you need to use the Inflector is the ``Doctrine\Common\Inflector\Inflector`` class. Installation ============ You can install the Inflector with composer: .. code-block:: $ composer require doctrine/inflector Here are the available methods that you can use: Tableize ======== Converts ``ModelName`` to ``model_name``: .. code-block:: php echo Inflector::tableize('ModelName'); // model_name Classify ======== Converts ``model_name`` to ``ModelName``: .. code-block:: php echo Inflector::classify('model_name'); // ModelName Camelize ======== This method uses `Classify`_ and then converts the first character to lowercase: .. code-block:: php echo Inflector::camelize('model_name'); // modelName ucwords ======= Takes a string and capitalizes all of the words, like PHP's built-in ucwords function. This extends that behavior, however, by allowing the word delimiters to be configured, rather than only separating on whitespace. Here is an example: .. code-block:: php $string = 'top-o-the-morning to all_of_you!'; echo Inflector::ucwords($string); // Top-O-The-Morning To All_of_you! echo Inflector::ucwords($string, '-_ '); // Top-O-The-Morning To All_Of_You! Pluralize ========= Returns a word in plural form. .. code-block:: php echo Inflector::pluralize('browser'); // browsers Singularize =========== .. code-block:: php echo Inflector::singularize('browsers'); // browser Rules ===== Customize the rules for pluralization and singularization: .. code-block:: php Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']); Inflector::rules('plural', [ 'rules' => ['/^(inflect)ors$/i' => '\1ables'], 'uninflected' => ['dontinflectme'], 'irregular' => ['red' => 'redlings'] ]); The arguments for the ``rules`` method are: - ``$type`` - The type of inflection, either ``plural`` or ``singular`` - ``$rules`` - An array of rules to be added. - ``$reset`` - If true, will unset default inflections for all new rules that are being defined in $rules. Reset ===== Clears Inflectors inflected value caches, and resets the inflection rules to the initial values. .. code-block:: php Inflector::reset(); Slugify ======= You can easily use the Inflector to create a slug from a string of text by using the `tableize`_ method and replacing underscores with hyphens: .. code-block:: php public static function slugify(string $text) : string { return str_replace('_', '-', Inflector::tableize($text)); } php-doctrine-inflector-1.3.1/lib/000077500000000000000000000000001356243425300166505ustar00rootroot00000000000000php-doctrine-inflector-1.3.1/lib/Doctrine/000077500000000000000000000000001356243425300204175ustar00rootroot00000000000000php-doctrine-inflector-1.3.1/lib/Doctrine/Common/000077500000000000000000000000001356243425300216475ustar00rootroot00000000000000php-doctrine-inflector-1.3.1/lib/Doctrine/Common/Inflector/000077500000000000000000000000001356243425300235745ustar00rootroot00000000000000php-doctrine-inflector-1.3.1/lib/Doctrine/Common/Inflector/Inflector.php000066400000000000000000000425641356243425300262450ustar00rootroot00000000000000. */ namespace Doctrine\Common\Inflector; /** * Doctrine inflector has static methods for inflecting text. * * The methods in these classes are from several different sources collected * across several different php projects and several different authors. The * original author names and emails are not known. * * Pluralize & Singularize implementation are borrowed from CakePHP with some modifications. * * @link www.doctrine-project.org * @since 1.0 * @author Konsta Vesterinen * @author Jonathan H. Wage */ class Inflector { /** * Plural inflector rules. * * @var string[][] */ private static $plural = array( 'rules' => array( '/(s)tatus$/i' => '\1\2tatuses', '/(quiz)$/i' => '\1zes', '/^(ox)$/i' => '\1\2en', '/([m|l])ouse$/i' => '\1ice', '/(matr|vert|ind)(ix|ex)$/i' => '\1ices', '/(x|ch|ss|sh)$/i' => '\1es', '/([^aeiouy]|qu)y$/i' => '\1ies', '/(hive|gulf)$/i' => '\1s', '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', '/sis$/i' => 'ses', '/([ti])um$/i' => '\1a', '/(c)riterion$/i' => '\1riteria', '/(p)erson$/i' => '\1eople', '/(m)an$/i' => '\1en', '/(c)hild$/i' => '\1hildren', '/(f)oot$/i' => '\1eet', '/(buffal|her|potat|tomat|volcan)o$/i' => '\1\2oes', '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i' => '\1i', '/us$/i' => 'uses', '/(alias)$/i' => '\1es', '/(analys|ax|cris|test|thes)is$/i' => '\1es', '/s$/' => 's', '/^$/' => '', '/$/' => 's', ), 'uninflected' => array( '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'people', 'cookie', 'police', ), 'irregular' => array( 'atlas' => 'atlases', 'axe' => 'axes', 'beef' => 'beefs', 'brother' => 'brothers', 'cafe' => 'cafes', 'canvas' => 'canvases', 'chateau' => 'chateaux', 'niveau' => 'niveaux', 'child' => 'children', 'cookie' => 'cookies', 'corpus' => 'corpuses', 'cow' => 'cows', 'criterion' => 'criteria', 'curriculum' => 'curricula', 'demo' => 'demos', 'domino' => 'dominoes', 'echo' => 'echoes', 'foot' => 'feet', 'fungus' => 'fungi', 'ganglion' => 'ganglions', 'gas' => 'gases', 'genie' => 'genies', 'genus' => 'genera', 'goose' => 'geese', 'graffito' => 'graffiti', 'hippopotamus' => 'hippopotami', 'hoof' => 'hoofs', 'human' => 'humans', 'iris' => 'irises', 'larva' => 'larvae', 'leaf' => 'leaves', 'loaf' => 'loaves', 'man' => 'men', 'medium' => 'media', 'memorandum' => 'memoranda', 'money' => 'monies', 'mongoose' => 'mongooses', 'motto' => 'mottoes', 'move' => 'moves', 'mythos' => 'mythoi', 'niche' => 'niches', 'nucleus' => 'nuclei', 'numen' => 'numina', 'occiput' => 'occiputs', 'octopus' => 'octopuses', 'opus' => 'opuses', 'ox' => 'oxen', 'passerby' => 'passersby', 'penis' => 'penises', 'person' => 'people', 'plateau' => 'plateaux', 'runner-up' => 'runners-up', 'sex' => 'sexes', 'soliloquy' => 'soliloquies', 'son-in-law' => 'sons-in-law', 'syllabus' => 'syllabi', 'testis' => 'testes', 'thief' => 'thieves', 'tooth' => 'teeth', 'tornado' => 'tornadoes', 'trilby' => 'trilbys', 'turf' => 'turfs', 'valve' => 'valves', 'volcano' => 'volcanoes', ) ); /** * Singular inflector rules. * * @var string[][] */ private static $singular = array( 'rules' => array( '/(s)tatuses$/i' => '\1\2tatus', '/^(.*)(menu)s$/i' => '\1\2', '/(quiz)zes$/i' => '\\1', '/(matr)ices$/i' => '\1ix', '/(vert|ind)ices$/i' => '\1ex', '/^(ox)en/i' => '\1', '/(alias)(es)*$/i' => '\1', '/(buffal|her|potat|tomat|volcan)oes$/i' => '\1o', '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|viri?)i$/i' => '\1us', '/([ftw]ax)es/i' => '\1', '/(analys|ax|cris|test|thes)es$/i' => '\1is', '/(shoe|slave)s$/i' => '\1', '/(o)es$/i' => '\1', '/ouses$/' => 'ouse', '/([^a])uses$/' => '\1us', '/([m|l])ice$/i' => '\1ouse', '/(x|ch|ss|sh)es$/i' => '\1', '/(m)ovies$/i' => '\1\2ovie', '/(s)eries$/i' => '\1\2eries', '/([^aeiouy]|qu)ies$/i' => '\1y', '/([lr])ves$/i' => '\1f', '/(tive)s$/i' => '\1', '/(hive)s$/i' => '\1', '/(drive)s$/i' => '\1', '/(dive)s$/i' => '\1', '/(olive)s$/i' => '\1', '/([^fo])ves$/i' => '\1fe', '/(^analy)ses$/i' => '\1sis', '/(analy|diagno|^ba|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', '/(c)riteria$/i' => '\1riterion', '/([ti])a$/i' => '\1um', '/(p)eople$/i' => '\1\2erson', '/(m)en$/i' => '\1an', '/(c)hildren$/i' => '\1\2hild', '/(f)eet$/i' => '\1oot', '/(n)ews$/i' => '\1\2ews', '/eaus$/' => 'eau', '/^(.*us)$/' => '\\1', '/s$/i' => '', ), 'uninflected' => array( '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', '.*ss', 'data', 'police', 'pants', 'clothes', ), 'irregular' => array( 'abuses' => 'abuse', 'avalanches' => 'avalanche', 'caches' => 'cache', 'criteria' => 'criterion', 'curves' => 'curve', 'emphases' => 'emphasis', 'foes' => 'foe', 'geese' => 'goose', 'graves' => 'grave', 'hoaxes' => 'hoax', 'media' => 'medium', 'neuroses' => 'neurosis', 'waves' => 'wave', 'oases' => 'oasis', 'valves' => 'valve', ) ); /** * Words that should not be inflected. * * @var array */ private static $uninflected = array( '.*?media', 'Amoyese', 'audio', 'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus', 'carp', 'chassis', 'clippers', 'cod', 'coitus', 'compensation', 'Congoese', 'contretemps', 'coreopsis', 'corps', 'data', 'debris', 'deer', 'diabetes', 'djinn', 'education', 'eland', 'elk', 'emoji', 'equipment', 'evidence', 'Faroese', 'feedback', 'fish', 'flounder', 'Foochowese', 'Furniture', 'furniture', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'gold', 'headquarters', 'herpes', 'hijinks', 'Hottentotese', 'information', 'innings', 'jackanapes', 'jedi', 'Kiplingese', 'knowledge', 'Kongoese', 'love', 'Lucchese', 'Luggage', 'mackerel', 'Maltese', 'metadata', 'mews', 'moose', 'mumps', 'Nankingese', 'news', 'nexus', 'Niasese', 'nutrition', 'offspring', 'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'plankton', 'pliers', 'pokemon', 'police', 'Portuguese', 'proceedings', 'rabies', 'rain', 'rhinoceros', 'rice', 'salmon', 'Sarawakese', 'scissors', 'sea[- ]bass', 'series', 'Shavese', 'shears', 'sheep', 'siemens', 'species', 'staff', 'swine', 'traffic', 'trousers', 'trout', 'tuna', 'us', 'Vermontese', 'Wenchowese', 'wheat', 'whiting', 'wildebeest', 'Yengeese' ); /** * Method cache array. * * @var array */ private static $cache = array(); /** * The initial state of Inflector so reset() works. * * @var array */ private static $initialState = array(); /** * Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'. */ public static function tableize(string $word) : string { return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $word)); } /** * Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'. */ public static function classify(string $word) : string { return str_replace([' ', '_', '-'], '', ucwords($word, ' _-')); } /** * Camelizes a word. This uses the classify() method and turns the first character to lowercase. */ public static function camelize(string $word) : string { return lcfirst(self::classify($word)); } /** * Uppercases words with configurable delimeters between words. * * Takes a string and capitalizes all of the words, like PHP's built-in * ucwords function. This extends that behavior, however, by allowing the * word delimeters to be configured, rather than only separating on * whitespace. * * Here is an example: * * * * * @param string $string The string to operate on. * @param string $delimiters A list of word separators. * * @return string The string with all delimeter-separated words capitalized. */ public static function ucwords(string $string, string $delimiters = " \n\t\r\0\x0B-") : string { return ucwords($string, $delimiters); } /** * Clears Inflectors inflected value caches, and resets the inflection * rules to the initial values. */ public static function reset() : void { if (empty(self::$initialState)) { self::$initialState = get_class_vars('Inflector'); return; } foreach (self::$initialState as $key => $val) { if ($key !== 'initialState') { self::${$key} = $val; } } } /** * Adds custom inflection $rules, of either 'plural' or 'singular' $type. * * ### Usage: * * {{{ * Inflector::rules('plural', array('/^(inflect)or$/i' => '\1ables')); * Inflector::rules('plural', array( * 'rules' => array('/^(inflect)ors$/i' => '\1ables'), * 'uninflected' => array('dontinflectme'), * 'irregular' => array('red' => 'redlings') * )); * }}} * * @param string $type The type of inflection, either 'plural' or 'singular' * @param array|iterable $rules An array of rules to be added. * @param boolean $reset If true, will unset default inflections for all * new rules that are being defined in $rules. * * @return void */ public static function rules(string $type, iterable $rules, bool $reset = false) : void { foreach ($rules as $rule => $pattern) { if ( ! is_array($pattern)) { continue; } if ($reset) { self::${$type}[$rule] = $pattern; } else { self::${$type}[$rule] = ($rule === 'uninflected') ? array_merge($pattern, self::${$type}[$rule]) : $pattern + self::${$type}[$rule]; } unset($rules[$rule], self::${$type}['cache' . ucfirst($rule)]); if (isset(self::${$type}['merged'][$rule])) { unset(self::${$type}['merged'][$rule]); } if ($type === 'plural') { self::$cache['pluralize'] = self::$cache['tableize'] = array(); } elseif ($type === 'singular') { self::$cache['singularize'] = array(); } } self::${$type}['rules'] = $rules + self::${$type}['rules']; } /** * Returns a word in plural form. * * @param string $word The word in singular form. * * @return string The word in plural form. */ public static function pluralize(string $word) : string { if (isset(self::$cache['pluralize'][$word])) { return self::$cache['pluralize'][$word]; } if (!isset(self::$plural['merged']['irregular'])) { self::$plural['merged']['irregular'] = self::$plural['irregular']; } if (!isset(self::$plural['merged']['uninflected'])) { self::$plural['merged']['uninflected'] = array_merge(self::$plural['uninflected'], self::$uninflected); } if (!isset(self::$plural['cacheUninflected']) || !isset(self::$plural['cacheIrregular'])) { self::$plural['cacheUninflected'] = '(?:' . implode('|', self::$plural['merged']['uninflected']) . ')'; self::$plural['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$plural['merged']['irregular'])) . ')'; } if (preg_match('/(.*)\\b(' . self::$plural['cacheIrregular'] . ')$/i', $word, $regs)) { self::$cache['pluralize'][$word] = $regs[1] . $word[0] . substr(self::$plural['merged']['irregular'][strtolower($regs[2])], 1); return self::$cache['pluralize'][$word]; } if (preg_match('/^(' . self::$plural['cacheUninflected'] . ')$/i', $word, $regs)) { self::$cache['pluralize'][$word] = $word; return $word; } foreach (self::$plural['rules'] as $rule => $replacement) { if (preg_match($rule, $word)) { self::$cache['pluralize'][$word] = preg_replace($rule, $replacement, $word); return self::$cache['pluralize'][$word]; } } } /** * Returns a word in singular form. * * @param string $word The word in plural form. * * @return string The word in singular form. */ public static function singularize(string $word) : string { if (isset(self::$cache['singularize'][$word])) { return self::$cache['singularize'][$word]; } if (!isset(self::$singular['merged']['uninflected'])) { self::$singular['merged']['uninflected'] = array_merge( self::$singular['uninflected'], self::$uninflected ); } if (!isset(self::$singular['merged']['irregular'])) { self::$singular['merged']['irregular'] = array_merge( self::$singular['irregular'], array_flip(self::$plural['irregular']) ); } if (!isset(self::$singular['cacheUninflected']) || !isset(self::$singular['cacheIrregular'])) { self::$singular['cacheUninflected'] = '(?:' . implode('|', self::$singular['merged']['uninflected']) . ')'; self::$singular['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$singular['merged']['irregular'])) . ')'; } if (preg_match('/(.*)\\b(' . self::$singular['cacheIrregular'] . ')$/i', $word, $regs)) { self::$cache['singularize'][$word] = $regs[1] . $word[0] . substr(self::$singular['merged']['irregular'][strtolower($regs[2])], 1); return self::$cache['singularize'][$word]; } if (preg_match('/^(' . self::$singular['cacheUninflected'] . ')$/i', $word, $regs)) { self::$cache['singularize'][$word] = $word; return $word; } foreach (self::$singular['rules'] as $rule => $replacement) { if (preg_match($rule, $word)) { self::$cache['singularize'][$word] = preg_replace($rule, $replacement, $word); return self::$cache['singularize'][$word]; } } self::$cache['singularize'][$word] = $word; return $word; } } php-doctrine-inflector-1.3.1/phpunit.xml.dist000066400000000000000000000013741356243425300212620ustar00rootroot00000000000000 ./tests/Doctrine/ ./lib/Doctrine/ performance php-doctrine-inflector-1.3.1/tests/000077500000000000000000000000001356243425300172445ustar00rootroot00000000000000php-doctrine-inflector-1.3.1/tests/Doctrine/000077500000000000000000000000001356243425300210135ustar00rootroot00000000000000php-doctrine-inflector-1.3.1/tests/Doctrine/Tests/000077500000000000000000000000001356243425300221155ustar00rootroot00000000000000php-doctrine-inflector-1.3.1/tests/Doctrine/Tests/Common/000077500000000000000000000000001356243425300233455ustar00rootroot00000000000000php-doctrine-inflector-1.3.1/tests/Doctrine/Tests/Common/Inflector/000077500000000000000000000000001356243425300252725ustar00rootroot00000000000000php-doctrine-inflector-1.3.1/tests/Doctrine/Tests/Common/Inflector/InflectorTest.php000066400000000000000000000416771356243425300306070ustar00rootroot00000000000000assertEquals( $singular, Inflector::singularize($plural), "'$plural' should be singularized to '$singular'" ); } /** * @dataProvider dataSampleWords */ public function testInflectingPlurals(string $singular, string $plural) : void { $this->assertEquals( $plural, Inflector::pluralize($singular), "'$singular' should be pluralized to '$plural'" ); } public function testCustomPluralRule() : void { Inflector::reset(); Inflector::rules('plural', array('/^(custom)$/i' => '\1izables')); $this->assertEquals(Inflector::pluralize('custom'), 'customizables'); Inflector::rules('plural', array('uninflected' => array('uninflectable'))); $this->assertEquals(Inflector::pluralize('uninflectable'), 'uninflectable'); Inflector::rules('plural', array( 'rules' => array('/^(alert)$/i' => '\1ables'), 'uninflected' => array('noflect', 'abtuse'), 'irregular' => array('amaze' => 'amazable', 'phone' => 'phonezes') )); $this->assertEquals(Inflector::pluralize('noflect'), 'noflect'); $this->assertEquals(Inflector::pluralize('abtuse'), 'abtuse'); $this->assertEquals(Inflector::pluralize('alert'), 'alertables'); $this->assertEquals(Inflector::pluralize('amaze'), 'amazable'); $this->assertEquals(Inflector::pluralize('phone'), 'phonezes'); } public function testCustomSingularRule() : void { Inflector::reset(); Inflector::rules('singular', array('/(eple)r$/i' => '\1', '/(jente)r$/i' => '\1')); $this->assertEquals(Inflector::singularize('epler'), 'eple'); $this->assertEquals(Inflector::singularize('jenter'), 'jente'); Inflector::rules('singular', array( 'rules' => array('/^(bil)er$/i' => '\1', '/^(inflec|contribu)tors$/i' => '\1ta'), 'uninflected' => array('singulars'), 'irregular' => array('spins' => 'spinor') )); $this->assertEquals(Inflector::singularize('inflectors'), 'inflecta'); $this->assertEquals(Inflector::singularize('contributors'), 'contributa'); $this->assertEquals(Inflector::singularize('spins'), 'spinor'); $this->assertEquals(Inflector::singularize('singulars'), 'singulars'); } public function testSettingNewRulesClearsCaches() : void { Inflector::reset(); $this->assertEquals(Inflector::singularize('Bananas'), 'Banana'); $this->assertEquals(Inflector::pluralize('Banana'), 'Bananas'); Inflector::rules('singular', array( 'rules' => array('/(.*)nas$/i' => '\1zzz') )); $this->assertEquals('Banazzz', Inflector::singularize('Bananas'), 'Was inflected with old rules.'); Inflector::rules('plural', array( 'rules' => array('/(.*)na$/i' => '\1zzz'), 'irregular' => array('corpus' => 'corpora') )); $this->assertEquals(Inflector::pluralize('Banana'), 'Banazzz', 'Was inflected with old rules.'); $this->assertEquals(Inflector::pluralize('corpus'), 'corpora', 'Was inflected with old irregular form.'); } public function testCustomRuleWithReset() : void { Inflector::reset(); $uninflected = array('atlas', 'lapis', 'onibus', 'pires', 'virus', '.*x'); $pluralIrregular = array('as' => 'ases'); Inflector::rules('singular', array( 'rules' => array('/^(.*)(a|e|o|u)is$/i' => '\1\2l'), 'uninflected' => $uninflected, ), true); Inflector::rules('plural', array( 'rules' => array( '/^(.*)(a|e|o|u)l$/i' => '\1\2is', ), 'uninflected' => $uninflected, 'irregular' => $pluralIrregular ), true); $this->assertEquals(Inflector::pluralize('Alcool'), 'Alcoois'); $this->assertEquals(Inflector::pluralize('Atlas'), 'Atlas'); $this->assertEquals(Inflector::singularize('Alcoois'), 'Alcool'); $this->assertEquals(Inflector::singularize('Atlas'), 'Atlas'); } public function testUcwords() : void { $this->assertSame('Top-O-The-Morning To All_of_you!', Inflector::ucwords( 'top-o-the-morning to all_of_you!')); } public function testUcwordsWithCustomDelimeters() : void { $this->assertSame('Top-O-The-Morning To All_Of_You!', Inflector::ucwords( 'top-o-the-morning to all_of_you!', '-_ ')); } /** * @dataProvider dataStringsTableize */ public function testTableize(string $expected, string $word) : void { $this->assertSame($expected, Inflector::tableize($word)); } /** * Strings which are used for testTableize. * * @return string[][] */ public function dataStringsTableize() : array { // In the format array('expected', 'word') return array( array('', ''), array('foo_bar', 'FooBar'), array('f0o_bar', 'F0oBar'), ); } /** * @dataProvider dataStringsClassify */ public function testClassify(string $expected, string $word) : void { $this->assertSame($expected, Inflector::classify($word)); } /** * Strings which are used for testClassify. * * @return string[][] */ public function dataStringsClassify() : array { // In the format array('expected', 'word') return array( array('', ''), array('FooBar', 'foo_bar'), array('FooBar', 'foo bar'), array('F0oBar', 'f0o bar'), array('F0oBar', 'f0o bar'), array('FooBar', 'foo_bar_'), ); } /** * @dataProvider dataStringsCamelize */ public function testCamelize(string $expected, string $word) : void { $this->assertSame($expected, Inflector::camelize($word)); } /** * Strings which are used for testCamelize. * * @return string[][] */ public function dataStringsCamelize() : array { // In the format array('expected', 'word') return array( array('', ''), array('fooBar', 'foo_bar'), array('fooBar', 'foo bar'), array('f0oBar', 'f0o bar'), array('f0oBar', 'f0o bar'), ); } }