PHP Класс Phactory\Inflector

This Inflector is a port of Ruby on Rails Inflector. It can be really helpful for developers that want to create frameworks based on naming conventions rather than configurations. It was ported to PHP for the Akelos Framework, a multilingual Ruby on Rails like framework for PHP that will be launched soon.
С версии: 0.1
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
camelize ( string $word ) : string Returns given word as CamelCased
classify ( string $table_name ) : string Converts a table name to its class name according to rails naming conventions.
humanize ( string $word, string $uppercase = '' ) : string Returns a human-readable string from $word
ordinalize ( integer $number ) : string Converts number to its ordinal English form.
pluralize ( string $word ) : string Pluralizes English nouns.
singularize ( string $word ) : string Singularizes English nouns.
tableize ( string $class_name ) : string Converts a class name to its table name according to rails naming conventions.
titleize ( string $word, string $uppercase = '' ) : string Converts an underscored or CamelCase word into a English sentence.
underscore ( string $word ) : string Converts a word "into_it_s_underscored_version"
variablize ( string $word ) : string Same as camelize but first char is underscored

Описание методов

camelize() публичный Метод

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"
См. также: variablize
public camelize ( string $word ) : string
$word string Word to convert to camel case
Результат string UpperCamelCasedWord

classify() публичный Метод

Converts "people" to "Person"
См. также: tableize
public classify ( string $table_name ) : string
$table_name string Table name for getting related ClassName.
Результат string SingularClassName

humanize() публичный Метод

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.
public humanize ( string $word, string $uppercase = '' ) : string
$word string String to "humanize"
$uppercase string If set to 'all' it will uppercase all the words instead of just the first one.
Результат string Human-readable word

ordinalize() публичный Метод

This method converts 13 to 13th, 2 to 2nd ...
public ordinalize ( integer $number ) : string
$number integer Number to get its ordinal value
Результат string Ordinal representation of given string.

pluralize() публичный статический Метод

Pluralizes English nouns.
public static pluralize ( string $word ) : string
$word string English noun to pluralize
Результат string Plural noun

singularize() публичный Метод

Singularizes English nouns.
public singularize ( string $word ) : string
$word string English noun to singularize
Результат string Singular noun.

tableize() публичный Метод

Converts "Person" to "people"
См. также: classify
public tableize ( string $class_name ) : string
$class_name string Class name for getting related table_name.
Результат string plural_table_name

titleize() публичный Метод

The titleize 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.
public titleize ( string $word, string $uppercase = '' ) : string
$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.
Результат string Text formatted as title

underscore() публичный Метод

Convert any "CamelCased" or "ordinary Word" into an "underscored_word". This can be really useful for creating friendly URLs.
public underscore ( string $word ) : string
$word string Word to underscore
Результат string Underscored word

variablize() публичный Метод

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"
См. также: camelize
public variablize ( string $word ) : string
$word string Word to lowerCamelCase
Результат string Returns a lowerCamelCasedWord