You are browsing a version that is no longer maintained. |
Introduction
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:
$ composer require doctrine/inflector
Here are the available methods that you can use:
Camelize
This method uses Classify and then converts the first character to lowercase:
1 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:
Singularize
1 echo Inflector::singularize('browsers'); // browser
Rules
Customize the rules for pluralization and singularization:
The arguments for the rules
method are:
$type
- The type of inflection, eitherplural
orsingular
$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.