1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JumpGate\ViewResolution\Builders; |
4
|
|
|
|
5
|
|
|
use Illuminate\View\Factory; |
6
|
|
|
use JumpGate\ViewResolution\Models\View as ViewModel; |
7
|
|
|
use JumpGate\ViewResolution\Resolvers\Layout; |
8
|
|
|
use JumpGate\ViewResolution\Resolvers\Path; |
9
|
|
|
|
10
|
|
|
class View |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var \Illuminate\View\View |
14
|
|
|
*/ |
15
|
|
|
public $layout; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var Factory |
19
|
|
|
*/ |
20
|
|
|
public $view; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var Layout |
24
|
|
|
*/ |
25
|
|
|
protected $viewLayout; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var Path |
29
|
|
|
*/ |
30
|
|
|
protected $viewPath; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param Layout $viewLayout |
34
|
|
|
* @param Path $viewPath |
35
|
|
|
* @param Factory $view |
36
|
|
|
*/ |
37
|
|
|
public function __construct(Layout $viewLayout, Path $viewPath, Factory $view) |
38
|
|
|
{ |
39
|
|
|
$this->viewLayout = $viewLayout; |
40
|
|
|
$this->viewPath = $viewPath; |
41
|
|
|
$this->view = $view; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param array $layoutOptions |
46
|
|
|
* @param null|string $view |
47
|
|
|
*/ |
48
|
|
|
public function setUp($layoutOptions, $view = null) |
49
|
|
|
{ |
50
|
|
|
$this->layout = $this->viewLayout->setUp($layoutOptions); |
|
|
|
|
51
|
|
|
$this->layout->layout = $this->viewPath->setUp($this->layout->layout, $view); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Check if a view exists. |
56
|
|
|
* |
57
|
|
|
* @param string $view |
58
|
|
|
* |
59
|
|
|
* @return bool |
60
|
|
|
*/ |
61
|
|
|
public function exists($view) |
62
|
|
|
{ |
63
|
|
|
return $this->view->exists($view); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get the current layout. |
68
|
|
|
* |
69
|
|
|
* @return mixed |
70
|
|
|
*/ |
71
|
|
|
public function getLayout() |
72
|
|
|
{ |
73
|
|
|
return $this->layout->layout; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* If a method is not defined, try to find it's view. |
78
|
|
|
* |
79
|
|
|
* @param array $parameters |
80
|
|
|
* |
81
|
|
|
* @return $this |
82
|
|
|
*/ |
83
|
|
|
public function missingMethod($parameters) |
84
|
|
|
{ |
85
|
|
|
if (! app()->runningInConsole()) { |
86
|
|
|
$this->viewPath->missingMethod($this->layout->layout, $parameters); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Set a custom layout for a page. |
94
|
|
|
* |
95
|
|
|
* @param string $view |
96
|
|
|
*/ |
97
|
|
|
public function setViewLayout($view) |
98
|
|
|
{ |
99
|
|
|
$this->layout = $this->viewLayout->change($view); |
|
|
|
|
100
|
|
|
$this->layout->layout = $this->viewPath->setUp($this->layout->layout, null); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Override the automatically resolved view. |
105
|
|
|
* |
106
|
|
|
* @param string $view |
107
|
|
|
* |
108
|
|
|
* @return $this |
109
|
|
|
*/ |
110
|
|
|
public function setViewPath($view) |
111
|
|
|
{ |
112
|
|
|
$this->layout->layout = $this->viewPath->setUp($this->layout->layout, $view); |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Share data with the view. |
119
|
|
|
* |
120
|
|
|
* @param $key |
121
|
|
|
* @param $value |
122
|
|
|
* |
123
|
|
|
* @return $this |
124
|
|
|
*/ |
125
|
|
|
public function addData($key, $value) |
126
|
|
|
{ |
127
|
|
|
$this->view->share($key, $value); |
128
|
|
|
|
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Return the dot notation view the resolver determined. |
134
|
|
|
* |
135
|
|
|
* @return mixed |
136
|
|
|
*/ |
137
|
|
|
public function getPath() |
138
|
|
|
{ |
139
|
|
|
return $this->viewPath->path; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Return the details of the view resolution for troubleshooting. |
144
|
|
|
* |
145
|
|
|
* @return mixed |
146
|
|
|
*/ |
147
|
|
|
public function debug() |
148
|
|
|
{ |
149
|
|
|
return $this->viewPath->viewModel; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Pass the view resolution details to the debugbar collector. |
154
|
|
|
* |
155
|
|
|
* @param ViewModel $viewModel |
156
|
|
|
*/ |
157
|
|
|
public function collectDetails($viewModel) |
158
|
|
|
{ |
159
|
|
|
if (checkDebugbar()) { |
160
|
|
|
$debugbar = app('debugbar'); |
161
|
|
|
|
162
|
|
|
if ($debugbar->shouldCollect('auto_views')) { |
163
|
|
|
$debugbar['auto_views']->addDetails($viewModel); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..