- Add BaseModel with automatic camel/snake case conversion - Add stringcase_helper with camel_to_snake(), snake_to_camel() functions - Update all models to extend BaseModel for consistent data handling - Update API controllers with standardized JSON response format - Remove legacy v1 PHP application directory - Consolidate documentation into AGENTS.md, delete VIEWS_RULES.md
48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
if (!function_exists('camel_to_snake')) {
|
|
function camel_to_snake(string $string): string
|
|
{
|
|
$pattern = '/([a-z])([A-Z])/';
|
|
return strtolower(preg_replace($pattern, '$1_$2', $string));
|
|
}
|
|
}
|
|
|
|
if (!function_exists('camel_to_snake_array')) {
|
|
function camel_to_snake_array(array $data): array
|
|
{
|
|
$converted = [];
|
|
foreach ($data as $key => $value) {
|
|
$snakeKey = camel_to_snake($key);
|
|
$converted[$snakeKey] = $value;
|
|
}
|
|
return $converted;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('snake_to_camel')) {
|
|
function snake_to_camel(string $string): string
|
|
{
|
|
$parts = explode('_', $string);
|
|
$camel = array_map(function ($part, $index) {
|
|
if ($index === 0) {
|
|
return $part;
|
|
}
|
|
return ucfirst($part);
|
|
}, $parts, array_keys($parts));
|
|
return implode('', $camel);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('snake_to_camel_array')) {
|
|
function snake_to_camel_array(array $data): array
|
|
{
|
|
$converted = [];
|
|
foreach ($data as $key => $value) {
|
|
$camelKey = snake_to_camel($key);
|
|
$converted[$camelKey] = $value;
|
|
}
|
|
return $converted;
|
|
}
|
|
}
|