1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace A17\Twill\Exceptions; |
4
|
|
|
|
5
|
|
|
use Illuminate\Auth\AuthenticationException; |
6
|
|
|
use Illuminate\Config\Repository as Config; |
7
|
|
|
use Illuminate\Contracts\Container\Container; |
8
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
9
|
|
|
use Illuminate\Routing\Redirector; |
10
|
|
|
use Illuminate\Routing\ResponseFactory; |
11
|
|
|
use Illuminate\Routing\UrlGenerator; |
12
|
|
|
use Illuminate\Validation\ValidationException; |
13
|
|
|
use Illuminate\View\Factory as ViewFactory; |
14
|
|
|
|
15
|
|
|
class Handler extends ExceptionHandler |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var Redirector |
20
|
|
|
*/ |
21
|
|
|
protected $redirector; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var UrlGenerator |
25
|
|
|
*/ |
26
|
|
|
protected $urlGenerator; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var ViewFactory |
30
|
|
|
*/ |
31
|
|
|
protected $viewFactory; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var ResponseFactory |
35
|
|
|
*/ |
36
|
|
|
protected $responseFactory; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var Config |
40
|
|
|
*/ |
41
|
|
|
protected $config; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param Container $container |
45
|
|
|
* @param Redirector $redirector |
46
|
|
|
* @param UrlGenerator $urlGenerator |
47
|
|
|
* @param ResponseFactory $responseFactory |
48
|
|
|
*/ |
49
|
50 |
|
public function __construct( |
50
|
|
|
Container $container, |
51
|
|
|
Redirector $redirector, |
52
|
|
|
UrlGenerator $urlGenerator, |
53
|
|
|
ResponseFactory $responseFactory, |
54
|
|
|
Config $config, |
55
|
|
|
ViewFactory $viewFactory |
|
|
|
|
56
|
|
|
) { |
57
|
50 |
|
parent::__construct($container); |
58
|
|
|
|
59
|
50 |
|
$this->redirector = $redirector; |
60
|
50 |
|
$this->urlGenerator = $urlGenerator; |
61
|
50 |
|
$this->responseFactory = $responseFactory; |
62
|
50 |
|
$this->viewFactory = $responseFactory; |
|
|
|
|
63
|
50 |
|
$this->config = $config; |
64
|
50 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Convert an authentication exception into a response. |
68
|
|
|
* |
69
|
|
|
* @param \Illuminate\Http\Request $request |
70
|
|
|
* @param \Illuminate\Auth\AuthenticationException $exception |
71
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
72
|
|
|
*/ |
73
|
1 |
|
protected function unauthenticated($request, AuthenticationException $exception) |
74
|
|
|
{ |
75
|
1 |
|
return $request->expectsJson() |
76
|
|
|
? $this->responseFactory->json(['message' => $exception->getMessage()], 401) |
77
|
1 |
|
: $this->redirector->guest($exception->redirectTo() ?? $this->urlGenerator->route('admin.login')); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get the Twill error view used to render a specified HTTP status code. |
82
|
|
|
* |
83
|
|
|
* @param integer $statusCode |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
protected function getTwillErrorView($statusCode, $frontend = false) |
87
|
|
|
{ |
88
|
|
|
if ($frontend) { |
89
|
|
|
return $this->config->get('twill.frontend.views_path') . ".errors.{$statusCode}"; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $this->viewFactory->exists("admin.errors.$statusCode") ? "admin.errors.$statusCode" : "twill::errors.$statusCode"; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
protected function invalidJson($request, ValidationException $exception) |
96
|
|
|
{ |
97
|
|
|
return response()->json($exception->errors(), $exception->status); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.