### Install Doctrine Inflector Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Installs the Doctrine Inflector library using Composer. This is the standard method for adding the library to your PHP project. ```console $ composer require doctrine/inflector ``` -------------------------------- ### Create Default English Inflector Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Creates a default English inflector instance using the InflectorFactory. This is the simplest way to get started with the library. ```php use Doctrine\Inflector\InflectorFactory; $inflector = InflectorFactory::create()->build(); ``` -------------------------------- ### Custom Singular and Plural Rules Setup Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Configures custom singular and plural rules using the InflectorFactory. This allows for fine-grained control over how words are inflected. ```php use Doctrine\Inflector\InflectorFactory; use Doctrine\Inflector\Rules\Pattern; use Doctrine\Inflector\Rules\Patterns; use Doctrine\Inflector\Rules\Ruleset; use Doctrine\Inflector\Rules\Substitution; use Doctrine\Inflector\Rules\Substitutions; use Doctrine\Inflector\Rules\Transformation; use Doctrine\Inflector\Rules\Transformations; use Doctrine\Inflector\Rules\Word; $inflector = InflectorFactory::create() ->withSingularRules( new Ruleset( new Transformations( new Transformation(new Pattern('/^(bil)er$/i'), '\1'), new Transformation(new Pattern('/^(inflec|contribu)tors$/i'), '\1ta') ), new Patterns(new Pattern('singulars')), new Substitutions(new Substitution(new Word('spins'), new Word('spinor'))) ) ) ->withPluralRules( new Ruleset( new Transformations( new Transformation(new Pattern('^(bil)er$'), '\1'), new Transformation(new Pattern('^(inflec|contribu)tors$'), '\1ta') ), new Patterns(new Pattern('noflect'), new Pattern('abtuse')), new Substitutions( new Substitution(new Word('amaze'), new Word('amazable')), new Substitution(new Word('phone'), new Word('phonezes')) ) ) ) ->build(); ``` -------------------------------- ### No Operation Inflector Example Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Demonstrates the use of NoopWordInflector, which implements a Null Object pattern for inflectors that perform no operations. Useful for disabling inflection. ```php use Doctrine\Inflector\Inflector; use Doctrine\Inflector\NoopWordInflector; $inflector = new Inflector(new NoopWordInflector(), new NoopWordInflector()); ``` -------------------------------- ### Camelize Conversion Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Converts a snake_case string to camelCase, capitalizing the first letter of each word except the first word. For example, 'model_name' becomes 'modelName'. ```php echo $inflector->camelize('model_name'); // modelName ``` -------------------------------- ### Classify Conversion Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Converts a snake_case string to CamelCase. For example, 'model_name' becomes 'ModelName'. ```php echo $inflector->classify('model_name'); // ModelName ``` -------------------------------- ### Tableize Conversion Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Converts a CamelCase string to snake_case. For example, 'ModelName' becomes 'model_name'. ```php echo $inflector->tableize('ModelName'); // model_name ``` -------------------------------- ### Generate URL-Friendly String Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Creates a URL-friendly string from a given text by converting it to lowercase and replacing spaces with hyphens. ```php echo $inflector->urlize('My first blog post'); // my-first-blog-post ``` -------------------------------- ### Manually Construct Inflector Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Manually constructs an Inflector instance by providing custom or default singular and plural rules. This offers more control over the inflection process. ```php use Doctrine\Inflector\CachedWordInflector; use Doctrine\Inflector\RulesetInflector; use Doctrine\Inflector\Rules\English; $inflector = new Inflector( new CachedWordInflector(new RulesetInflector( English\Rules::getSingularRuleset() )), new CachedWordInflector(new RulesetInflector( English\Rules::getPluralRuleset() )) ); ``` -------------------------------- ### Create Inflector for a Specific Language Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Creates an inflector instance for a specified language, such as Spanish. The InflectorFactory supports multiple languages out-of-the-box. ```php use Doctrine\Inflector\InflectorFactory; use Doctrine\Inflector\Language; $inflector = InflectorFactory::createForLanguage(Language::SPANISH)->build(); ``` -------------------------------- ### Pluralize a Word Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Converts a given word into its plural form. This function handles common English pluralization rules. ```php echo $inflector->pluralize('browser'); // browsers ``` -------------------------------- ### Capitalize Words Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Capitalizes the first letter of each word in a string, similar to PHP's ucwords function but with potential extended behavior. ```php echo $inflector->capitalize('some example string'); // Some Example String ``` -------------------------------- ### Singularize a Word Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Converts a given word into its singular form. This function handles common English singularization rules. ```php echo $inflector->singularize('browsers'); // browser ``` -------------------------------- ### Capitalize String with Custom Delimiters Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Capitalizes a string, allowing for custom word delimiters beyond whitespace. This is useful for handling strings with mixed separators. ```php $string = 'top-o-the-morning to all_of_you!'; echo $inflector->capitalize($string); // Top-O-The-Morning To All_of_you! echo $inflector->capitalize($string, '-_ '); // Top-O-The-Morning To All_Of_You! ``` -------------------------------- ### Remove Accents from String Source: https://github.com/doctrine/inflector/blob/2.0.x/docs/en/index.rst Removes diacritical marks (accents) from characters in a string, returning an unaccented version. ```php echo $inflector->unaccent('año'); // ano ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.