Files
trafficpumper/app/Http/Requests/StoreEarnTaskResultsRequest.php
T
2026-08-29 15:53:53 +03:00

71 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Validator;
class StoreEarnTaskResultsRequest extends FormRequest
{
/**
* Token ve cihaz yetkilendirmesi middleware'de tamamlandığı için isteğin doğrulanmasına izin verir.
*
* @author Gökhan Engin - İletişim : https://bit.ly/YazılımUzmanı
*/
public function authorize(): bool
{
return true;
}
/**
* Görev sonucu listesinin tür, boyut ve HTTP durum alanlarını katı biçimde doğrular.
*
* @return array<string, mixed>
*
* @author Gökhan Engin - İletişim : https://bit.ly/YazılımUzmanı
*/
public function rules(): array
{
return [
'tasks' => ['required', 'array', 'min:1', 'max:50'],
'tasks.*.CID' => ['required', 'integer', 'min:1'],
'tasks.*.task_id' => ['required', 'string', 'max:64'],
'tasks.*.completed' => ['required'],
'tasks.*.responseCode' => ['nullable', 'integer', 'between:100,599'],
'tasks.*.error' => ['nullable', 'string', 'max:'.config('earn.api.task_result_max_error_length')],
];
}
/**
* Boolean ve başarı alanlarının sessiz tür dönüşümü olmadan tutarlı olmasını denetler.
*
* @return array<int, callable(Validator): void>
*
* @author Gökhan Engin - İletişim : https://bit.ly/YazılımUzmanı
*/
public function after(): array
{
// Tür dönüşümü yapmadan kayıtlar arası tutarlılığı denetler.
// Yazar: Gökhan Engin - İletişim : https://bit.ly/YazılımUzmanı
return [function (Validator $validator): void {
foreach ((array) $this->input('tasks', []) as $index => $task) {
if (! is_int($task['CID'] ?? null)) {
$validator->errors()->add("tasks.$index.CID", 'The CID field must be a JSON integer.');
}
if (array_key_exists('responseCode', $task) && $task['responseCode'] !== null && ! is_int($task['responseCode'])) {
$validator->errors()->add("tasks.$index.responseCode", 'The responseCode field must be a JSON integer or null.');
}
if (! is_bool($task['completed'] ?? null)) {
$validator->errors()->add("tasks.$index.completed", 'The completed field must be a JSON boolean.');
continue;
}
if ($task['completed'] === true && (($task['error'] ?? null) !== null
|| ! isset($task['responseCode']) || $task['responseCode'] < 200 || $task['responseCode'] > 399)) {
$validator->errors()->add("tasks.$index.completed", 'A completed task requires a 2xx/3xx response and no error.');
}
}
}];
}
}