1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Laravel\Forge\Sites; |
4
|
|
|
|
5
|
|
|
use Laravel\Forge\Contracts\ApplicationContract; |
6
|
|
|
use Laravel\Forge\ApiResource; |
7
|
|
|
|
8
|
|
|
class Site extends ApiResource |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Resource type. |
12
|
|
|
* |
13
|
|
|
* @return string |
14
|
|
|
*/ |
15
|
|
|
public static function resourceType() |
16
|
|
|
{ |
17
|
|
|
return 'site'; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Resource path (relative to Server URL). |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public function resourcePath() |
26
|
|
|
{ |
27
|
|
|
return 'sites'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Site domain. |
32
|
|
|
* |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
public function domain() |
36
|
|
|
{ |
37
|
|
|
return $this->getData('name'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Site username. |
42
|
|
|
* |
43
|
|
|
* @return string|null |
44
|
|
|
*/ |
45
|
|
|
public function username() |
46
|
|
|
{ |
47
|
|
|
return $this->getData('username'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Project type. |
52
|
|
|
* |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
public function projectType() |
56
|
|
|
{ |
57
|
|
|
return $this->getData('project_type'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Site directory. |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public function directory() |
66
|
|
|
{ |
67
|
|
|
return $this->getData('directory'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Site repository. |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function repository() |
76
|
|
|
{ |
77
|
|
|
return $this->getData('repository'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Site repository provider. |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function repositoryProvider() |
86
|
|
|
{ |
87
|
|
|
return $this->getData('repository_provider'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Site repository branch. |
92
|
|
|
* |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function repositoryBranch() |
96
|
|
|
{ |
97
|
|
|
return $this->getData('repository_branch'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Site repository status. |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function repositoryStatus() |
106
|
|
|
{ |
107
|
|
|
return $this->getData('repository_status'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Site deployment status. |
112
|
|
|
* |
113
|
|
|
* @return string | null |
114
|
|
|
*/ |
115
|
|
|
public function deploymentStatus() |
116
|
|
|
{ |
117
|
|
|
return $this->getData('deployment_status'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Site allows wildcard URIs. |
122
|
|
|
* |
123
|
|
|
* @return boolean |
124
|
|
|
*/ |
125
|
|
|
public function wildcards() |
126
|
|
|
{ |
127
|
|
|
return $this->getData('wildcards'); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Site quick deploy enabled. |
132
|
|
|
* |
133
|
|
|
* @return boolean |
134
|
|
|
*/ |
135
|
|
|
public function quickDeploy() |
136
|
|
|
{ |
137
|
|
|
return $this->getData('quick_deploy'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Site hipchat room. |
142
|
|
|
* |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function hipchatRoom() |
146
|
|
|
{ |
147
|
|
|
return $this->getData('hipchat_room'); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Site slack channel. |
152
|
|
|
* |
153
|
|
|
* @return string |
154
|
|
|
*/ |
155
|
|
|
public function slackChannel() |
156
|
|
|
{ |
157
|
|
|
return $this->getData('slack_channel'); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Site app. |
162
|
|
|
* |
163
|
|
|
* @return string | null |
164
|
|
|
*/ |
165
|
|
|
public function app() |
166
|
|
|
{ |
167
|
|
|
return $this->getData('app'); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Site app status. |
172
|
|
|
* |
173
|
|
|
* @return string | null |
174
|
|
|
*/ |
175
|
|
|
public function appStatus() |
176
|
|
|
{ |
177
|
|
|
return $this->getData('app_status'); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Install new application on site. |
182
|
|
|
* |
183
|
|
|
* @param \Laravel\Forge\Contracts\ApplicationContract $application |
184
|
|
|
* |
185
|
|
|
* @return bool |
186
|
|
|
*/ |
187
|
|
View Code Duplication |
public function install(ApplicationContract $application) |
|
|
|
|
188
|
|
|
{ |
189
|
|
|
$this->getHttpClient()->request('POST', $this->apiUrl($application->type()), [ |
190
|
|
|
'json' => $application->payload(), |
191
|
|
|
]); |
192
|
|
|
|
193
|
|
|
return true; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Install new application on site. |
198
|
|
|
* |
199
|
|
|
* @param \Laravel\Forge\Contracts\ApplicationContract $application |
200
|
|
|
* |
201
|
|
|
* @return bool |
202
|
|
|
*/ |
203
|
|
View Code Duplication |
public function updateApplication(ApplicationContract $application) |
|
|
|
|
204
|
|
|
{ |
205
|
|
|
$this->getHttpClient()->request('PUT', $this->apiUrl($application->type()), [ |
206
|
|
|
'json' => $application->payload(), |
207
|
|
|
]); |
208
|
|
|
|
209
|
|
|
return true; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Uninstall application from site. |
214
|
|
|
* |
215
|
|
|
* @param \Laravel\Forge\Contracts\ApplicationContract $application |
216
|
|
|
* |
217
|
|
|
* @return bool |
218
|
|
|
*/ |
219
|
|
|
public function uninstall(ApplicationContract $application) |
220
|
|
|
{ |
221
|
|
|
$this->getHttpClient()->request('DELETE', $this->apiUrl($application->type())); |
222
|
|
|
|
223
|
|
|
return true; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Connect load balancer. |
228
|
|
|
* |
229
|
|
|
* @return bool |
230
|
|
|
*/ |
231
|
|
|
public function balance(array $serverIds) |
232
|
|
|
{ |
233
|
|
|
$this->getHttpClient()->request('PUT', $this->apiUrl('/balancing'), [ |
234
|
|
|
'json' => ['servers' => $serverIds] |
235
|
|
|
]); |
236
|
|
|
|
237
|
|
|
return true; |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.