1
|
|
|
<?php namespace Anomaly\Streams\Platform\Application; |
2
|
|
|
|
3
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Application |
7
|
|
|
* |
8
|
|
|
* @link http://pyrocms.com/ |
9
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
10
|
|
|
* @author Ryan Thompson <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class Application |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
use DispatchesJobs; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The application locale. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $locale = null; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The enabled state of the application. |
26
|
|
|
* |
27
|
|
|
* @var bool |
28
|
|
|
*/ |
29
|
|
|
protected $enabled = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Keep installed status around. |
33
|
|
|
* |
34
|
|
|
* @var bool |
35
|
|
|
*/ |
36
|
|
|
protected $installed = null; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The application reference. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $reference = 'default'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The application repository. |
47
|
|
|
* |
48
|
|
|
* @var ApplicationRepository |
49
|
|
|
*/ |
50
|
|
|
protected $applications; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Create a new Application instance. |
54
|
|
|
* |
55
|
|
|
* @param ApplicationRepository $model |
|
|
|
|
56
|
|
|
*/ |
57
|
|
|
public function __construct(ApplicationRepository $applications) |
58
|
|
|
{ |
59
|
|
|
$this->applications = $applications; |
60
|
|
|
|
61
|
|
|
$this->reference = env('DEFAULT_REFERENCE', $this->reference); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Setup the application. |
66
|
|
|
*/ |
67
|
|
|
public function setup() |
68
|
|
|
{ |
69
|
|
|
$this->setTablePrefix(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Set the database table prefix going forward. |
74
|
|
|
* We really don't need a core table from here on out. |
75
|
|
|
*/ |
76
|
|
|
public function setTablePrefix() |
77
|
|
|
{ |
78
|
|
|
app('db')->getSchemaBuilder()->getConnection()->setTablePrefix($this->getReference() . '_'); |
79
|
|
|
app('db')->getSchemaBuilder()->getConnection()->getSchemaGrammar()->setTablePrefix($this->getReference() . '_'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get the reference. |
84
|
|
|
* |
85
|
|
|
* @return null |
86
|
|
|
*/ |
87
|
|
|
public function getReference() |
88
|
|
|
{ |
89
|
|
|
return $this->reference; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Set the reference. |
94
|
|
|
* |
95
|
|
|
* @param $reference |
96
|
|
|
* @return $this |
97
|
|
|
*/ |
98
|
|
|
public function setReference($reference) |
99
|
|
|
{ |
100
|
|
|
$this->reference = $reference; |
101
|
|
|
|
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get the storage path for the application. |
107
|
|
|
* |
108
|
|
|
* @param string $path |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
public function getStoragePath($path = '') |
112
|
|
|
{ |
113
|
|
|
return storage_path('streams/' . $this->getReference()) . ($path ? '/' . $path : $path); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Get the public assets path for the application. |
118
|
|
|
* |
119
|
|
|
* @param string $path |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
public function getAssetsPath($path = '') |
123
|
|
|
{ |
124
|
|
|
return public_path('app/' . $this->getReference()) . ($path ? '/' . $path : $path); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Get the resources path for the application. |
129
|
|
|
* |
130
|
|
|
* @param string $path |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function getResourcesPath($path = '') |
134
|
|
|
{ |
135
|
|
|
return base_path('resources/' . $this->getReference()) . ($path ? '/' . $path : $path); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Return the app reference. |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function tablePrefix() |
144
|
|
|
{ |
145
|
|
|
return $this->reference . '_'; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Locate the app by request or passed |
150
|
|
|
* variable and set the application reference. |
151
|
|
|
* |
152
|
|
|
* @return bool |
153
|
|
|
*/ |
154
|
|
|
public function locate() |
155
|
|
|
{ |
156
|
|
|
if ($app = $this->applications->findByDomain(app('request')->root())) { |
157
|
|
|
|
158
|
|
|
$this->installed = true; |
159
|
|
|
$this->locale = $app->locale; |
|
|
|
|
160
|
|
|
$this->enabled = $app->enabled; |
|
|
|
|
161
|
|
|
$this->reference = $app->reference; |
|
|
|
|
162
|
|
|
|
163
|
|
|
return true; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
return false; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Get the resolved locale. |
171
|
|
|
* |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
|
|
public function getLocale() |
175
|
|
|
{ |
176
|
|
|
return $this->locale; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Return if the application is enabled. |
181
|
|
|
* |
182
|
|
|
* @return bool |
183
|
|
|
*/ |
184
|
|
|
public function isEnabled() |
185
|
|
|
{ |
186
|
|
|
if (is_null($this->enabled)) { |
187
|
|
|
return true; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
return $this->enabled; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Is the application installed? |
195
|
|
|
* |
196
|
|
|
* @return bool |
197
|
|
|
*/ |
198
|
|
|
public function isInstalled() |
199
|
|
|
{ |
200
|
|
|
if (is_null($this->installed)) { |
201
|
|
|
$this->installed = file_exists(base_path('.env')); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
return $this->installed; |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.