-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathIniFile.php
More file actions
68 lines (57 loc) · 1.69 KB
/
IniFile.php
File metadata and controls
68 lines (57 loc) · 1.69 KB
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
<?php
namespace DrupalCodeBuilder\Generator;
use DrupalCodeBuilder\File\CodeFile;
use Ckr\Util\ArrayMerger;
/**
* Generator for ini files used for pre-D8 info files.
*/
class IniFile extends File {
/**
* {@inheritdoc}
*/
public function getFileInfo(): CodeFile {
$ini_data = [];
foreach ($this->containedComponents['element'] as $key => $child_item) {
$child_item_data = $child_item->getContents();
// Use array merge as child items may provide numerically-keyed lists,
// which should not clobber each other.
$ini_data = ArrayMerger::doMerge($ini_data, $child_item_data);
}
$file_info = new CodeFile($this->processInfoLines($ini_data));
return $file_info;
}
/**
* Process a structured array of info files lines to a flat array for merging.
*
* @param $lines
* An array of lines keyed by label.
* Place grouped labels (eg, dependencies) into an array of
* their own, keyed numerically.
* Eg:
* name => module name
* dependencies => array(foo, bar)
*
* @return
* An array of lines for the .info file.
*/
function processInfoLines($lines) {
foreach ($lines as $label => $data) {
if (is_array($data)) {
foreach ($data as $data_piece) {
$merged_lines[] = $label . "[] = $data_piece"; // Urgh terrible variable name!
}
}
elseif ($data == '') {
// An empty data value means a blank line.
$merged_lines[] = '';
}
else {
$merged_lines[] = "$label = $data";
}
}
// Add final empty line so the file has a closing linebreak.
$merged_lines[] = '';
//drush_print_r($merged_lines);
return $merged_lines;
}
}