forked from dreamsxin/ext-async
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.php
More file actions
154 lines (120 loc) · 3.73 KB
/
package.php
File metadata and controls
154 lines (120 loc) · 3.73 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
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
<?php
// Helper script being used to sync package.xml file list.
define('NS', 'http://pear.php.net/dtd/package-2.0');
function get_role($file)
{
switch (strtolower(pathinfo($file, PATHINFO_EXTENSION))) {
case 'md':
return 'doc';
}
return 'src';
}
function collect_files($dir, array $include, $role = null)
{
$result = [];
foreach (glob($dir . '/*') as $entry) {
if (is_dir($entry)) {
$result = array_merge($result, collect_files($entry, $include, $role));
} elseif (in_array(strtolower(basename($entry)), $include)) {
$result[] = [
$entry,
$role ?? get_role($entry)
];
} elseif (in_array(strtolower(pathinfo($entry, PATHINFO_EXTENSION)), $include)) {
$result[] = [
$entry,
$role ?? get_role($entry)
];
}
}
return $result;
}
$file = __DIR__ . '/package.xml';
$dom = new \DOMDocument();
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$dom->load($file);
$xpath = new \DOMXPath($dom);
$xpath->registerNamespace('p', NS);
foreach ($xpath->query('/p:package/p:date') as $el) {
foreach ($el->childNodes as $child) {
$el->removeChild($child);
}
$el->appendChild($dom->createTextNode(gmdate('Y-m-d')));
}
foreach ($xpath->query('/p:package/p:time') as $el) {
foreach ($el->childNodes as $child) {
$el->removeChild($child);
}
$el->appendChild($dom->createTextNode(gmdate('H:i:s')));
}
foreach ($xpath->query('/p:package/p:contents') as $contents) {
foreach ($contents->childNodes as $child) {
$contents->removeChild($child);
}
$dir = $contents->appendChild($dom->createElementNS(NS, 'dir'));
$name = $dom->createAttribute('name');
$name->appendChild($dom->createTextNode('/'));
$dir->appendChild($name);
$files = [];
foreach (glob(__DIR__ . '/*') as $entry) {
$include = false;
switch (basename($entry)) {
case 'LICENSE':
case 'README.md':
$include = true;
$role = 'doc';
break;
case 'config.m4':
case 'config.w32':
case 'Makefile.frag':
case 'php_async.c':
case 'php_async.h':
$role = 'src';
$include = true;
break;
}
if (!$include) {
continue;
}
if (is_dir($entry)) {
continue;
}
$files[] = [
$entry,
$role
];
}
$files = array_merge($files, collect_files(__DIR__ . '/include', [
'h'
]));
$files = array_merge($files, collect_files(__DIR__ . '/src', [
'c'
]));
$files = array_merge($files, collect_files(__DIR__ . '/thirdparty/boost', [
'license',
's'
]));
$files = array_merge($files, collect_files(__DIR__ . '/thirdparty/libuv', [
'h',
'c',
'md',
'license'
]));
$files = array_merge($files, collect_files(__DIR__ . '/tests', [
'phpt',
'php',
'inc'
], 'test'));
foreach ($files as list ($entry, $role)) {
$fe = $dom->createElementNS(NS, 'file');
$dir->appendChild($fe);
$a = $dom->createAttribute('role');
$a->appendChild($dom->createTextNode($role));
$fe->appendChild($a);
$a = $dom->createAttribute('name');
$a->appendChild($dom->createTextNode(substr($entry, strlen(__DIR__) + 1)));
$fe->appendChild($a);
}
}
$dom->save($file);