add nova
This commit is contained in:
67
nova/src/Exceptions/AuthenticationException.php
Normal file
67
nova/src/Exceptions/AuthenticationException.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Exceptions;
|
||||
|
||||
use Illuminate\Auth\AuthenticationException as BaseAuthenticationException;
|
||||
use Inertia\Inertia;
|
||||
use Laravel\Nova\Nova;
|
||||
|
||||
class AuthenticationException extends BaseAuthenticationException
|
||||
{
|
||||
/**
|
||||
* Render the exception.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function render($request)
|
||||
{
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'message' => $this->getMessage(),
|
||||
'redirect' => $this->location(),
|
||||
], 401);
|
||||
} elseif ($request->is('nova-api/*') || $request->is('nova-vendor/*')) {
|
||||
return response(null, 401);
|
||||
}
|
||||
|
||||
if ($request->inertia() || config('nova.routes.login', false) !== false) {
|
||||
return $this->redirectForInertia($request);
|
||||
}
|
||||
|
||||
return redirect()->guest($this->location());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the location the user should be redirected to.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function location()
|
||||
{
|
||||
return config('nova.routes.login') ?: Nova::url('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect request for Inertia.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
protected function redirectForInertia($request)
|
||||
{
|
||||
tap(redirect(), function ($redirect) use ($request) {
|
||||
$url = $redirect->getUrlGenerator();
|
||||
|
||||
$intended = $request->method() === 'GET' && $request->route() && ! $request->expectsJson()
|
||||
? $url->full()
|
||||
: $url->previous();
|
||||
|
||||
if ($intended) {
|
||||
$redirect->setIntendedUrl($intended);
|
||||
}
|
||||
});
|
||||
|
||||
return Inertia::location($this->location());
|
||||
}
|
||||
}
|
||||
9
nova/src/Exceptions/HelperNotSupported.php
Normal file
9
nova/src/Exceptions/HelperNotSupported.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class HelperNotSupported extends Exception
|
||||
{
|
||||
}
|
||||
10
nova/src/Exceptions/LensCountException.php
Normal file
10
nova/src/Exceptions/LensCountException.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Exceptions;
|
||||
|
||||
use LogicException;
|
||||
|
||||
class LensCountException extends LogicException
|
||||
{
|
||||
//
|
||||
}
|
||||
20
nova/src/Exceptions/MissingActionHandlerException.php
Normal file
20
nova/src/Exceptions/MissingActionHandlerException.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class MissingActionHandlerException extends Exception
|
||||
{
|
||||
/**
|
||||
* Create a new exception instance.
|
||||
*
|
||||
* @param mixed $action
|
||||
* @param string $method
|
||||
* @return static
|
||||
*/
|
||||
public static function make($action, $method)
|
||||
{
|
||||
return new static('Action handler ['.get_class($action).'@'.$method.'] not defined.');
|
||||
}
|
||||
}
|
||||
31
nova/src/Exceptions/NovaException.php
Normal file
31
nova/src/Exceptions/NovaException.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class NovaException extends Exception
|
||||
{
|
||||
/**
|
||||
* Create a new exception instance.
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $class
|
||||
* @return \Laravel\Nova\Exceptions\HelperNotSupported
|
||||
*/
|
||||
public static function helperNotSupported($method, $class)
|
||||
{
|
||||
return new HelperNotSupported("The {$method} helper method is not supported by the {$class} class.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new exception instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Laravel\Nova\Exceptions\ResourceMissingException
|
||||
*/
|
||||
public static function missingResourceForRepeater($name)
|
||||
{
|
||||
return ResourceMissingException::forRepeater("Missing resource for repeater {$name}");
|
||||
}
|
||||
}
|
||||
75
nova/src/Exceptions/NovaExceptionHandler.php
Normal file
75
nova/src/Exceptions/NovaExceptionHandler.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Exceptions;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Inertia\Inertia;
|
||||
use Laravel\Nova\Nova;
|
||||
use Laravel\Nova\Util;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
use Throwable;
|
||||
|
||||
class NovaExceptionHandler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*
|
||||
* Used only on Laravel 8 and above.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
with(Nova::$reportCallback, function ($handler) {
|
||||
/** @var (callable(\Throwable):(void))|(\Closure(\Throwable):(void))|null $handler */
|
||||
if ($handler instanceof Closure || is_callable($handler)) {
|
||||
$this->reportable(function (Throwable $e) use ($handler) {
|
||||
call_user_func($handler, $e);
|
||||
})->stop();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare exception for rendering.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Throwable $e
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function render($request, Throwable $e)
|
||||
{
|
||||
if (Util::isNovaRequest($request)) {
|
||||
return $this->renderInertiaException($request, $this->prepareException($e));
|
||||
}
|
||||
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render Inertia Exception.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface|\Throwable $e
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
protected function renderInertiaException($request, $e)
|
||||
{
|
||||
$statusCode = $e instanceof HttpExceptionInterface ? $e->getStatusCode() : 500;
|
||||
|
||||
Inertia::setRootView('nova::layout');
|
||||
|
||||
if ($statusCode === 403) {
|
||||
return Inertia::render('Nova.Error403')->toResponse($request)->setStatusCode($statusCode);
|
||||
} elseif ($statusCode === 404) {
|
||||
return Inertia::render('Nova.Error404')->toResponse($request)->setStatusCode($statusCode);
|
||||
}
|
||||
|
||||
if ($request->inertia()) {
|
||||
return Inertia::render('Nova.Error')->toResponse($request)->setStatusCode(500);
|
||||
}
|
||||
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
}
|
||||
30
nova/src/Exceptions/ResourceMissingException.php
Normal file
30
nova/src/Exceptions/ResourceMissingException.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ResourceMissingException extends Exception
|
||||
{
|
||||
public function __construct(Model $model)
|
||||
{
|
||||
parent::__construct(
|
||||
__('Unable to find Resource for model [:model].', ['model' => get_class($model)])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new exception instance.
|
||||
*
|
||||
* @param string $resource
|
||||
* @return static
|
||||
*/
|
||||
public static function forRepeater($resource)
|
||||
{
|
||||
return new static(__(
|
||||
"Unable to find Resource for the given resource name [:resource],
|
||||
['resource' => $resource]
|
||||
"));
|
||||
}
|
||||
}
|
||||
22
nova/src/Exceptions/ResourceSaveCancelledException.php
Normal file
22
nova/src/Exceptions/ResourceSaveCancelledException.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Nova\Exceptions;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class ResourceSaveCancelledException extends HttpException
|
||||
{
|
||||
/**
|
||||
* @param string|null $message
|
||||
* @param \Throwable|null $previous
|
||||
* @param int $code
|
||||
*/
|
||||
public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = [])
|
||||
{
|
||||
if (empty($message)) {
|
||||
$message = __('The resource was prevented from being saved!');
|
||||
}
|
||||
|
||||
parent::__construct(500, $message, $previous, $headers, $code);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user