Documentation

Inflector
in package

This file was originally part of the Akelos Framework

Table of Contents

Properties

$initialized  : bool
$irregular  : array<string|int, mixed>|null
$ordinals  : array<string|int, mixed>|null
$plural  : array<string|int, mixed>|null
$singular  : array<string|int, mixed>|null
$uncountable  : array<string|int, mixed>|null

Methods

camelize()  : string
Returns given word as CamelCased
classify()  : string
Converts a table name to its class name according to rails naming conventions.
humanize()  : string
Returns a human-readable string from $word
hyphenize()  : string
Converts a word "into-it-s-hyphenated-version"
init()  : void
monthize()  : int
Converts a number of days to a number of months
ordinalize()  : string
Converts number to its ordinal English form.
pluralize()  : string|false
Pluralizes English nouns.
singularize()  : string
Singularizes English nouns.
tableize()  : string
Converts a class name to its table name according to rails naming conventions.
titleize()  : string
Converts an underscored or CamelCase word into a English sentence.
underscorize()  : string
Converts a word "into_it_s_underscored_version"
variablize()  : string
Same as camelize but first char is underscored

Properties

$initialized

protected static bool $initialized = false

$irregular

protected static array<string|int, mixed>|null $irregular

$ordinals

protected static array<string|int, mixed>|null $ordinals

$plural

protected static array<string|int, mixed>|null $plural

$singular

protected static array<string|int, mixed>|null $singular

$uncountable

protected static array<string|int, mixed>|null $uncountable

Methods

camelize()

Returns given word as CamelCased

public static camelize(string $word) : string

Converts a word like "send_email" to "SendEmail". It will remove non alphanumeric character from the word, so "who's online" will be converted to "WhoSOnline"

Parameters
$word : string

Word to convert to camel case

Tags
see
variablize
Return values
string

UpperCamelCasedWord

classify()

Converts a table name to its class name according to rails naming conventions.

public static classify(string $table_name) : string

Converts "people" to "Person"

Parameters
$table_name : string

Table name for getting related ClassName.

Tags
see
tableize
Return values
string

SingularClassName

humanize()

Returns a human-readable string from $word

public static humanize(string $word[, string $uppercase = '' ]) : string

Returns a human-readable string from $word, by replacing underscores with a space, and by upper-casing the initial character by default.

If you need to uppercase all the words you just have to pass 'all' as a second parameter.

Parameters
$word : string

String to "humanize"

$uppercase : string = ''

If set to 'all' it will uppercase all the words instead of just the first one.

Return values
string

Human-readable word

hyphenize()

Converts a word "into-it-s-hyphenated-version"

public static hyphenize(string $word) : string

Convert any "CamelCased" or "ordinary Word" into an "hyphenated-word".

This can be really useful for creating friendly URLs.

Parameters
$word : string

Word to hyphenate

Return values
string

hyphenized word

monthize()

Converts a number of days to a number of months

public static monthize(int $days) : int
Parameters
$days : int
Return values
int

ordinalize()

Converts number to its ordinal English form.

public static ordinalize(int $number) : string

This method converts 13 to 13th, 2 to 2nd ...

Parameters
$number : int

Number to get its ordinal value

Return values
string

Ordinal representation of given string.

pluralize()

Pluralizes English nouns.

public static pluralize(string $word[, int $count = 2 ]) : string|false
Parameters
$word : string

English noun to pluralize

$count : int = 2

The count

Return values
string|false

Plural noun

singularize()

Singularizes English nouns.

public static singularize(string $word[, int $count = 1 ]) : string
Parameters
$word : string

English noun to singularize

$count : int = 1
Return values
string

Singular noun.

tableize()

Converts a class name to its table name according to rails naming conventions.

public static tableize(string $class_name) : string

Converts "Person" to "people"

Parameters
$class_name : string

Class name for getting related table_name.

Tags
see
classify
Return values
string

plural_table_name

titleize()

Converts an underscored or CamelCase word into a English sentence.

public static titleize(string $word[, string $uppercase = '' ]) : string

The titleize public function converts text like "WelcomePage", "welcome_page" or "welcome page" to this "Welcome Page". If second parameter is set to 'first' it will only capitalize the first character of the title.

Parameters
$word : string

Word to format as tile

$uppercase : string = ''

If set to 'first' it will only uppercase the first character. Otherwise it will uppercase all the words in the title.

Return values
string

Text formatted as title

underscorize()

Converts a word "into_it_s_underscored_version"

public static underscorize(string $word) : string

Convert any "CamelCased" or "ordinary Word" into an "underscored_word".

This can be really useful for creating friendly URLs.

Parameters
$word : string

Word to underscore

Return values
string

Underscored word

variablize()

Same as camelize but first char is underscored

public static variablize(string $word) : string

Converts a word like "send_email" to "sendEmail". It will remove non alphanumeric character from the word, so "who's online" will be converted to "whoSOnline"

Parameters
$word : string

Word to lowerCamelCase

Tags
see
camelize
Return values
string

Returns a lowerCamelCasedWord


        
On this page

Search results