feat(utils): added misc functions file with utilities

Added useful misc utilities that don't belong in a specific class/domain and should be available globally.
This commit is contained in:
Miguel Nogueira 2025-04-14 15:47:55 +01:00
parent 4c4e6d4c99
commit f8467ada09
2 changed files with 28 additions and 0 deletions

View File

@ -9,6 +9,9 @@
"php-di/slim-bridge": "^3.4" "php-di/slim-bridge": "^3.4"
}, },
"autoload": { "autoload": {
"files": [
"src/Utils/Functions.php"
],
"psr-4": { "psr-4": {
"Models\\": "src/Models/", "Models\\": "src/Models/",
"Interfaces\\": "src/Interfaces", "Interfaces\\": "src/Interfaces",

25
src/Utils/Functions.php Normal file
View File

@ -0,0 +1,25 @@
<?php
/**
* Converts camelCase to snake_case.
*
* @see https://gist.github.com/carousel/1aacbea013d230768b3dec1a14ce5751
* @param $input
* @return string
*/
function camel_to_snake($input)
{
return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $input));
}
/**
* Converts snake_case to camelCase.
*
* @see https://gist.github.com/carousel/1aacbea013d230768b3dec1a14ce5751
* @param $input
* @return string
*/
function snakeToCamel($input)
{
return lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $input))));
}