|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Acacha\ForgePublish\Commands\Traits; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Trait InteractsWithAssignments. |
|
7
|
|
|
* |
|
8
|
|
|
* @package Acacha\ForgePublish\Commands\Traits |
|
9
|
|
|
*/ |
|
10
|
|
|
trait InteractsWithAssignments |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Ask assignment. |
|
14
|
|
|
*/ |
|
15
|
|
|
protected function askAssignment() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->assignments = $this->fetchAssignments(); |
|
|
|
|
|
|
18
|
|
|
$names = collect($this->assignments)->pluck('name')->toArray(); |
|
19
|
|
|
$default = array_search($this->currentAssignment(),$names); |
|
20
|
|
|
$selected = $this->choice('Assignment?',$names,$default); |
|
|
|
|
|
|
21
|
|
|
return $this->findAssignmentByName($selected)->id; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Current assignment |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function currentAssignment() { |
|
28
|
|
|
if (fp_env('ACACHA_FORGE_ASSIGNMENT')) { |
|
29
|
|
|
$assignmentFound = collect($this->assignments)->filter(function ($assignment) { |
|
30
|
|
|
return $assignment->id == fp_env('ACACHA_FORGE_ASSIGNMENT'); |
|
31
|
|
|
})->first(); |
|
32
|
|
|
if ($assignmentFound) return $assignmentFound->name; |
|
33
|
|
|
} |
|
34
|
|
|
return null; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Find assignment by name. |
|
39
|
|
|
* |
|
40
|
|
|
* @param $name |
|
41
|
|
|
* @return null |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function findAssignmentByName($name) |
|
44
|
|
|
{ |
|
45
|
|
|
$assignmentFound = collect($this->assignments)->filter(function ($assignment) use ($name) { |
|
46
|
|
|
return $assignment->name == $name; |
|
47
|
|
|
})->first(); |
|
48
|
|
|
if ($assignmentFound) return $assignmentFound; |
|
49
|
|
|
return null; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Ask forge site. |
|
54
|
|
|
* |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function askForgeSite() |
|
58
|
|
|
{ |
|
59
|
|
|
$default = $this->defaultForgeSite(); |
|
60
|
|
|
return $this->ask('Forge site?',$default); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Ask forge server. |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function askForgeServer() |
|
69
|
|
|
{ |
|
70
|
|
|
$default = $this->defaultForgeServer(); |
|
71
|
|
|
return $this->ask('Forge server?',$default); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Default forge site |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function defaultForgeSite() |
|
78
|
|
|
{ |
|
79
|
|
|
return fp_env('ACACHA_FORGE_SITE') ? fp_env('ACACHA_FORGE_SITE') : null; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Default forge server. |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function defaultForgeServer() |
|
86
|
|
|
{ |
|
87
|
|
|
return fp_env('ACACHA_FORGE_SERVER') ? fp_env('ACACHA_FORGE_SERVER') : null; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Ask name. |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function askName() |
|
94
|
|
|
{ |
|
95
|
|
|
$default = $this->defaultName(); |
|
96
|
|
|
return $this->ask('name?',$default); |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Ask repository Uri. |
|
101
|
|
|
*/ |
|
102
|
|
|
protected function askRepositoryUri() { |
|
103
|
|
|
$default = $this->defaultRepositoryUri(); |
|
|
|
|
|
|
104
|
|
|
return $this->ask('Repository URI?', $default); |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Ask repository Uri. |
|
109
|
|
|
*/ |
|
110
|
|
|
protected function askRepositoryType() { |
|
111
|
|
|
$default = $this->defaultRepositoryType(); |
|
112
|
|
|
return $this->ask('Repository type?', $default); |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Default repository type. |
|
117
|
|
|
* |
|
118
|
|
|
* @return string |
|
119
|
|
|
*/ |
|
120
|
|
|
protected function defaultRepositoryType() |
|
121
|
|
|
{ |
|
122
|
|
|
return 'github'; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Default repository URI. |
|
127
|
|
|
* |
|
128
|
|
|
* @return null |
|
129
|
|
|
*/ |
|
130
|
|
|
protected function defaultRepositoryUri() |
|
131
|
|
|
{ |
|
132
|
|
|
return fp_env('ACACHA_FORGE_GITHUB_REPO') ? fp_env('ACACHA_FORGE_GITHUB_REPO') : $this->getRepoFromGithubConfig(); |
|
|
|
|
|
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Default name. |
|
137
|
|
|
* |
|
138
|
|
|
* @return null|string |
|
139
|
|
|
*/ |
|
140
|
|
|
protected function defaultName() |
|
141
|
|
|
{ |
|
142
|
|
|
return fp_env('ACACHA_FORGE_DOMAIN') ? fp_env('ACACHA_FORGE_DOMAIN') : strtolower(camel_case(basename(getcwd()))); |
|
143
|
|
|
} |
|
144
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: