PHP Класс yii\helpers\BaseInflector

Do not use BaseInflector. Use Inflector instead.
С версии: 2.0
Автор: Antonio Ramirez ([email protected])
Автор: Alexander Makarov ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$plurals the rules for converting a word into its plural form. The keys are the regular expressions and the values are the corresponding replacements.
$singulars the rules for converting a word into its singular form. The keys are the regular expressions and the values are the corresponding replacements.
$specials the special rules for converting a word between its plural form and singular form. The keys are the special words in singular form, and the values are the corresponding plural form.
$transliteration fallback map for transliteration used by BaseInflector::transliterate when intl isn't available.
$transliterator Either a [[\Transliterator]], or a string from which a [[\Transliterator]] can be built for transliteration. Used by BaseInflector::transliterate when intl is available. Defaults to [[TRANSLITERATE_LOOSE]]

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

Метод Описание
camel2id ( string $name, string $separator = '-', boolean | string $strict = false ) : string Converts a CamelCase name into an ID in lowercase.
camel2words ( string $name, boolean $ucwords = true ) : string Converts a CamelCase name into space-separated words.
camelize ( string $word ) : string Returns given word as CamelCased 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"
classify ( string $tableName ) : string Converts a table name to its class name. For example, converts "people" to "Person"
humanize ( string $word, boolean $ucAll = false ) : string Returns a human-readable string from $word
id2camel ( string $id, string $separator = '-' ) : string Converts an ID into a CamelCase name.
ordinalize ( integer $number ) : string Converts number to its ordinal English form. For example, converts 13 to 13th, 2 to 2nd .
pluralize ( string $word ) : string Converts a word to its plural form.
sentence ( array $words, string $twoWordsConnector = ' and ', string $lastWordConnector = null, string $connector = ', ' ) : string Converts a list of words into a sentence.
singularize ( string $word ) : string Returns the singular of the $word
slug ( string $string, string $replacement = '-', boolean $lowercase = true ) : string Returns a string with all spaces converted to given replacement, non word characters removed and the rest of characters transliterated.
tableize ( string $className ) : string Converts a class name to its table name (pluralized) naming conventions. For example, converts "Person" to "people"
titleize ( string $words, boolean $ucAll = false ) : string Converts an underscored or CamelCase word into a English sentence.
transliterate ( string $string, string | Transliterator $transliterator = null ) : string Returns transliterated version of a string.
underscore ( string $words ) : string Converts any "CamelCased" into an "underscored_word".
variablize ( string $word ) : string Same as camelize but first char is in lowercase.

Защищенные методы

Метод Описание
hasIntl ( ) : boolean

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

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

Words in the ID may be concatenated using the specified character (defaults to '-'). For example, 'PostTag' will be converted to 'post-tag'.
public static camel2id ( string $name, string $separator = '-', boolean | string $strict = false ) : string
$name string the string to be converted
$separator string the character used to concatenate the words in the ID
$strict boolean | string whether to insert a separator between two consecutive uppercase chars, defaults to false
Результат string the resulting ID

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

For example, 'PostTag' will be converted to 'Post Tag'.
public static camel2words ( string $name, boolean $ucwords = true ) : string
$name string the string to be converted
$ucwords boolean whether to capitalize the first letter in each word
Результат string the resulting words

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

Returns given word as CamelCased 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 static camelize ( string $word ) : string
$word string the word to CamelCase
Результат string

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

Converts a table name to its class name. For example, converts "people" to "Person"
public static classify ( string $tableName ) : string
$tableName string
Результат string

hasIntl() защищенный статический Метод

protected static hasIntl ( ) : boolean
Результат boolean if intl extension is loaded

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

Returns a human-readable string from $word
public static humanize ( string $word, boolean $ucAll = false ) : string
$word string the string to humanize
$ucAll boolean whether to set all words to uppercase or not
Результат string

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

