/
package.php
188 lines (155 loc) · 5 KB
/
package.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
#!/usr/bin/env php
<?php
error_reporting(error_reporting() ^ E_DEPRECATED);
if (version_compare(PHP_VERSION, '5.3.2') >= 0) {
error_reporting(error_reporting() ^ E_DEPRECATED);
}
date_default_timezone_set('America/Chicago');
require_once 'PEAR/PackageFileManager2.php';
PEAR::setErrorHandling(PEAR_ERROR_DIE);
/**
* Recursively populated $GLOBALS['files']
*
* @param string $path The path to glob through.
*
* @return void
* @uses $GLOBALS['files']
*/
function readDirectory($path)
{
foreach (glob($path . '/*') as $file) {
if (!is_dir($file)) {
$GLOBALS['files'][] = $file;
} else {
readDirectory($file);
}
}
}
$outsideDir = realpath(dirname(dirname(__FILE__)));
$version = trim(file_get_contents($outsideDir . '/VERSION'));
$api_version = $version;
$api_state = 'beta';
$release_version = $version;
$release_state = 'beta';
$release_notes = "This is an alpha release, see readme.md for examples.";
$summary = "A PHP library for HAL generation";
$description =<<<EOF
HAL is a simple way of linking with JSON or XML.
It provides a set of conventions for expressing hyperlinks to, and embeddedness of, related resources - the rest of a HAL document is just plain old JSON or XML.
HAL is a bit like HTML for machines, in that it is designed to drive many different types of application. The difference is that HTML is intended for presenting a graphical hypertext interface to a 'human actor', whereas HAL is intended for presenting a machine hypertext interface to 'automated actors'.
This document contains a formalised specification of HAL. For a friendlier, more pracitcal introduction to HAL you can read this article: JSON Linking with HAL
HAL has two main components: Resources and Links.
- https://github.com/zircote/Hal
- http://groups.google.com/group/hal-discuss
- http://stateless.co/hal_specification.html
- http://blog.stateless.co/post/13296666138/json-linking-with-hal
- http://www.mnot.net/blog/2011/11/25/linking_in_json
- https://gist.github.com/2289546
EOF;
$package = new PEAR_PackageFileManager2();
$package->setOptions(
array(
'filelistgenerator' => 'file',
'outputdirectory' => dirname(dirname(__FILE__)),
'simpleoutput' => true,
'baseinstalldir' => '/',
'packagedirectory' => $outsideDir,
'dir_roles' => array(
'benchmarks' => 'doc',
'examples' => 'doc',
'library' => 'php',
'library/Hal' => 'php',
'tests' => 'test',
),
'exceptions' => array(
'CHANGELOG' => 'doc',
'readme.md' => 'doc',
'VERSION' => 'doc',
'LICENSE-2.0.txt' => 'doc',
),
'ignore' => array(
'build/*',
'package.xml',
'composer.json',
'build.xml',
'scripts/*',
'.git',
'.gitignore',
'tests/phpunit.xml',
'tests/build*',
'.project',
'.buildpath',
'.settings',
'*.tgz'
)
)
);
$package->setPackage('Hal');
$package->setSummary($summary);
$package->setDescription($description);
$package->setChannel('zircote.com/pear');
$package->setPackageType('php');
$package->setLicense(
'Apache 2.0',
'http://www.apache.org/licenses/LICENSE-2.0'
);
$package->setNotes($release_notes);
$package->setReleaseVersion($release_version);
$package->setReleaseStability($release_state);
$package->setAPIVersion($api_version);
$package->setAPIStability($api_state);
/**
* Dependencies
*/
$maintainers = array(
array(
'name' => 'Robert Allen',
'user' => 'zircote',
'email' => 'zircote@gmail.com',
'role' => 'lead',
)
);
foreach ($maintainers as $_m) {
$package->addMaintainer(
$_m['role'],
$_m['user'],
$_m['name'],
$_m['email']
);
}
$files = array(); // classes and tests
readDirectory($outsideDir . '/library');
readDirectory($outsideDir . '/tests');
$base = $outsideDir . '/';
foreach ($files as $file) {
$file = str_replace($base, '', $file);
$package->addReplacement(
$file,
'package-info',
'@name@',
'name'
);
$package->addReplacement(
$file,
'package-info',
'@package_version@',
'version'
);
}
$files = array(); // reset global
readDirectory($outsideDir . '/library');
foreach ($files as $file) {
$file = str_replace($base, '', $file);
$package->addInstallAs($file, str_replace('library/', '', $file));
}
$package->setPhpDep('5.3.3');
$package->setPearInstallerDep('1.7.0');
$package->generateContents();
$package->addRelease();
if ( isset($_GET['make'])
|| (isset($_SERVER['argv']) && @$_SERVER['argv'][1] == 'make')
) {
$package->writePackageFile();
} else {
$package->debugPackageFile();
}