Skip to content

Commit a0bf4ac

Browse files
committed
added support for the following tags in package.xml:
- <State> inside <Release> (package development state: 'alpha','beta','stable','snapshot') - <Changelog> stores <Release> entries - <Maintainers> stores multiple <Maintainer> entries - <Role> inside <Maintainer> ('lead','developer','contributor','helper')
1 parent 807b49a commit a0bf4ac

File tree

1 file changed

+101
-19
lines changed

1 file changed

+101
-19
lines changed

pear/PEAR/Common.php

Lines changed: 101 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// | license@php.net so we can mail you a copy immediately. |
1515
// +----------------------------------------------------------------------+
1616
// | Authors: Stig Bakken <ssb@fast.no> |
17+
// | Tomas V.V.Cox <cox@idecnet.com> |
1718
// | |
1819
// +----------------------------------------------------------------------+
1920
//
@@ -26,7 +27,7 @@
2627
* - check in inforFromDescFile that the minimal data needed is present
2728
* (pack name, version, files, others?)
2829
* - perhaps use parser folding to be less restrictive with the format
29-
of the package.xml file
30+
* of the package.xml file
3031
*/
3132
class PEAR_Common extends PEAR
3233
{
@@ -47,6 +48,16 @@ class PEAR_Common extends PEAR
4748
/** assoc with information about a package */
4849
var $pkginfo = array();
4950

51+
/**
52+
* Permitted maintainer roles
53+
* @var array
54+
*/
55+
var $maintainer_roles = array('lead','developer','contributor','helper');
56+
/**
57+
* Permitted release states
58+
* @var array
59+
*/
60+
var $releases_states = array('alpha','beta','stable','snapshot');
5061
// }}}
5162

5263
// {{{ constructor
@@ -119,6 +130,7 @@ function _element_start($xp, $name, $attribs)
119130
{
120131
array_push($this->element_stack, $name);
121132
$this->current_element = $name;
133+
$this->prev_element = $this->element_stack[sizeof($this->element_stack)-2];
122134
$this->current_attributes = $attribs;
123135
switch ($name) {
124136
case 'Dir':
@@ -139,6 +151,30 @@ function _element_start($xp, $name, $attribs)
139151
$this->lib_atts = $attribs;
140152
$this->lib_atts['Role'] = 'extension';
141153
break;
154+
case 'Maintainers':
155+
$this->pkginfo['maintainers'] = array();
156+
$this->m_i = 0; // maintainers array index
157+
break;
158+
case 'Maintainer':
159+
// compatibility check
160+
if (!isset($this->pkginfo['maintainers'])) {
161+
$this->pkginfo['maintainers'] = array();
162+
$this->m_i = 0;
163+
}
164+
$this->pkginfo['maintainers'][$this->m_i] = array();
165+
$this->current_maintainer =& $this->pkginfo['maintainers'][$this->m_i];
166+
break;
167+
case 'Changelog':
168+
$this->pkginfo['changelog'] = array();
169+
$this->c_i = 0; // changelog array index
170+
$this->in_changelog = true;
171+
break;
172+
case 'Release':
173+
if ($this->in_changelog) {
174+
$this->pkginfo['changelog'][$this->c_i] = array();
175+
$this->current_release =& $this->pkginfo['changelog'][$this->c_i];
176+
}
177+
break;
142178
}
143179
}
144180

@@ -190,6 +226,16 @@ function _element_end($xp, $name)
190226
unset($this->lib_atts);
191227
unset($this->lib_sources);
192228
break;
229+
case 'Maintainer':
230+
$this->m_i++;
231+
break;
232+
case 'Release':
233+
if ($this->in_changelog) {
234+
$this->c_i++;
235+
}
236+
break;
237+
case 'Changelog':
238+
$this->in_changelog = false;
193239
}
194240
array_pop($this->element_stack);
195241
$this->current_element = $this->element_stack[sizeof($this->element_stack)-1];
@@ -200,42 +246,64 @@ function _element_end($xp, $name)
200246

