transition

This commit is contained in:
2024-08-14 22:04:34 +03:00
parent 1ab3f678b7
commit 1f3ebafe69
50 changed files with 924 additions and 172 deletions
+17
View File
@@ -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);
}
}
+59
View File
@@ -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()]);
}
}