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 87
static string
studly(string $value, bool $normalize = false)
Convert a value to studly case (cached).
at line 101
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 122
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 136
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 155
static void
flushSnake()
Flush the snake cache.
at line 163
static void
flushCamel()
Flush the camel cache.
at line 171
static void
flushStudly()
Flush the studly cache.
at line 179
static void
flushPlural()
Flush the plural cache.
at line 187
static void
flushSingular()
Flush the singular cache.
at line 195
static void
flushPluralStudly()
Flush the plural studly cache.
at line 203
static void
flushState()
Flush all static state.