1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SleepingOwl\Admin\Templates; |
4
|
|
|
|
5
|
|
|
use SleepingOwl\Admin\Contracts\AdminInterface; |
6
|
|
|
use Illuminate\Contracts\Foundation\Application; |
7
|
|
|
use SleepingOwl\Admin\Contracts\Template\MetaInterface; |
8
|
|
|
use SleepingOwl\Admin\Contracts\Template\TemplateInterface; |
9
|
|
|
use SleepingOwl\Admin\Contracts\Navigation\NavigationInterface; |
10
|
|
|
|
11
|
|
|
abstract class Template implements TemplateInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Application |
15
|
|
|
*/ |
16
|
|
|
protected $app; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var MetaInterface |
20
|
|
|
*/ |
21
|
|
|
protected $meta; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var NavigationInterface |
25
|
|
|
*/ |
26
|
|
|
protected $navigation; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Breadcrumbs |
30
|
|
|
*/ |
31
|
|
|
protected $breadcrumbs; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var AdminInterface |
35
|
|
|
*/ |
36
|
|
|
protected $admin; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* TemplateDefault constructor. |
40
|
|
|
* |
41
|
|
|
* @param Application $application |
42
|
|
|
* @param AdminInterface $admin |
43
|
|
|
* @param MetaInterface $meta |
44
|
|
|
* @param NavigationInterface $navigation |
45
|
|
|
* @param Breadcrumbs $breadcrumbs |
46
|
|
|
*/ |
47
|
285 |
|
public function __construct( |
48
|
|
|
Application $application, |
49
|
|
|
AdminInterface $admin, |
50
|
|
|
MetaInterface $meta, |
51
|
|
|
NavigationInterface $navigation, |
52
|
|
|
Breadcrumbs $breadcrumbs |
53
|
|
|
) { |
54
|
285 |
|
$this->app = $application; |
55
|
285 |
|
$this->meta = $meta; |
56
|
285 |
|
$this->navigation = $navigation; |
57
|
285 |
|
$this->breadcrumbs = $breadcrumbs; |
58
|
285 |
|
$this->admin = $admin; |
59
|
285 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Название с указанием версии. |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
public function longName() |
67
|
|
|
{ |
68
|
|
|
return $this->name().' v.'.$this->version(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return Breadcrumbs |
73
|
|
|
*/ |
74
|
|
|
public function breadcrumbs() |
75
|
|
|
{ |
76
|
|
|
return $this->breadcrumbs; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return MetaInterface |
81
|
|
|
*/ |
82
|
285 |
|
public function meta() |
83
|
|
|
{ |
84
|
285 |
|
return $this->meta; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return NavigationInterface |
89
|
|
|
*/ |
90
|
|
|
public function navigation() |
91
|
|
|
{ |
92
|
|
|
return $this->navigation; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Генерация относительно пути до asset файлов для текущей темы. |
97
|
|
|
* |
98
|
|
|
* @param string $path относительный путь до файла, например `js/app.js` |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
285 |
|
public function assetPath($path = null) |
103
|
|
|
{ |
104
|
285 |
|
return ! is_null($path) ? $this->assetDir().'/'.ltrim($path, '/') : $this->assetDir(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
2 |
|
public function getTitle() |
111
|
|
|
{ |
112
|
2 |
|
return config('sleeping_owl.title'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param string $title |
117
|
|
|
* @param string $separator |
118
|
|
|
* |
119
|
|
|
* @return string |
120
|
|
|
*/ |
121
|
1 |
|
public function makeTitle($title, $separator = ' | ') |
122
|
|
|
{ |
123
|
1 |
|
if (empty($title)) { |
124
|
1 |
|
return $this->getTitle(); |
125
|
|
|
} |
126
|
|
|
|
127
|
1 |
|
return $title."{$separator}".$this->getTitle(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param string $view |
132
|
|
|
* |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
285 |
|
public function getViewPath($view) |
136
|
|
|
{ |
137
|
285 |
|
if ($view instanceof \Illuminate\View\View) { |
138
|
1 |
|
return $view->getPath(); |
139
|
|
|
} |
140
|
|
|
|
141
|
285 |
|
return $this->getViewNamespace().'.'.$view; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @param string|\Illuminate\View\View $view |
146
|
|
|
* @param array $data |
147
|
|
|
* @param array $mergeData |
148
|
|
|
* |
149
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
150
|
|
|
*/ |
151
|
1 |
|
public function view($view, array $data = [], $mergeData = []) |
152
|
|
|
{ |
153
|
1 |
|
$data['template'] = $this; |
154
|
|
|
|
155
|
1 |
|
if ($view instanceof \Illuminate\View\View) { |
156
|
1 |
|
return $view->with($data); |
157
|
|
|
} |
158
|
|
|
|
159
|
1 |
|
return view($this->getViewPath($view), $data, $mergeData); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param string $key |
164
|
|
|
* |
165
|
|
|
* @return string |
166
|
|
|
*/ |
167
|
|
|
public function renderBreadcrumbs($key) |
168
|
|
|
{ |
169
|
|
|
if (config('sleeping_owl.breadcrumbs')) { |
170
|
|
|
$this->breadcrumbs()->setView( |
171
|
|
|
$this->getViewPath('_partials.breadcrumbs') |
172
|
|
|
); |
173
|
|
|
|
174
|
|
|
return $this->breadcrumbs()->renderIfExists($key); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @return string |
180
|
|
|
*/ |
181
|
|
|
public function renderNavigation() |
182
|
|
|
{ |
183
|
|
|
return $this->navigation()->render( |
184
|
|
|
$this->getViewPath('_partials.navigation.navigation') |
|
|
|
|
185
|
|
|
); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Регистрация стандартных глобальных Javascript перменных. |
190
|
|
|
*/ |
191
|
|
|
protected function setGlobalVariables() |
192
|
|
|
{ |
193
|
|
|
$globalVars = $this->admin->scriptVariables(); |
194
|
|
|
|
195
|
|
|
foreach ($globalVars as $var => $value) { |
196
|
|
|
$this->meta->putGlobalVar($var, $value); |
|
|
|
|
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param string $title |
202
|
|
|
* |
203
|
|
|
* @return string |
204
|
|
|
*/ |
205
|
|
|
public function renderMeta($title) |
206
|
|
|
{ |
207
|
|
|
$this->setGlobalVariables(); |
208
|
|
|
|
209
|
|
|
return $this->meta() |
210
|
|
|
->setTitle($this->makeTitle($title)) |
211
|
|
|
->addMeta(['charset' => 'utf-8'], 'meta::charset') |
212
|
|
|
->addMeta(['content' => csrf_token(), 'name' => 'csrf-token']) |
213
|
|
|
->addMeta(['content' => 'width=device-width, initial-scale=1', 'name' => 'viewport']) |
214
|
|
|
->addMeta(['content' => 'IE=edge', 'http-equiv' => 'X-UA-Compatible']) |
215
|
|
|
->render(); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
public function toArray() |
219
|
|
|
{ |
220
|
|
|
return [ |
221
|
|
|
'asset_dir' => $this->assetDir(), |
222
|
|
|
'view_namespace' => $this->getViewNamespace(), |
223
|
|
|
'name' => $this->name(), |
224
|
|
|
'version' => $this->version(), |
225
|
|
|
'homepage' => $this->homepage(), |
226
|
|
|
]; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.