Use native request functions for request param parsing

This commit is contained in:
Jan Böhmer 2026-02-21 22:52:08 +01:00
parent 5100469751
commit 76584c3d99

View file

@ -308,21 +308,14 @@ class ScanController extends AbstractController
{ {
$this->denyAccessUnlessGranted('@tools.label_scanner'); $this->denyAccessUnlessGranted('@tools.label_scanner');
$input = trim((string) $request->request->get('input', '')); $input = trim($request->request->getString('input', ''));
$mode = (string) ($request->request->get('mode') ?? ''); $modeEnum = $request->request->getEnum('mode', BarcodeSourceType::class);
$infoMode = (bool) filter_var($request->request->get('info_mode', false), FILTER_VALIDATE_BOOL); $infoMode = $request->request->getBoolean('info_mode', false);
if ($input === '') { if ($input === '') {
return new JsonResponse(['ok' => false], 200); return new JsonResponse(['ok' => false], 200);
} }
$modeEnum = null;
if ($mode !== '') {
$i = (int) $mode;
$cases = BarcodeSourceType::cases();
$modeEnum = $cases[$i] ?? null; // null if out of range
}
try { try {
$scan = $this->barcodeNormalizer->scanBarcodeContent($input, $modeEnum); $scan = $this->barcodeNormalizer->scanBarcodeContent($input, $modeEnum);
} catch (InvalidArgumentException) { } catch (InvalidArgumentException) {
@ -340,7 +333,6 @@ class ScanController extends AbstractController
$redirectUrl = $this->barcodeParser->getRedirectURL($scan); $redirectUrl = $this->barcodeParser->getRedirectURL($scan);
$targetFound = true; $targetFound = true;
} catch (EntityNotFoundException) { } catch (EntityNotFoundException) {
$targetFound = false;
} }
// Only resolve Part for part-like targets. Storelocation scans should remain null here. // Only resolve Part for part-like targets. Storelocation scans should remain null here.