StrCache
class StrCache
Cached string transformations for known-finite inputs.
Use this class for framework internals where input strings come from a finite set (class names, attribute names, column names, etc.).
For arbitrary or user-provided input, use Str methods directly to avoid unbounded cache growth in long-running Swoole workers.
Properties
| static protected array<string, array<string, string>> | $snakeCache | The cache of snake-cased words. |
|
| static protected array<string, string> | $camelCache | The cache of camel-cased words. |
|
| static protected array<string, array<int, string>> | $studlyCache | The cache of studly-cased words. |
|
| static protected array<string, string> | $pluralCache | The cache of plural words. |
|
| static protected array<string, string> | $singularCache | The cache of singular words. |
|
| static protected array<string, string> | $pluralStudlyCache | The cache of plural studly words. |
Methods
Convert a string to snake case (cached).
Convert a value to camel case (cached).
Convert a value to studly case (cached).
Get the plural form of a word (cached).
Get the singular form of a word (cached).
Pluralize the last word of a studly caps string (cached).
Flush the snake cache.
Flush the camel cache.
Flush the studly cache.
Flush the plural cache.
Flush the singular cache.
Flush the plural studly cache.
Flush all static state.
Details
at line 63
static string
snake(string $value, string $delimiter = '_')
Convert a string to snake case (cached).
at line 75
static string
camel(string $value)
Convert a value to camel case (cached).
at line 83
static string
studly(string $value, bool $normalize = false)
Convert a value to studly case (cached).
at line 97
static string
plural(string $value, int|array $count = 2)
Get the plural form of a word (cached).
Best for finite inputs like class names, not user input.
at line 118
static string
singular(string $value)
Get the singular form of a word (cached).
Best for finite inputs like class names, not user input.
at line 132
static string
pluralStudly(string $value, int|array $count = 2)
Pluralize the last word of a studly caps string (cached).
Best for finite inputs like class names, not user input.
at line 151
static void
flushSnake()
Flush the snake cache.
at line 159
static void
flushCamel()
Flush the camel cache.
at line 167
static void
flushStudly()
Flush the studly cache.
at line 175
static void
flushPlural()
Flush the plural cache.
at line 183
static void
flushSingular()
Flush the singular cache.
at line 191
static void
flushPluralStudly()
Flush the plural studly cache.
at line 199
static void
flushState()
Flush all static state.