style: Laravel Pint 코드 포맷팅 적용
- PSR-12 스타일 가이드 준수 - 302개 파일 스타일 이슈 자동 수정 - 코드 로직 변경 없음 (포맷팅만)
This commit is contained in:
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class ApiResponse
|
||||
{
|
||||
|
||||
function normalizeFiles(array $laravelFiles): array {
|
||||
public function normalizeFiles(array $laravelFiles): array
|
||||
{
|
||||
$files = ['name' => [], 'type' => [], 'tmp_name' => [], 'size' => [], 'fileType' => []];
|
||||
foreach ($laravelFiles as $file) {
|
||||
$files['name'][] = $file->getClientOriginalName();
|
||||
@@ -18,10 +18,11 @@ function normalizeFiles(array $laravelFiles): array {
|
||||
$files['size'][] = $file->getSize();
|
||||
$files['fileType'][] = '';
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
# DebugQuery Helper
|
||||
// DebugQuery Helper
|
||||
public static function debugQueryLog(): array
|
||||
{
|
||||
$logs = DB::getQueryLog();
|
||||
@@ -31,17 +32,18 @@ public static function debugQueryLog(): array
|
||||
->map(function ($log) {
|
||||
$query = $log['query'];
|
||||
foreach ($log['bindings'] as $binding) {
|
||||
$binding = is_numeric($binding) ? $binding : "'" . addslashes($binding) . "'";
|
||||
$binding = is_numeric($binding) ? $binding : "'".addslashes($binding)."'";
|
||||
$query = preg_replace('/\\?/', $binding, $query, 1);
|
||||
}
|
||||
|
||||
// \n 제거
|
||||
$query = str_replace(["\n", "\r"], ' ', $query)." (time: {$log['time']})";
|
||||
|
||||
return trim($query);
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
# ApiResponse Helper
|
||||
// ApiResponse Helper
|
||||
public static function success(
|
||||
$data = null,
|
||||
string $message = '요청 성공',
|
||||
@@ -52,7 +54,10 @@ public static function success(
|
||||
'message' => $message,
|
||||
'data' => $data,
|
||||
];
|
||||
if(!empty($debug)) $response['query'] = $debug;
|
||||
if (! empty($debug)) {
|
||||
$response['query'] = $debug;
|
||||
}
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
@@ -85,7 +90,7 @@ public static function response($type = '', $query = '', $key = ''): array
|
||||
$debug = app()->environment('local') && request()->is('api/*');
|
||||
|
||||
$result = match ($type) {
|
||||
'get' => $key ? $query->get()->keyBy($key) : $query->get(),
|
||||
'get' => $key ? $query->get()->keyBy($key) : $query->get(),
|
||||
'getSub' => $query->get(),
|
||||
'count' => $query->count(),
|
||||
'first' => $query->first(),
|
||||
@@ -94,7 +99,7 @@ public static function response($type = '', $query = '', $key = ''): array
|
||||
default => null,
|
||||
};
|
||||
|
||||
if($type=='getSub'){
|
||||
if ($type == 'getSub') {
|
||||
$array = $result->map(function ($item) {
|
||||
return (array) $item;
|
||||
})->toArray();
|
||||
@@ -118,8 +123,7 @@ public static function response($type = '', $query = '', $key = ''): array
|
||||
public static function handle(
|
||||
callable $callback,
|
||||
string $responseTitle = '요청'
|
||||
): JsonResponse
|
||||
{
|
||||
): JsonResponse {
|
||||
try {
|
||||
$result = $callback();
|
||||
|
||||
@@ -133,12 +137,12 @@ public static function handle(
|
||||
// ['error' => 'NO_TENANT', 'code' => 400]
|
||||
// ['code' => 404, 'message' => '데이터 없음']
|
||||
if (is_array($result) && (
|
||||
array_key_exists('error', $result) ||
|
||||
(array_key_exists('code', $result) && is_numeric($result['code']) && (int)$result['code'] >= 400)
|
||||
)
|
||||
array_key_exists('error', $result) ||
|
||||
(array_key_exists('code', $result) && is_numeric($result['code']) && (int) $result['code'] >= 400)
|
||||
)
|
||||
) {
|
||||
$code = (int)($result['code'] ?? 400);
|
||||
$message = (string)($result['message'] ?? ($result['error'] ?? ($responseTitle.' 실패')));
|
||||
$code = (int) ($result['code'] ?? 400);
|
||||
$message = (string) ($result['message'] ?? ($result['error'] ?? ($responseTitle.' 실패')));
|
||||
$details = $result['details'] ?? null;
|
||||
|
||||
// 에러에도 쿼리 로그 포함되도록 error()가 처리하게 맡김
|
||||
@@ -147,11 +151,11 @@ public static function handle(
|
||||
|
||||
// 표준 박스( ['data'=>..., 'query'=>...] ) 하위호환
|
||||
if (is_array($result) && array_key_exists('data', $result)) {
|
||||
$data = $result['data'];
|
||||
$data = $result['data'];
|
||||
$debug = $result['query'] ?? [];
|
||||
} else {
|
||||
// 그냥 도메인 결과만 반환한 경우
|
||||
$data = $result;
|
||||
$data = $result;
|
||||
$debug = (app()->environment('local') && request()->is('api/*'))
|
||||
? self::debugQueryLog()
|
||||
: [];
|
||||
|
||||
Reference in New Issue
Block a user