Class Inflections
A representation of the inflections used by an inflector.
Methods summary
public static
get( string $locale
= 'en' )
: ICanBoogie\Inflections
Returns inflections for the specified locale.
Returns inflections for the specified locale.
Note: Inflections are shared for the same locale. If you need to alter an instance you SHOULD clone it first, otherwise your changes will affect others.
Parameters
$locale
Returns
public
__get( string $property
)
Returns the ICanBoogie\Inflections::$acronyms
, ICanBoogie\Inflections::$acronym_regex
, ICanBoogie\Inflections::$plurals
, ICanBoogie\Inflections::$singulars
,
ICanBoogie\Inflections::$uncountables
and ICanBoogie\Inflections::$humans
properties.
Returns the ICanBoogie\Inflections::$acronyms
, ICanBoogie\Inflections::$acronym_regex
, ICanBoogie\Inflections::$plurals
, ICanBoogie\Inflections::$singulars
,
ICanBoogie\Inflections::$uncountables
and ICanBoogie\Inflections::$humans
properties.
Parameters
$property
Throws
in attempt to read an unaccessible property. If the PropertyNotDefined class is not available a \InvalidArgumentException is thrown instead.
public
acronym( $word
)
Specifies a new acronym. An acronym must be specified as it will appear in a camelized string. An underscore string that contains the acronym will retain the acronym when passed to camelize, humanize, or titleize. A camelized string that contains the acronym will maintain the acronym when titleized or humanized, and will convert the acronym into a non-delimited single lowercase word when passed to underscore.
Specifies a new acronym. An acronym must be specified as it will appear in a camelized string. An underscore string that contains the acronym will retain the acronym when passed to camelize, humanize, or titleize. A camelized string that contains the acronym will maintain the acronym when titleized or humanized, and will convert the acronym into a non-delimited single lowercase word when passed to underscore.
$this->acronym('HTML'); $this->titleize('html'); // 'HTML' $this->camelize('html'); // 'HTML' $this->underscore('MyHTML'); // 'my_html'
The acronym, however, must occur as a delimited unit and not be part of another word for conversions to recognize it:
$this->acronym('HTTP'); $this->camelize('my_http_delimited'); // 'MyHTTPDelimited' $this->camelize('https'); // 'Https', not 'HTTPs' $this->underscore('HTTPS'); // 'http_s', not 'https' $this->acronym('HTTPS'); $this->camelize('https'); // 'HTTPS' $this->underscore('HTTPS'); // 'https'
Note: Acronyms that are passed to pluralize will no longer be recognized, since the acronym will not occur as a delimited unit in the pluralized result. To work around this, you must specify the pluralized form as an acronym as well:
$this->acronym('API'); $this->camelize($this->pluralize('api')); // 'Apis' $this->acronym('APIs'); $this->camelize($this->pluralize('api')); // 'APIs'
ICanBoogie\Inflections::acronym()
may be used to specify any word that contains an acronym or
otherwise needs to maintain a non-standard capitalization. The only
restriction is that the word must begin with a capital letter.
$this->acronym('RESTful'); $this->underscore('RESTful'); // 'restful' $this->underscore('RESTfulController'); // 'restful_controller' $this->titleize('RESTfulController'); // 'RESTful Controller' $this->camelize('restful'); // 'RESTful' $this->camelize('restful_controller'); // 'RESTfulController' $this->acronym('McHammer'); $this->underscore('McHammer'); // 'mchammer' $this->camelize('mchammer'); // 'McHammer'
public
plural( string $rule
, string $replacement
)
Specifies a new pluralization rule and its replacement.
Specifies a new pluralization rule and its replacement.
$this->plural('/^(ax|test)is$/i', '\1es'); $this->plural('/(buffal|tomat)o$/i', '\1oes'); $this->plural('/^(m|l)ouse$/i', '\1ice');
Parameters
$rule
- A regex string.
$replacement
The replacement should always be a string that may include references to the matched data from the rule.
public
singular( string $rule
, string $replacement
)
Specifies a new singularization rule and its replacement.
Specifies a new singularization rule and its replacement.
$this->singular('/(n)ews$/i', '\1ews'); $this->singular('/([^aeiouy]|qu)ies$/i', '\1y'); $this->singular('/(quiz)zes$/i', '\1');
Parameters
$rule
- A regex string.
$replacement
The replacement should always be a string that may include references to the matched data from the rule.
public
irregular( string $singular
, string $plural
)
Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used for strings, not regular expressions. You simply pass the irregular in singular and plural form.
Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used for strings, not regular expressions. You simply pass the irregular in singular and plural form.
$this->irregular('child', 'children'); $this->irregular('person', 'people');
Parameters
$singular
$plural
public
uncountable( string|array $word
)
Add uncountable words that shouldn't be attempted inflected.
Add uncountable words that shouldn't be attempted inflected.
$this->uncountable('money'); $this->uncountable(explode(' ', 'money information rice'));
Parameters
$word
public
human( string $rule
, string $replacement
)
Specifies a humanized form of a string by a regular expression rule or by a string mapping. When using a regular expression based replacement, the normal humanize formatting is called after the replacement. When a string is used, the human form should be specified as desired (example: 'The name', not 'the_name').
Specifies a humanized form of a string by a regular expression rule or by a string mapping. When using a regular expression based replacement, the normal humanize formatting is called after the replacement. When a string is used, the human form should be specified as desired (example: 'The name', not 'the_name').
$this->human('/_cnt$/i', '\1_count'); $this->human('legacy_col_person_name', 'Name');
Parameters
$rule
A regular expression rule or a string mapping. Strings that starts with "/", "#" or "~" are recognized as regular expressions.
$replacement