| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- declare(strict_types=1);
- namespace App\Service\Utils;
- use App\Tests\Service\Utils\StringsUtilsTest;
- /**
- * Class StringsUtils : méthodes d'aide pour la gestion de string.
- * @package App\Service\Utils
- */
- class StringsUtils
- {
- /**
- * Supprime les quotes d'une chaine de caractères
- * @param string $str
- * @return string
- * @see StringsUtilsTest::testUnquote()
- */
- public static function unquote(string $str): string {
- return str_replace("'", "", $str);
- }
- /**
- * Convert CamelCase formatted string into snake_case
- * @see https://stackoverflow.com/a/40514305/4279120
- *
- * @param string $string
- * @param string $sep
- * @return string
- */
- public static function camelToSnake(string $string, string $sep = "_"): string {
- return strtolower(
- preg_replace(
- '/(?<=\d)(?=[A-Za-z])|(?<=[A-Za-z])(?=\d)|(?<=[a-z])(?=[A-Z])/',
- $sep,
- $string
- )
- );
- }
- }
|