-
Notifications
You must be signed in to change notification settings - Fork 9
/
packagexmlsetup.php
170 lines (157 loc) · 5.38 KB
/
packagexmlsetup.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
<?php
/**
* packagexmlsetup.php for PEAR2_Autoload
*
* PHP version 5
*
* @category PEAR2
* @package PEAR2_Autoload
* @author Gregory Beaver <[email protected]>
* @author Brett Bieber <[email protected]>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version GIT: $Id$
* @link http://pear2.php.net/PEAR2_Autoload
*/
/**
* References the package in $package and/or $compatible.
*/
use Pyrus\Developer\PackageFile\v2;
/**
* Configuration array.
*
* Each key is the task.
*
* The task "replace" uses an array where the key is the value to be searched
* for, and the value is an array of additional attributes for the task, which
* normally contain at least "type" (pear-config/package-info) and "to", which
* specifies the value to replace it with.
*
* The task "eol" uses an array where the key is a filename pattern to be
* matched, and the value is the target platform's EOL to be used for those
* file names (windows/unix).
*
* Unrecognized tasks are ignored.
*
* @var array
*/
$config = array(
'replace' => array(
'../src' => array(
'type' => 'pear-config',
'to' => 'php_dir'
),
'@PACKAGE_VERSION@' => array(
'type' => 'package-info',
'to' => 'version'
),
'GIT: $Id$' => array(
'type' => 'package-info',
'to' => 'version'
)
),
'eol' => array()
);
if (!isset($package)) {
die('This file must be executed via "pyrus.phar make".');
}
$packageGen = function (
array $config,
v2 $package,
v2 $compatible = null
) {
$tasksNs = $package->getTasksNs();
$cTasksNs = $compatible ? $compatible->getTasksNs() : '';
$oldCwd = getcwd();
chdir(__DIR__);
$package->setRawRelease('php', '');
$release = $package->getReleaseToInstall('php');
foreach (new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
'.',
RecursiveDirectoryIterator::UNIX_PATHS
| RecursiveDirectoryIterator::SKIP_DOTS
),
RecursiveIteratorIterator::LEAVES_ONLY
) as $path) {
$filename = substr($path->getPathname(), 2);
$cFilename = str_replace('src/', 'php/', $filename);
if (isset($package->files[$filename])) {
$parsedFilename = pathinfo($filename);
$as = (strpos($filename, 'examples/') === 0)
? $filename
: substr($filename, strpos($filename, '/') + 1);
if (strpos($filename, 'scripts/') === 0) {
if (isset($parsedFilename['extension'])
&& 'php' === $parsedFilename['extension']
&& !is_file(
$parsedFilename['dirname'] . '/' .
$parsedFilename['filename']
)
&& is_file(
$parsedFilename['dirname'] . '/' .
$parsedFilename['filename'] . '.bat'
)
) {
$as = substr($as, 0, -4);
}
}
$release->installAs($filename, $as);
$contents = file_get_contents($filename);
foreach ($config['replace'] as $from => $attribs) {
if (strpos($contents, $from) !== false) {
$attribs['from'] = $from;
$package->files[$filename] = array_merge_recursive(
$package->files[$filename]->getArrayCopy(),
array(
"{$tasksNs}:replace" => array(
array(
'attribs' => $attribs
)
)
)
);
if ($compatible) {
$compatible->files[$cFilename] = array_merge_recursive(
$compatible->files[$cFilename]->getArrayCopy(),
array(
"{$cTasksNs}:replace" => array(
array(
'attribs' => $attribs
)
)
)
);
}
}
}
foreach ($config['eol'] as $pattern => $platform) {
if (fnmatch($pattern, $filename)) {
$package->files[$filename] = array_merge_recursive(
$package->files[$filename]->getArrayCopy(),
array(
"{$tasksNs}:{$platform}eol" => array()
)
);
if ($compatible) {
$compatible->files[$cFilename] = array_merge_recursive(
$compatible->files[$cFilename]->getArrayCopy(),
array(
"{$cTasksNs}:{$platform}eol" => array()
)
);
}
}
}
}
}
chdir($oldCwd);
return array($package, $compatible);
};
list($package, $compatible) = $packageGen(
$config,
$package,
isset($compatible) ? $compatible : null
);
if (null === $compatible) {
unset($compatible);
}