-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed string cache from
Hyperf\Stringable\Str
Co-authored-by: Deeka Wong <[email protected]> Co-authored-by: 李铭昕 <[email protected]>
- Loading branch information
1 parent
7773386
commit 4056a0c
Showing
3 changed files
with
103 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of Hyperf. | ||
* | ||
* @link https://www.hyperf.io | ||
* @document https://hyperf.wiki | ||
* @contact [email protected] | ||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE | ||
*/ | ||
namespace Hyperf\Stringable; | ||
|
||
class StrCache | ||
{ | ||
/** | ||
* The cache of snake-cased words. | ||
*/ | ||
protected static array $snakeCache = []; | ||
|
||
/** | ||
* The cache of camel-cased words. | ||
*/ | ||
protected static array $camelCache = []; | ||
|
||
/** | ||
* The cache of studly-cased words. | ||
*/ | ||
protected static array $studlyCache = []; | ||
|
||
public static function camel($value) | ||
{ | ||
if (isset(static::$camelCache[$value])) { | ||
return static::$camelCache[$value]; | ||
} | ||
|
||
return static::$camelCache[$value] = Str::camel($value); | ||
} | ||
|
||
public static function snake(string $value, string $delimiter = '_'): string | ||
{ | ||
if (isset(static::$snakeCache[$value][$delimiter])) { | ||
return static::$snakeCache[$value][$delimiter]; | ||
} | ||
|
||
return static::$snakeCache[$value][$delimiter] = Str::snake($value, $delimiter); | ||
} | ||
|
||
public static function studly(string $value, string $gap = ''): string | ||
{ | ||
if (isset(static::$studlyCache[$value][$gap])) { | ||
return static::$studlyCache[$value][$gap]; | ||
} | ||
|
||
return static::$studlyCache[$value][$gap] = Str::studly($value, $gap); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters