-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathScaffoldOptions.php
203 lines (183 loc) · 4.74 KB
/
ScaffoldOptions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
namespace Drupal\Composer\Plugin\Scaffold;
/**
* Per-project options from the 'extras' section of the composer.json file.
*
* Projects that describe scaffold files do so via their scaffold options. This
* data is pulled from the 'drupal-scaffold' portion of the extras section of
* the project data.
*
* @internal
*/
class ScaffoldOptions {
/**
* The raw data from the 'extras' section of the top-level composer.json file.
*
* @var array
*/
protected $options = [];
/**
* ScaffoldOptions constructor.
*
* @param array $options
* The scaffold options taken from the 'drupal-scaffold' section.
*/
protected function __construct(array $options) {
$this->options = $options + [
"allowed-packages" => [],
"locations" => [],
"symlink" => FALSE,
"file-mapping" => [],
];
// Define any default locations.
$this->options['locations'] += [
'project-root' => '.',
'web-root' => '.',
];
}
/**
* Determines if the provided 'extras' section has scaffold options.
*
* @param array $extras
* The contents of the 'extras' section.
*
* @return bool
* True if scaffold options have been declared
*/
public static function hasOptions(array $extras) {
return array_key_exists('drupal-scaffold', $extras);
}
/**
* Creates a scaffold options object.
*
* @param array $extras
* The contents of the 'extras' section.
*
* @return self
* The scaffold options object representing the provided scaffold options
*/
public static function create(array $extras) {
$options = static::hasOptions($extras) ? $extras['drupal-scaffold'] : [];
return new self($options);
}
/**
* Creates a new scaffold options object with some values overridden.
*
* @param array $options
* Override values.
*
* @return self
* The scaffold options object representing the provided scaffold options
*/
protected function override(array $options) {
return new self($options + $this->options);
}
/**
* Creates a new scaffold options object with an overridden 'symlink' value.
*
* @param bool $symlink
* Whether symlinking should be enabled or not.
*
* @return self
* The scaffold options object representing the provided scaffold options
*/
public function overrideSymlink($symlink) {
return $this->override(['symlink' => $symlink]);
}
/**
* Determines whether any allowed packages were defined.
*
* @return bool
* Whether there are allowed packages
*/
public function hasAllowedPackages() {
return !empty($this->allowedPackages());
}
/**
* Gets allowed packages from these options.
*
* @return array
* The list of allowed packages
*/
public function allowedPackages() {
return $this->options['allowed-packages'];
}
/**
* Gets the location mapping table, e.g. 'webroot' => './'.
*
* @return array
* A map of name : location values
*/
public function locations() {
return $this->options['locations'];
}
/**
* Determines whether a given named location is defined.
*
* @param string $name
* The location name to search for.
*
* @return bool
* True if the specified named location exist.
*/
protected function hasLocation($name) {
return array_key_exists($name, $this->locations());
}
/**
* Gets a specific named location.
*
* @param string $name
* The name of the location to fetch.
*
* @return string
* The value of the provided named location
*/
public function getLocation($name) {
return $this->hasLocation($name) ? $this->locations()[$name] : FALSE;
}
/**
* Determines if symlink mode is set.
*
* @return bool
* Whether or not 'symlink' mode
*/
public function symlink() {
return $this->options['symlink'];
}
/**
* Determines if there are file mappings.
*
* @return bool
* Whether or not the scaffold options contain any file mappings
*/
public function hasFileMapping() {
return !empty($this->fileMapping());
}
/**
* Returns the actual file mappings.
*
* @return array
* File mappings for just this config type.
*/
public function fileMapping() {
return $this->options['file-mapping'];
}
/**
* Determines if there is defined a value for the 'gitignore' option.
*
* @return bool
* Whether or not there is a 'gitignore' option setting
*/
public function hasGitIgnore() {
return isset($this->options['gitignore']);
}
/**
* Gets the value of the 'gitignore' option.
*
* @return bool
* The 'gitignore' option, or TRUE if undefined.
*/
public function gitIgnore() {
return $this->hasGitIgnore() ? $this->options['gitignore'] : TRUE;
}
}