doctrine/inflector
Doctrine Inflector is a lightweight PHP library for common string transformations: convert words between singular and plural forms, and handle case changes. Useful for naming conventions in frameworks and tools where consistent word inflection is needed.
Start by installing the package via Composer:
composer require doctrine/inflector
Then, instantiate the inflector for your target language (e.g., English):
use Doctrine\Inflector\InflectorFactory;
$inflector = InflectorFactory::create()->build();
Begin with basic pluralization/singularization and casing transformations:
echo $inflector->pluralize('person'); // 'people'
echo $inflector->singularize('vertices'); // 'vertex'
echo $inflector->camelize('user_name'); // 'userName'
echo $inflector->snakeCase('UserName'); // 'user_name'
The README and /docs directory in the repo provide concise API examples—start there for quick validation.
$tableName = $inflector->tableize('UserProfile'); // 'user_profiles'
$className = $inflector->classify('product_categories'); // 'ProductCategory'
Str::plural() is unavailable. Since it’s PSR- compliant and dependency-light, drop it into any project.$inflector = InflectorFactory::createForLocale('es')->build(); // Spanish rules
$inflector->getPluralRuleRuleset()->addIrregular('octopus', 'octopodes');
Inflector::pluralize()) entirely—use the new Inflector instance methods only. If upgrading, update composer constraints to "doctrine/inflector": "^2.0" and audit usages.createForLocale() for non-English text; otherwise, words like criterium → criteriums (incorrect vs criteria) will slip through.Uninflected list is extensive but not exhaustive. If a word fails inflection (e.g., data staying plural), extend uninflected words:
$inflector->getUninflected()->add('/^(data|equipment)$/i');
camelize('foo-bar') → 'fooBar', but humanize() (not part of Inflector) isn’t included. Use snakeCase() + titleCase() from other libraries for roundtrips.InflectorFactory on every request.test/InflectorTest.php. Check them when debugging unexpected output (e.g., why nursery → nurseries but brownie → brownies).How can I help you explore Laravel packages today?