|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Laravel Platfourm package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Longman\Platfourm\Http\Controllers; |
|
12
|
|
|
|
|
13
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
|
14
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesResources; |
|
15
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
|
16
|
|
|
use Illuminate\Foundation\Validation\ValidatesRequests; |
|
17
|
|
|
use Illuminate\Routing\Controller as BaseController; |
|
18
|
|
|
use Longman\Platfourm\Contracts\Auth\AuthUserService as AuthUserServiceContract; |
|
19
|
|
|
use View; |
|
20
|
|
|
|
|
21
|
|
|
abstract class Controller extends BaseController |
|
22
|
|
|
{ |
|
23
|
|
|
use AuthorizesRequests, DispatchesJobs, ValidatesRequests; |
|
24
|
|
|
|
|
25
|
|
|
protected $app; |
|
26
|
|
|
|
|
27
|
|
|
protected $scopeNamespace; |
|
28
|
|
|
protected $httpNamespace; |
|
29
|
|
|
protected $viewNamespace; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->app = app(); |
|
34
|
|
|
$lang = $this->app->getLocale(); |
|
35
|
|
|
View::share([ |
|
36
|
|
|
'lang' => $lang, |
|
37
|
|
|
]); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Get auth user service. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $guard |
|
44
|
|
|
* @return \Longman\Platfourm\Auth\Services\AuthUserService |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getAuthService($guard = null) |
|
47
|
|
|
{ |
|
48
|
|
|
$authService = $this->app->make(AuthUserServiceContract::class); |
|
49
|
|
|
return $authService->setGuard($guard); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get the evaluated view contents for the given view. |
|
54
|
|
|
* |
|
55
|
|
|
* @param string $view |
|
56
|
|
|
* @param array $data |
|
57
|
|
|
* @param array $mergeData |
|
58
|
|
|
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function view($view, $data = [], $mergeData = []) |
|
61
|
|
|
{ |
|
62
|
|
|
$viewMask = []; |
|
63
|
|
|
if ($this->scopeNamespace) { |
|
64
|
|
|
$viewMask[] = $this->scopeNamespace; |
|
65
|
|
|
} |
|
66
|
|
|
if ($this->viewNamespace) { |
|
67
|
|
|
$viewMask[] = $this->viewNamespace; |
|
68
|
|
|
} |
|
69
|
|
|
$viewMask[] = $view; |
|
70
|
|
|
|
|
71
|
|
|
return view(implode('.', $viewMask), $data, $mergeData); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get an instance of the redirector. |
|
76
|
|
|
* |
|
77
|
|
|
* @param string|null $to |
|
78
|
|
|
* @param int $status |
|
79
|
|
|
* @param array $headers |
|
80
|
|
|
* @param bool $secure |
|
81
|
|
|
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function redirect($to = null, $status = 302, $headers = [], $secure = null) |
|
84
|
|
|
{ |
|
85
|
|
|
if ($to === null) { |
|
86
|
|
|
return redirect(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
if ($to === '/') { |
|
90
|
|
|
return redirect($to, $status, $headers, $secure); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$toMask = []; |
|
94
|
|
|
if ($this->scopeNamespace && $this->scopeNamespace !== 'site') { |
|
95
|
|
|
$toMask[] = $this->scopeNamespace; |
|
96
|
|
|
} |
|
97
|
|
|
if ($this->httpNamespace) { |
|
98
|
|
|
$toMask[] = $this->httpNamespace; |
|
99
|
|
|
} |
|
100
|
|
|
$toMask[] = $to; |
|
101
|
|
|
|
|
102
|
|
|
return redirect(implode('/', $toMask), $status, $headers, $secure); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Return a new response from the application. |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $content |
|
109
|
|
|
* @param int $status |
|
110
|
|
|
* @param array $headers |
|
111
|
|
|
* @return \Symfony\Component\HttpFoundation\Response|\Illuminate\Contracts\Routing\ResponseFactory |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function response($content = '', $status = 200, array $headers = []) |
|
114
|
|
|
{ |
|
115
|
|
|
return response($content, $status, $headers); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|