201247
function _pkginfo_cdata($xp, $data)
202248
{
203-
$prev = $this->element_stack[sizeof($this->element_stack)-2];
204249
switch ($this->current_element) {
205250
case 'Name':
206-
switch ($prev) {
251+
switch ($this->prev_element) {
207252
case 'Package':
208253
$this->pkginfo['package'] .= $data;
209254
break;
210255
case 'Maintainer':
211-
$this->pkginfo['maintainer_name'] .= $data;
256+
$this->current_maintainer['name'] .= $data;
212257
break;
213258
}
214259
break;
215260
case 'Summary':
216261
$this->pkginfo['summary'] .= $data;
217262
break;
218263
case 'Initials':
219-
$this->pkginfo['maintainer_handle'] .= $data;
264+
$this->current_maintainer['handle'] .= $data;
220265
break;
221266
case 'Email':
222-
$this->pkginfo['maintainer_email'] .= $data;
267+
$this->current_maintainer['email'] .= $data;
268+
break;
269+
case 'Role':
270+
if (!in_array($data, $this->maintainer_roles)) {
271+
trigger_error("The maintainer role: '$data' is not valid", E_USER_WARNING);
272+
} else {
273+
$this->current_maintainer['role'] .= $data;
274+
}
223275
break;
224276
case 'Version':
225-
$this->pkginfo['version'] .= $data;
277+
if ($this->in_changelog) {
278+
$this->current_release['version'] .= $data;
279+
} else {
280+
$this->pkginfo['version'] .= $data;
281+
}
226282
break;
227283
case 'Date':
228-
$this->pkginfo['release_date'] .= $data;
284+
if ($this->in_changelog) {
285+
$this->current_release['release_date'] .= $data;
286+
} else {
287+
$this->pkginfo['release_date'] .= $data;
288+
}
229289
break;
230290
case 'Notes':
231-
$this->pkginfo['release_notes'] .= $data;
291+
if ($this->in_changelog) {
292+
$this->current_release['release_notes'] .= $data;
293+
} else {
294+
$this->pkginfo['release_notes'] .= $data;
295+
}
232296
break;
233-
case 'Dir':
234-
if (!$this->phpdir) {
235-
break;
297+
case 'State':
298+
if (!in_array($data, $this->releases_states)) {
299+
trigger_error("The release state: '$data' is not valid", E_USER_WARNING);
300+
} elseif ($this->in_changelog) {
301+
$this->current_release['release_state'] = $data;
302+
} else {
303+
$this->pkginfo['release_state'] .= $data;
236304
}
237-
$dir = trim($data);
238-
// XXX add to file list
305+
break;
306+
case 'Dir':
239307
break;
240308
case 'File':
241309
$role = strtolower($this->current_attributes['Role']);
@@ -272,12 +340,14 @@ function infoFromDescriptionFile($descfile)
272340
$this->pkginfo = array();
273341
$this->current_element = false;
274342
$this->destdir = '';
275-
$this->filelist = array();
343+
$this->pkginfo['filelist'] = array();
344+
$this->filelist =& $this->pkginfo['filelist'];
345+
$this->in_changelog = false;
276346

277347
// read the whole thing so we only get one cdata callback
278348
// for each block of cdata
279349
$data = fread($fp, filesize($descfile));
280-
if (!@xml_parse($xp, $data, 1)) {
350+
if (!xml_parse($xp, $data, 1)) {
281351
$msg = sprintf("XML error: %s at line %d",
282352
xml_error_string(xml_get_error_code($xp)),
283353
xml_get_current_line_number($xp));
@@ -288,12 +358,24 @@ function infoFromDescriptionFile($descfile)
288358
xml_parser_free($xp);
289359

290360
foreach ($this->pkginfo as $k => $v) {
291-
$this->pkginfo[$k] = trim($v);
361+
if (!is_array($v)) {
362+
$this->pkginfo[$k] = trim($v);
363+
}
292364
}
293-
$this->pkginfo['filelist'] = &$this->filelist;
294365
return $this->pkginfo;
295366
}
296-
297367
// }}}
368+
369+
/**
370+
* Returns info from a tgz pear package
371+
* (experimental)
372+
*/
373+
function infoFromTgzFile($file)
374+
{
375+
// untar in temp
376+
// chdir($tmp);
377+
//return $this->infoFromDescriptionFile('package.xml');
378+
// clean temp
379+
}
298380
}
299381
?>

0 commit comments

Comments
 (0)