fyre / inflector
An inflection library.
v3.0
2024-11-01 04:06 UTC
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^11
README
FyreInflector is a free, open-source inflection library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/inflector
In PHP:
use Fyre\Utility\Inflector;
Basic Usage
$inflector = new Inflector();
Methods
Camelize
Convert a delimited string into CamelCase.
$string
is the input string.$delimiter
is a string representing the delimiter, and will default to "_".
$camelized = $inflector->camelize($string, $delimiter);
Classify
Convert a table_name to a singular ClassName.
$tableName
is a string representing the table name.
$className = $inflector->classify($tableName);
Dasherize
Convert a string into kebab-case.
$string
is the input string.
$dasherized = $inflector->dasherize($string);
Humanize
Convert a delimited string into Human Readable Form.
$string
is the input string.$delimiter
is a string representing the delimiter, and will default to "_".
$title = $inflector->humanize($string, $delimiter);
Pluralize
Get the plural form of a word.
$string
is the input string.
$plural = $inflector->pluralize($string);
Rules
Add inflection rules.
$type
is a string representing the inflection type, and must be one of either "plural", "singular", "irregular" or "uncountable".$rules
is an array containing the rules to add.
$inflector->rules($type, $rules);
Singularize
Get the singular form of a word.
$string
is the input string.
$singular = $inflector->singularize($string);
Tableize
Convert a ClassName to a pluralized table_name.
$className
is a string representing the class name.
$tableName = $inflector->tableize($className);
Underscore
Convert a string into snake_case.
$string
is the input string.
$underscored = $inflector->underscore($string);
Variable
Convert a delimited string into camelBack.
$string
is the input string.
$variable = $inflector->variable($string);