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