CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 4.4 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.4
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
      • Crypto
      • Exception
    • Validation
    • View

Class Inflector

Pluralize and singularize English words.

Inflector pluralizes and singularizes English nouns. Used by CakePHP's naming conventions throughout the framework.

Namespace: Cake\Utility
Link: https://book.cakephp.org/4/en/core-libraries/inflector.html

Property Summary

  • $_cache protected static
    array<string, mixed>

    Method cache array.

  • $_initialState protected static
    array

    The initial state of Inflector so reset() works.

  • $_irregular protected static
    array<string, string>

    Irregular rules

  • $_plural protected static
    array<string, string>

    Plural inflector rules

  • $_singular protected static
    array<string, string>

    Singular inflector rules

  • $_uninflected protected static
    array<string>

    Words that should not be inflected

Method Summary

  • _cache() protected static

    Cache inflected values, and return if already available

  • camelize() public static

    Returns the input lower_case_delimited_string as a CamelCasedString.

  • classify() public static

    Returns Cake model class name ("Person" for the database table "people".) for given database table.

  • dasherize() public static

    Returns the input CamelCasedString as an dashed-string.

  • delimit() public static

    Expects a CamelCasedInputString, and produces a lower_case_delimited_string

  • humanize() public static

    Returns the input lower_case_delimited_string as 'A Human Readable String'. (Underscores are replaced by spaces and capitalized following words.)

  • pluralize() public static

    Return $word in plural form.

  • reset() public static

    Clears Inflectors inflected value caches. And resets the inflection rules to the initial values.

  • rules() public static

    Adds custom inflection $rules, of either 'plural', 'singular', 'uninflected' or 'irregular' $type.

  • singularize() public static

    Return $word in singular form.

  • tableize() public static

    Returns corresponding table name for given model $className. ("people" for the model class "Person").

  • underscore() public static

    Returns the input CamelCasedString as an underscored_string.

  • variable() public static

    Returns camelBacked version of an underscored string.

Method Detail

_cache() ¶ protected static

_cache(string $type, string $key, string|false $value = false): string|false

Cache inflected values, and return if already available

Parameters
string $type

Inflection type

string $key

Original value

string|false $value optional

Inflected value

Returns
string|false

camelize() ¶ public static

camelize(string $string, string $delimiter = '_'): string

Returns the input lower_case_delimited_string as a CamelCasedString.

Parameters
string $string

String to camelize

string $delimiter optional

the delimiter in the input string

Returns
string
Links
https://book.cakephp.org/4/en/core-libraries/inflector.html#creating-camelcase-and-under-scored-forms

classify() ¶ public static

classify(string $tableName): string

Returns Cake model class name ("Person" for the database table "people".) for given database table.

Parameters
string $tableName

Name of database table to get class name for

Returns
string
Links
https://book.cakephp.org/4/en/core-libraries/inflector.html#creating-table-and-class-name-forms

dasherize() ¶ public static

dasherize(string $string): string

Returns the input CamelCasedString as an dashed-string.

Also replaces underscores with dashes

Parameters
string $string

The string to dasherize.

Returns
string

delimit() ¶ public static

delimit(string $string, string $delimiter = '_'): string

Expects a CamelCasedInputString, and produces a lower_case_delimited_string

Parameters
string $string

String to delimit

string $delimiter optional

the character to use as a delimiter

Returns
string

humanize() ¶ public static

humanize(string $string, string $delimiter = '_'): string

Returns the input lower_case_delimited_string as 'A Human Readable String'. (Underscores are replaced by spaces and capitalized following words.)

Parameters
string $string

String to be humanized

string $delimiter optional

the character to replace with a space

Returns
string
Links
https://book.cakephp.org/4/en/core-libraries/inflector.html#creating-human-readable-forms

pluralize() ¶ public static

pluralize(string $word): string

Return $word in plural form.

Parameters
string $word

Word in singular

Returns
string
Links
https://book.cakephp.org/4/en/core-libraries/inflector.html#creating-plural-singular-forms

reset() ¶ public static

reset(): void

Clears Inflectors inflected value caches. And resets the inflection rules to the initial values.

Returns
void

rules() ¶ public static

rules(string $type, array $rules, bool $reset = false): void

Adds custom inflection $rules, of either 'plural', 'singular', 'uninflected' or 'irregular' $type.

Usage:

Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
Inflector::rules('irregular', ['red' => 'redlings']);
Inflector::rules('uninflected', ['dontinflectme']);
Parameters
string $type

The type of inflection, either 'plural', 'singular', or 'uninflected'.

array $rules

Array of rules to be added.

bool $reset optional

If true, will unset default inflections for all new rules that are being defined in $rules.

Returns
void

singularize() ¶ public static

singularize(string $word): string

Return $word in singular form.

Parameters
string $word

Word in plural

Returns
string
Links
https://book.cakephp.org/4/en/core-libraries/inflector.html#creating-plural-singular-forms

tableize() ¶ public static

tableize(string $className): string

Returns corresponding table name for given model $className. ("people" for the model class "Person").

Parameters
string $className

Name of class to get database table name for

Returns
string
Links
https://book.cakephp.org/4/en/core-libraries/inflector.html#creating-table-and-class-name-forms

underscore() ¶ public static

underscore(string $string): string

Returns the input CamelCasedString as an underscored_string.

Also replaces dashes with underscores

Parameters
string $string

CamelCasedString to be "underscorized"

Returns
string
Links
https://book.cakephp.org/4/en/core-libraries/inflector.html#creating-camelcase-and-under-scored-forms

variable() ¶ public static

variable(string $string): string

Returns camelBacked version of an underscored string.

Parameters
string $string

String to convert.

Returns
string
Links
https://book.cakephp.org/4/en/core-libraries/inflector.html#creating-variable-names

Property Detail

$_cache ¶ protected static

Method cache array.

Type
array<string, mixed>

$_initialState ¶ protected static

The initial state of Inflector so reset() works.

Type
array

$_irregular ¶ protected static

Irregular rules

Type
array<string, string>

$_plural ¶ protected static

Plural inflector rules

Type
array<string, string>

$_singular ¶ protected static

Singular inflector rules

Type
array<string, string>

$_uninflected ¶ protected static

Words that should not be inflected

Type
array<string>
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs