: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @link https://book.cakephp.org/3/en/core-libraries/inflector.html#creating-plural-singular-forms
public static function pluralize($word)
if (isset(static::$_cache['pluralize'][$word])) {
return static::$_cache['pluralize'][$word];
if (!isset(static::$_cache['irregular']['pluralize'])) {
$words = array_keys(static::$_irregular);
static::$_cache['irregular']['pluralize'] = '/(.*?(?:\\b|_))(' . implode('|', $words) . ')$/i';
$upperWords = array_map('ucfirst', $words);
static::$_cache['irregular']['upperPluralize'] = '/(.*?(?:\\b|[a-z]))(' . implode('|', $upperWords) . ')$/';
preg_match(static::$_cache['irregular']['pluralize'], $word, $regs) ||
preg_match(static::$_cache['irregular']['upperPluralize'], $word, $regs)
static::$_cache['pluralize'][$word] = $regs[1] . substr($regs[2], 0, 1) .
substr(static::$_irregular[strtolower($regs[2])], 1);
return static::$_cache['pluralize'][$word];
if (!isset(static::$_cache['uninflected'])) {
static::$_cache['uninflected'] = '/^(' . implode('|', static::$_uninflected) . ')$/i';
if (preg_match(static::$_cache['uninflected'], $word, $regs)) {
static::$_cache['pluralize'][$word] = $word;
foreach (static::$_plural as $rule => $replacement) {
if (preg_match($rule, $word)) {
static::$_cache['pluralize'][$word] = preg_replace($rule, $replacement, $word);
return static::$_cache['pluralize'][$word];
* Return $word in singular form.
* @param string $word Word in plural
* @return string Word in singular
* @link https://book.cakephp.org/3/en/core-libraries/inflector.html#creating-plural-singular-forms
public static function singularize($word)
if (isset(static::$_cache['singularize'][$word])) {
return static::$_cache['singularize'][$word];
if (!isset(static::$_cache['irregular']['singular'])) {
$wordList = array_values(static::$_irregular);
static::$_cache['irregular']['singular'] = '/(.*?(?:\\b|_))(' . implode('|', $wordList) . ')$/i';
$upperWordList = array_map('ucfirst', $wordList);
static::$_cache['irregular']['singularUpper'] = '/(.*?(?:\\b|[a-z]))(' .
implode('|', $upperWordList) .
preg_match(static::$_cache['irregular']['singular'], $word, $regs) ||
preg_match(static::$_cache['irregular']['singularUpper'], $word, $regs)
static::$_cache['singularize'][$word] = $regs[1] . substr($regs[2], 0, 1) .
substr(array_search(strtolower($regs[2]), static::$_irregular, true), 1);
return static::$_cache['singularize'][$word];
if (!isset(static::$_cache['uninflected'])) {
static::$_cache['uninflected'] = '/^(' . implode('|', static::$_uninflected) . ')$/i';
if (preg_match(static::$_cache['uninflected'], $word, $regs)) {
static::$_cache['pluralize'][$word] = $word;
foreach (static::$_singular as $rule => $replacement) {
if (preg_match($rule, $word)) {
static::$_cache['singularize'][$word] = preg_replace($rule, $replacement, $word);
return static::$_cache['singularize'][$word];
static::$_cache['singularize'][$word] = $word;
* Returns the input lower_case_delimited_string as a CamelCasedString.
* @param string $string String to camelize
* @param string $delimiter the delimiter in the input string
* @return string CamelizedStringLikeThis.
* @link https://book.cakephp.org/3/en/core-libraries/inflector.html#creating-camelcase-and-under-scored-forms
public static function camelize($string, $delimiter = '_')
$cacheKey = __FUNCTION__ . $delimiter;
$result = static::_cache($cacheKey, $string);
$result = str_replace(' ', '', static::humanize($string, $delimiter));
static::_cache($cacheKey, $string, $result);
* Returns the input CamelCasedString as an underscored_string.
* Also replaces dashes with underscores
* @param string $string CamelCasedString to be "underscorized"
* @return string underscore_version of the input string
* @link https://book.cakephp.org/3/en/core-libraries/inflector.html#creating-camelcase-and-under-scored-forms
public static function underscore($string)
return static::delimit(str_replace('-', '_', $string), '_');
* Returns the input CamelCasedString as an dashed-string.
* Also replaces underscores with dashes
* @param string $string The string to dasherize.
* @return string Dashed version of the input string
public static function dasherize($string)
return static::delimit(str_replace('_', '-', $string), '-');
* Returns the input lower_case_delimited_string as 'A Human Readable String'.
* (Underscores are replaced by spaces and capitalized following words.)
* @param string $string String to be humanized
* @param string $delimiter the character to replace with a space
* @return string Human-readable string
* @link https://book.cakephp.org/3/en/core-libraries/inflector.html#creating-human-readable-forms
public static function humanize($string, $delimiter = '_')
$cacheKey = __FUNCTION__ . $delimiter;
$result = static::_cache($cacheKey, $string);
$result = explode(' ', str_replace($delimiter, ' ', $string));
foreach ($result as &$word) {
$word = mb_strtoupper(mb_substr($word, 0, 1)) . mb_substr($word, 1);
$result = implode(' ', $result);
static::_cache($cacheKey, $string, $result);
* Expects a CamelCasedInputString, and produces a lower_case_delimited_string
* @param string $string String to delimit
* @param string $delimiter the character to use as a delimiter
* @return string delimited string
public static function delimit($string, $delimiter = '_')
$cacheKey = __FUNCTION__ . $delimiter;
$result = static::_cache($cacheKey, $string);
$result = mb_strtolower(preg_replace('/(?<=\\w)([A-Z])/', $delimiter . '\\1', $string));
static::_cache($cacheKey, $string, $result);
* Returns corresponding table name for given model $className. ("people" for the model class "Person").
* @param string $className Name of class to get database table name for
* @return string Name of the database table for given class
* @link https://book.cakephp.org/3/en/core-libraries/inflector.html#creating-table-and-class-name-forms
public static function tableize($className)
$result = static::_cache(__FUNCTION__, $className);
$result = static::pluralize(static::underscore($className));
static::_cache(__FUNCTION__, $className, $result);
* Returns Cake model class name ("Person" for the database table "people".) for given database table.
* @param string $tableName Name of database table to get class name for
* @return string Class name
* @link https://book.cakephp.org/3/en/core-libraries/inflector.html#creating-table-and-class-name-forms
public static function classify($tableName)
$result = static::_cache(__FUNCTION__, $tableName);
$result = static::camelize(static::singularize($tableName));
static::_cache(__FUNCTION__, $tableName, $result);
* Returns camelBacked version of an underscored string.
* @param string $string String to convert.
* @return string in variable form
* @link https://book.cakephp.org/3/en/core-libraries/inflector.html#creating-variable-names
public static function variable($string)
$result = static::_cache(__FUNCTION__, $string);
$camelized = static::camelize(static::underscore($string));
$replace = strtolower(substr($camelized, 0, 1));
$result = $replace . substr($camelized, 1);
static::_cache(__FUNCTION__, $string, $result);
* Returns a string with all spaces converted to dashes (by default), accented
* characters converted to non-accented characters, and non word characters removed.
* @deprecated 3.2.7 Use Text::slug() instead.
* @param string $string the string you want to slug
* @param string $replacement will replace keys in map
* @link https://book.cakephp.org/3/en/core-libraries/inflector.html#creating-url-safe-strings
public static function slug($string, $replacement = '-')
'Inflector::slug() is deprecated. ' .
'Use Text::slug() instead.'
$quotedReplacement = preg_quote($replacement, '/');
'/[^\s\p{Zs}\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]/mu' => ' ',
'/[\s\p{Zs}]+/mu' => $replacement,
sprintf('/^[%s]+|[%s]+$/', $quotedReplacement, $quotedReplacement) => '',
array_keys(static::$_transliteration),
static::$_transliteration,
return preg_replace(array_keys($map), array_values($map), $string);