58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Presentation\Api\V1\Http\Requests\IncoSheets;
|
|
|
|
use Domain\Models\ValueObjects\Inco\IncoIdQuery;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
/**
|
|
* @method \Uri\Rfc3986\Uri toUri()
|
|
*/
|
|
final class IncoSheetsSearchRequest extends FormRequest
|
|
{
|
|
/** @return array<string, array<int, mixed>> */
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'incoIdLike' => ['required', 'string'],
|
|
'brands' => ['sometimes', 'array'],
|
|
'brands.*' => ['sometimes', 'string'],
|
|
'short' => ['sometimes', Rule::in(['true', 'false', true, false, '1', '0', 1, 0])],
|
|
];
|
|
}
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function incoIdSearch(): IncoIdQuery
|
|
{
|
|
return new IncoIdQuery($this->string('incoIdLike')->value());
|
|
}
|
|
|
|
/** @return array<string> */
|
|
public function brands(): array
|
|
{
|
|
$raw = $this->array('brands');
|
|
$result = [];
|
|
foreach ($raw as $b) {
|
|
if (is_string($b) || is_numeric($b)) {
|
|
$val = trim((string) $b);
|
|
if ($val !== '') {
|
|
$result[] = $val;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
public function isShort(): bool
|
|
{
|
|
return filter_var($this->input('short', false), FILTER_VALIDATE_BOOLEAN);
|
|
}
|
|
}
|