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

static string
snake(string $value, string $delimiter = '_')

Convert a string to snake case (cached).

static string
camel(string $value)

Convert a value to camel case (cached).

static string
studly(string $value, bool $normalize = false)

Convert a value to studly case (cached).

static string
plural(string $value, int|array $count = 2)

Get the plural form of a word (cached).

static string
singular(string $value)

Get the singular form of a word (cached).

static string
pluralStudly(string $value, int|array $count = 2)

Pluralize the last word of a studly caps string (cached).

static void
flushSnake()

Flush the snake cache.

static void
flushCamel()

Flush the camel cache.

static void
flushStudly()

Flush the studly cache.

static void
flushPlural()

Flush the plural cache.

static void
flushSingular()

Flush the singular cache.

static void
flushPluralStudly()

Flush the plural studly cache.

static void
flushState()

Flush all static state.

Details

at line 63
static string snake(string $value, string $delimiter = '_')

Convert a string to snake case (cached).

Parameters

string $value
string $delimiter

Return Value

string

at line 75
static string camel(string $value)

Convert a value to camel case (cached).

Parameters

string $value

Return Value

string

at line 87
static string studly(string $value, bool $normalize = false)

Convert a value to studly case (cached).

Parameters

string $value
bool $normalize

Return Value

string

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.

Parameters

string $value
int|array $count

Return Value

string

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.

Parameters

string $value

Return Value

string

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.

Parameters

string $value
int|array $count

Return Value

string

at line 155
static void flushSnake()

Flush the snake cache.

Return Value

void

at line 163
static void flushCamel()

Flush the camel cache.

Return Value

void

at line 171
static void flushStudly()

Flush the studly cache.

Return Value

void

at line 179
static void flushPlural()

Flush the plural cache.

Return Value

void

at line 187
static void flushSingular()

Flush the singular cache.

Return Value

void

at line 195
static void flushPluralStudly()

Flush the plural studly cache.

Return Value

void

at line 203
static void flushState()

Flush all static state.

Return Value

void