Words in the ID separated by $separator (defaults to '-') will be concatenated into a CamelCase name. For example, 'post-tag' is converted to 'PostTag'.
public static id2camel ( string $id, string $separator = '-' ) : string
$id string the ID to be converted
$separator string the character used to separate the words in the ID
Результат string the resulting CamelCase name

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

..
public static ordinalize ( integer $number ) : string
$number integer the number to get its ordinal value
Результат string

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

Note that this is for English only! For example, 'apple' will become 'apples', and 'child' will become 'children'.
public static pluralize ( string $word ) : string
$word string the word to be pluralized
Результат string the pluralized word

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

Special treatment is done for the last few words. For example, php $words = ['Spain', 'France']; echo Inflector::sentence($words); output: Spain and France $words = ['Spain', 'France', 'Italy']; echo Inflector::sentence($words); output: Spain, France and Italy $words = ['Spain', 'France', 'Italy']; echo Inflector::sentence($words, ' & '); output: Spain, France & Italy
С версии: 2.0.1
public static sentence ( array $words, string $twoWordsConnector = ' and ', string $lastWordConnector = null, string $connector = ', ' ) : string
$words array the words to be converted into an string
$twoWordsConnector string the string connecting words when there are only two
$lastWordConnector string the string connecting the last two words. If this is null, it will take the value of `$twoWordsConnector`.
$connector string the string connecting words other than those connected by $lastWordConnector and $twoWordsConnector
Результат string the generated sentence

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

Returns the singular of the $word
public static singularize ( string $word ) : string
$word string the english word to singularize
Результат string Singular noun.

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

If intl extension isn't available uses fallback that converts latin characters only and removes the rest. You may customize characters map via $transliteration property of the helper.
public static slug ( string $string, string $replacement = '-', boolean $lowercase = true ) : string
$string string An arbitrary string to convert
$replacement string The replacement to use for spaces
$lowercase boolean whether to return the string in lowercase or not. Defaults to `true`.
Результат string The converted string.

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

Converts a class name to its table name (pluralized) naming conventions. For example, converts "Person" to "people"
public static tableize ( string $className ) : string
$className string the class name for getting related table_name
Результат string

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

Converts an underscored or CamelCase word into a English sentence.
public static titleize ( string $words, boolean $ucAll = false ) : string
$words string
$ucAll boolean whether to set all words to uppercase
Результат string

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

If intl extension isn't available uses fallback that converts latin characters only and removes the rest. You may customize characters map via $transliteration property of the helper.
С версии: 2.0.7 this method is public.
public static transliterate ( string $string, string | Transliterator $transliterator = null ) : string
$string string input string
$transliterator string | Transliterator either a [[\Transliterator]] or a string from which a [[\Transliterator]] can be built.
Результат string

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

Converts any "CamelCased" into an "underscored_word".
public static underscore ( string $words ) : string
$words string the word(s) to underscore
Результат string

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"
public static variablize ( string $word ) : string
$word string to lowerCamelCase
Результат string

Описание свойств

$plurals публичное статическое свойство

the rules for converting a word into its plural form. The keys are the regular expressions and the values are the corresponding replacements.
public static $plurals

$singulars публичное статическое свойство

the rules for converting a word into its singular form. The keys are the regular expressions and the values are the corresponding replacements.
public static $singulars

$specials публичное статическое свойство

the special rules for converting a word between its plural form and singular form. The keys are the special words in singular form, and the values are the corresponding plural form.
public static $specials

$transliteration публичное статическое свойство

fallback map for transliteration used by BaseInflector::transliterate when intl isn't available.
public static $transliteration

$transliterator публичное статическое свойство

Either a [[\Transliterator]], or a string from which a [[\Transliterator]] can be built for transliteration. Used by BaseInflector::transliterate when intl is available. Defaults to [[TRANSLITERATE_LOOSE]]
См. также: http://php.net/manual/en/transliterator.transliterate.php
public static $transliterator