Files
breadcrumb-the-shire/lib/Support/helpers/request.php
2026-03-04 15:56:58 +01:00

39 lines
906 B
PHP

<?php
use MintyPHP\Http\Input\FormErrors;
use MintyPHP\Http\Input\RequestInput;
use MintyPHP\Http\Input\RequestInputFactory;
use MintyPHP\Support\Flash;
function requestInput(): RequestInput
{
static $requestInput = null;
if ($requestInput instanceof RequestInput) {
return $requestInput;
}
$factory = app(RequestInputFactory::class);
$requestInput = $factory->create();
return $requestInput;
}
function formErrors(): FormErrors
{
return new FormErrors();
}
function formErrorsFrom(array|FormErrors $errors): FormErrors
{
return formErrors()->merge($errors);
}
function flashFormErrors(FormErrors $errors, ?string $scope = null, string $keyPrefix = 'form_error'): void
{
$index = 0;
foreach ($errors->toFlatList() as $message) {
$key = $keyPrefix . '_' . $index;
Flash::error((string) $message, $scope, $key);
$index++;
}
}