ICanBoogie/Inflector v1.4.2
  • Namespace
  • Class

Namespaces

  • ICanBoogie

Classes

  • Inflections
  • Inflector

Constants

  • INFLECTOR_DEFAULT_LOCALE

Functions

  • camelize
  • capitalize
  • downcase
  • humanize
  • hyphenate
  • pluralize
  • singularize
  • titleize
  • underscore
  • upcase

Class Inflections

A representation of the inflections used by an inflector.

Namespace: ICanBoogie
Located at inflections.php

Methods summary

public static ICanBoogie\Inflections
# get( string $locale = ICanBoogie\INFLECTOR_DEFAULT_LOCALE )

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 MUST clone it first, otherwise your changes will affect others.

Parameters

$locale

Returns

ICanBoogie\Inflections
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

PropertyNotDefined

in attempt to read an inaccessible property. If the PropertyNotDefined class is not available a \InvalidArgumentException is thrown instead.

public ICanBoogie\Inflections
# acronym( string $acronym )

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'

Parameters

$acronym

Returns

ICanBoogie\Inflections
$this
public ICanBoogie\Inflections
# 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.

Returns

ICanBoogie\Inflections
$this
public ICanBoogie\Inflections
# 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.

Returns

ICanBoogie\Inflections
$this
public ICanBoogie\Inflections
# 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

Returns

ICanBoogie\Inflections
$this
public ICanBoogie\Inflections
# 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

Returns

ICanBoogie\Inflections
$this
public ICanBoogie\Inflections
# 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

Returns

ICanBoogie\Inflections
$this

Properties summary

protected array $plurals

Rules for pluralize().

Rules for pluralize().

# array()
protected array $singulars

Rules for singularize().

Rules for singularize().

# array()
protected array $uncountables

Uncountables.

Uncountables.

# array()
protected array $humans

Rules for humanize().

Rules for humanize().

# array()
protected array $acronyms

Acronyms.

Acronyms.

# array()
protected string $acronym_regex

Acronyms regex.

Acronyms regex.

# '/(?=a)b/'

Magic properties

public read-only array $plurals

Rules for pluralize().

public read-only array $singulars

Rules for singularize().

public read-only array $uncountables

Uncountables.

public read-only array $humans

Rules for humanize().

public read-only array $acronyms

Acronyms.

public read-only array $acronym_regex

Acronyms regex.

ICanBoogie/Inflector v1.4.2 API documentation generated by ApiGen