14
14
// | license@php.net so we can mail you a copy immediately. |
15
15
// +----------------------------------------------------------------------+
16
16
// | Authors: Stig Bakken <ssb@fast.no> |
17
+ // | Tomas V.V.Cox <cox@idecnet.com> |
17
18
// | |
18
19
// +----------------------------------------------------------------------+
19
20
//
26
27
* - check in inforFromDescFile that the minimal data needed is present
27
28
* (pack name, version, files, others?)
28
29
* - perhaps use parser folding to be less restrictive with the format
29
- of the package.xml file
30
+ * of the package.xml file
30
31
*/
31
32
class PEAR_Common extends PEAR
32
33
{
@@ -47,6 +48,16 @@ class PEAR_Common extends PEAR
47
48
/** assoc with information about a package */
48
49
var $ pkginfo = array ();
49
50
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 ' );
50
61
// }}}
51
62
52
63
// {{{ constructor
@@ -119,6 +130,7 @@ function _element_start($xp, $name, $attribs)
119
130
{
120
131
array_push ($ this ->element_stack , $ name );
121
132
$ this ->current_element = $ name ;
133
+ $ this ->prev_element = $ this ->element_stack [sizeof ($ this ->element_stack )-2 ];
122
134
$ this ->current_attributes = $ attribs ;
123
135
switch ($ name ) {
124
136
case 'Dir ' :
@@ -139,6 +151,30 @@ function _element_start($xp, $name, $attribs)
139
151
$ this ->lib_atts = $ attribs ;
140
152
$ this ->lib_atts ['Role ' ] = 'extension ' ;
141
153
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 ;
142
178
}
143
179
}
144
180
@@ -190,6 +226,16 @@ function _element_end($xp, $name)
190
226
unset($ this ->lib_atts );
191
227
unset($ this ->lib_sources );
192
228
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 ;
193
239
}
194
240
array_pop ($ this ->element_stack );
195
241
$ this ->current_element = $ this ->element_stack [sizeof ($ this ->element_stack )-1 ];
@@ -200,42 +246,64 @@ function _element_end($xp, $name)
200
246
201
247
function _pkginfo_cdata ($ xp , $ data )
202
248
{
203
- $ prev = $ this ->element_stack [sizeof ($ this ->element_stack )-2 ];
204
249
switch ($ this ->current_element ) {
205
250
case 'Name ' :
206
- switch ($ prev ) {
251
+ switch ($ this -> prev_element ) {
207
252
case 'Package ' :
208
253
$ this ->pkginfo ['package ' ] .= $ data ;
209
254
break ;
210
255
case 'Maintainer ' :
211
- $ this ->pkginfo [ ' maintainer_name ' ] .= $ data ;
256
+ $ this ->current_maintainer [ ' name ' ] .= $ data ;
212
257
break ;
213
258
}
214
259
break ;
215
260
case 'Summary ' :
216
261
$ this ->pkginfo ['summary ' ] .= $ data ;
217
262
break ;
218
263
case 'Initials ' :
219
- $ this ->pkginfo [ ' maintainer_handle ' ] .= $ data ;
264
+ $ this ->current_maintainer [ ' handle ' ] .= $ data ;
220
265
break ;
221
266
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
+ }
223
275
break ;
224
276
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
+ }
226
282
break ;
227
283
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
+ }
229
289
break ;
230
290
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
+ }
232
296
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 ;
236
304
}
237
- $ dir = trim ( $ data ) ;
238
- // XXX add to file list
305
+ break ;
306
+ case ' Dir ' :
239
307
break ;
240
308
case 'File ' :
241
309
$ role = strtolower ($ this ->current_attributes ['Role ' ]);
@@ -272,12 +340,14 @@ function infoFromDescriptionFile($descfile)
272
340
$ this ->pkginfo = array ();
273
341
$ this ->current_element = false ;
274
342
$ this ->destdir = '' ;
275
- $ this ->filelist = array ();
343
+ $ this ->pkginfo ['filelist ' ] = array ();
344
+ $ this ->filelist =& $ this ->pkginfo ['filelist ' ];
345
+ $ this ->in_changelog = false ;
276
346
277
347
// read the whole thing so we only get one cdata callback
278
348
// for each block of cdata
279
349
$ data = fread ($ fp , filesize ($ descfile ));
280
- if (!@ xml_parse ($ xp , $ data , 1 )) {
350
+ if (!xml_parse ($ xp , $ data , 1 )) {
281
351
$ msg = sprintf ("XML error: %s at line %d " ,
282
352
xml_error_string (xml_get_error_code ($ xp )),
283
353
xml_get_current_line_number ($ xp ));
@@ -288,12 +358,24 @@ function infoFromDescriptionFile($descfile)
288
358
xml_parser_free ($ xp );
289
359
290
360
foreach ($ this ->pkginfo as $ k => $ v ) {
291
- $ this ->pkginfo [$ k ] = trim ($ v );
361
+ if (!is_array ($ v )) {
362
+ $ this ->pkginfo [$ k ] = trim ($ v );
363
+ }
292
364
}
293
- $ this ->pkginfo ['filelist ' ] = &$ this ->filelist ;
294
365
return $ this ->pkginfo ;
295
366
}
296
-
297
367
// }}}
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
+ }
298
380
}
299
381
?>
0 commit comments