transition
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Util\Form;
|
||||
|
||||
|
||||
use Exception;
|
||||
|
||||
|
||||
final class FormException extends Exception
|
||||
{
|
||||
// Redefine the exception so message isn't optional
|
||||
public function __construct(string $message, int $code = 0, Exception $previous = null)
|
||||
{
|
||||
// make sure everything is assigned properly
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Util\Form;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Validation\Validator;
|
||||
use Lucent\LucentException;
|
||||
|
||||
class ResponseFormError
|
||||
{
|
||||
/**
|
||||
* @param $errors list<string>
|
||||
*/
|
||||
public static function render(array $errors): ResponseFactory|Application|Response
|
||||
{
|
||||
return response(view("lucent::forms.errors", ["errors" => $errors])->render(), 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @return ResponseFactory|Application|Response
|
||||
*/
|
||||
public static function fromValidator(Validator $validator): ResponseFactory|Application|Response
|
||||
{
|
||||
|
||||
return self::render($validator->errors()->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $errors
|
||||
* @return ResponseFactory|Application|Response
|
||||
*/
|
||||
public static function fromArray(array $errors): ResponseFactory|Application|Response
|
||||
{
|
||||
return self::render($errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $errorString
|
||||
* @return ResponseFactory|Application|Response
|
||||
*/
|
||||
public static function fromMessage(string $errorString): ResponseFactory|Application|Response
|
||||
{
|
||||
return self::render([$errorString]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LucentException|FormException $exception
|
||||
* @return ResponseFactory|Application|Response
|
||||
*/
|
||||
public static function fromException(LucentException|FormException $exception): ResponseFactory|Application|Response
|
||||
{
|
||||
return self::render([$exception->getMessage()]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user