diff options
Diffstat (limited to 'src/application/mystic/forum/utils/StringUtils.php')
-rw-r--r-- | src/application/mystic/forum/utils/StringUtils.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/application/mystic/forum/utils/StringUtils.php b/src/application/mystic/forum/utils/StringUtils.php new file mode 100644 index 0000000..7d4bf9d --- /dev/null +++ b/src/application/mystic/forum/utils/StringUtils.php @@ -0,0 +1,24 @@ +<?php +declare(strict_types=1); + +namespace mystic\forum\utils; + +final class StringUtils { + use StaticClass; + + public static function camelToSnake(string $camelCase): string { + $result = ''; + + for ($i = 0; $i < strlen($camelCase); $i++) { + $char = $camelCase[$i]; + + if (ctype_upper($char)) { + $result .= '_' . strtolower($char); + } else { + $result .= $char; + } + } + + return ltrim($result, '_'); + } +} |