major update
This commit is contained in:
38
lib/Support/helpers/request.php
Normal file
38
lib/Support/helpers/request.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user