Class Inflector
The Inflector transforms words from singular to plural, class names to table names, modularized
class names to ones without, and class names to foreign keys. Inflections can be localized, the
default english inflections for pluralization, singularization, and uncountable words are
kept in lib/inflections/en.php
.
Methods summary
public static
get( string $locale
= self::DEFAULT_LOCALE )
: ICanBoogie\Inflector
Returns an inflector for the specified locale.
Returns an inflector for the specified locale.
Note: Inflectors are shared for the same locale. If you need to alter an inflector you
MUST clone it first.
Parameters
Returns
public
__get( string $property
)
Returns the ICanBoogie\Inflector::$inflections
property.
Parameters
Throws
PropertyNotDefined
in attempt to read an inaccessible property. If the PropertyNotDefined
class is not available a \InvalidArgumentException is thrown instead.
public
pluralize( string $word
)
: string
Returns the plural form of the word in the string.
Returns the plural form of the word in the string.
$this->pluralize('post');
$this->pluralize('children');
$this->pluralize('sheep');
$this->pluralize('words');
$this->pluralize('CamelChild');
Parameters
Returns
string
public
singularize( string $word
)
: string
The reverse of pluralize, returns the singular form of a word in a string.
The reverse of pluralize, returns the singular form of a word in a string.
$this->singularize('posts');
$this->singularize('childred');
$this->singularize('sheep');
$this->singularize('word');
$this->singularize('CamelChildren');
Parameters
Returns
string
public
camelize( string $term
, boolean $downcase_first_letter
= self::UPCASE_FIRST_LETTER )
: string
By default, camelize converts strings to UpperCamelCase.
By default, camelize converts strings to UpperCamelCase.
camelize will also convert "/" to "\" which is useful for converting paths to
namespaces.
$this->camelize('active_model');
$this->camelize('active_model', true);
$this->camelize('active_model/errors');
$this->camelize('active_model/errors', true);
As a rule of thumb you can think of camelize as the inverse of underscore,
though there are cases where that does not hold:
$this->camelize($this->underscore('SSLError'));
Parameters
Returns
string
public
underscore( string $camel_cased_word
)
: string
Makes an underscored, lowercase form from the expression in the string.
Makes an underscored, lowercase form from the expression in the string.
Changes "\" to "/" to convert namespaces to paths.
$this->underscore('ActiveModel');
$this->underscore('ActiveModel\Errors');
As a rule of thumb you can think of underscore as the inverse of camelize(),
though there are cases where that does not hold:
$this->camelize($this->underscore('SSLError'));
Parameters
Returns
string
public
humanize( string $lower_case_and_underscored_word
)
: string
Capitalizes the first word and turns underscores into spaces and strips a trailing "_id",
if any. Like titleize(), this is meant for creating pretty output.
Capitalizes the first word and turns underscores into spaces and strips a trailing "_id",
if any. Like titleize(), this is meant for creating pretty output.
$this->humanize('employee_salary');
$this->humanize('author_id');
Parameters
$lower_case_and_underscored_word
Returns
string
public
titleize( string $str
)
: string
Capitalizes all the words and replaces some characters in the string to create a nicer
looking title. titleize() is meant for creating pretty output. It is not used in
the Rails internals.
Capitalizes all the words and replaces some characters in the string to create a nicer
looking title. titleize() is meant for creating pretty output. It is not used in
the Rails internals.
$this->titleize('man from the boondocks');
$this->titleize('x-men: the last stand');
$this->titleize('TheManWithoutAPast');
$this->titleize('raiders_of_the_lost_ark');
Parameters
Returns
string
public
dasherize( string $underscored_word
)
: string
Replaces underscores with dashes in the string.
Replaces underscores with dashes in the string.
$this->dasherize('puni_puni');
Parameters
Returns
string
public
hyphenate( string $str
)
: string
Makes an hyphenated, lowercase form from the expression in the string.
Makes an hyphenated, lowercase form from the expression in the string.
This is a combination of underscore and ICanBoogie\Inflector::dasherize()
.
Parameters
Returns
string
public
ordinal( integer $number
)
: string
Returns the suffix that should be added to a number to denote the position in an ordered
sequence such as 1st, 2nd, 3rd, 4th.
Returns the suffix that should be added to a number to denote the position in an ordered
sequence such as 1st, 2nd, 3rd, 4th.
$this->ordinal(1);
$this->ordinal(2);
$this->ordinal(1002);
$this->ordinal(1003);
$this->ordinal(-11);
$this->ordinal(-1021);
Parameters
Returns
string
public
ordinalize( integer $number
)
: string
Turns a number into an ordinal string used to denote the position in an ordered sequence
such as 1st, 2nd, 3rd, 4th.
Turns a number into an ordinal string used to denote the position in an ordered sequence
such as 1st, 2nd, 3rd, 4th.
$this->ordinalize(1);
$this->ordinalize(2);
$this->ordinalize(1002);
$this->ordinalize(1003);
$this->ordinalize(-11);
$this->ordinalize(-1021);
Parameters
Returns
string
Constants summary
DOWNCASE_FIRST_LETTER
: boolean
camelize() option to downcase the first letter.
camelize() option to downcase the first letter.
true
UPCASE_FIRST_LETTER
: boolean
camelize() option to keep the first letter as is.
camelize() option to keep the first letter as is.
false
Properties summary
protected
$inflections
: ICanBoogie\Inflections
Inflections used by the inflector.
Inflections used by the inflector.
Magic properties