Bearsampp 2026.9.23
Loading...
Searching...
No Matches
v1.php
Go to the documentation of this file.
1<?php
18require_once 'PEAR/Validate.php';
19require_once 'System.php';
20require_once 'PEAR/PackageFile/v2.php';
36{
41 function __construct(&$packagefile)
42 {
43 $this->_packagefile = &$packagefile;
44 }
45
47 {
48 return '1.10.18';
49 }
50
57 function toTgz(&$packager, $compress = true, $where = null)
58 {
59 require_once 'Archive/Tar.php';
60 if ($where === null) {
61 if (!($where = System::mktemp(array('-d')))) {
62 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: mktemp failed');
63 }
64 } elseif (!@System::mkDir(array('-p', $where))) {
65 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: "' . $where . '" could' .
66 ' not be created');
67 }
68 if (file_exists($where . DIRECTORY_SEPARATOR . 'package.xml') &&
69 !is_file($where . DIRECTORY_SEPARATOR . 'package.xml')) {
70 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: unable to save package.xml as' .
71 ' "' . $where . DIRECTORY_SEPARATOR . 'package.xml"');
72 }
73 if (!$this->_packagefile->validate(PEAR_VALIDATE_PACKAGING)) {
74 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: invalid package file');
75 }
76 $pkginfo = $this->_packagefile->getArray();
77 $ext = $compress ? '.tgz' : '.tar';
78 $pkgver = $pkginfo['package'] . '-' . $pkginfo['version'];
79 $dest_package = getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext;
80 if (file_exists(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext) &&
81 !is_file(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext)) {
82 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: cannot create tgz file "' .
83 getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext . '"');
84 }
85 if ($pkgfile = $this->_packagefile->getPackageFile()) {
86 $pkgdir = dirname(realpath($pkgfile));
87 $pkgfile = basename($pkgfile);
88 } else {
89 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: package file object must ' .
90 'be created from a real file');
91 }
92 // {{{ Create the package file list
93 $filelist = array();
94 $i = 0;
95
96 foreach ($this->_packagefile->getFilelist() as $fname => $atts) {
97 $file = $pkgdir . DIRECTORY_SEPARATOR . $fname;
98 if (!file_exists($file)) {
99 return PEAR::raiseError("File does not exist: $fname");
100 } else {
101 $filelist[$i++] = $file;
102 if (!isset($atts['md5sum'])) {
103 $this->_packagefile->setFileAttribute($fname, 'md5sum', md5_file($file));
104 }
105 $packager->log(2, "Adding file $fname");
106 }
107 }
108 // }}}
109 $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true);
110 if ($packagexml) {
111 $tar = new Archive_Tar($dest_package, $compress);
112 $tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
113 // ----- Creates with the package.xml file
114 $ok = $tar->createModify(array($packagexml), '', $where);
115 if (PEAR::isError($ok)) {
116 return $ok;
117 } elseif (!$ok) {
118 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: tarball creation failed');
119 }
120 // ----- Add the content of the package
121 if (!$tar->addModify($filelist, $pkgver, $pkgdir)) {
122 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: tarball creation failed');
123 }
124 return $dest_package;
125 }
126 }
127
135 function toPackageFile($where = null, $state = PEAR_VALIDATE_NORMAL, $name = 'package.xml',
136 $nofilechecking = false)
137 {
138 if (!$this->_packagefile->validate($state, $nofilechecking)) {
139 return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: invalid package.xml',
140 null, null, null, $this->_packagefile->getValidationWarnings());
141 }
142 if ($where === null) {
143 if (!($where = System::mktemp(array('-d')))) {
144 return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: mktemp failed');
145 }
146 } elseif (!@System::mkDir(array('-p', $where))) {
147 return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: "' . $where . '" could' .
148 ' not be created');
149 }
150 $newpkgfile = $where . DIRECTORY_SEPARATOR . $name;
151 $np = @fopen($newpkgfile, 'wb');
152 if (!$np) {
153 return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: unable to save ' .
154 "$name as $newpkgfile");
155 }
156 fwrite($np, $this->toXml($state, true));
157 fclose($np);
158 return $newpkgfile;
159 }
160
168 function _fixXmlEncoding($string)
169 {
170 return strtr($string, array(
171 '&' => '&amp;',
172 '>' => '&gt;',
173 '<' => '&lt;',
174 '"' => '&quot;',
175 '\'' => '&apos;' ));
176 }
177
184 function toXml($state = PEAR_VALIDATE_NORMAL, $nofilevalidation = false)
185 {
186 $this->_packagefile->setDate(date('Y-m-d'));
187 if (!$this->_packagefile->validate($state, $nofilevalidation)) {
188 return false;
189 }
190 $pkginfo = $this->_packagefile->getArray();
191 static $maint_map = array(
192 "handle" => "user",
193 "name" => "name",
194 "email" => "email",
195 "role" => "role",
196 );
197 $ret = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
198 $ret .= "<!DOCTYPE package SYSTEM \"http://pear.php.net/dtd/package-1.0\">\n";
199 $ret .= "<package version=\"1.0\" packagerversion=\"1.10.18\">\n" .
200" <name>$pkginfo[package]</name>";
201 if (isset($pkginfo['extends'])) {
202 $ret .= "\n<extends>$pkginfo[extends]</extends>";
203 }
204 $ret .=
205 "\n <summary>".$this->_fixXmlEncoding($pkginfo['summary'])."</summary>\n" .
206" <description>".trim($this->_fixXmlEncoding($pkginfo['description']))."\n </description>\n" .
207" <maintainers>\n";
208 foreach ($pkginfo['maintainers'] as $maint) {
209 $ret .= " <maintainer>\n";
210 foreach ($maint_map as $idx => $elm) {
211 $ret .= " <$elm>";
212 $ret .= $this->_fixXmlEncoding($maint[$idx]);
213 $ret .= "</$elm>\n";
214 }
215 $ret .= " </maintainer>\n";
216 }
217 $ret .= " </maintainers>\n";
218 $ret .= $this->_makeReleaseXml($pkginfo, false, $state);
219 if (isset($pkginfo['changelog']) && count($pkginfo['changelog']) > 0) {
220 $ret .= " <changelog>\n";
221 foreach ($pkginfo['changelog'] as $oldrelease) {
222 $ret .= $this->_makeReleaseXml($oldrelease, true);
223 }
224 $ret .= " </changelog>\n";
225 }
226 $ret .= "</package>\n";
227 return $ret;
228 }
229
230 // }}}
231 // {{{ _makeReleaseXml()
232
243 function _makeReleaseXml($pkginfo, $changelog = false, $state = PEAR_VALIDATE_NORMAL)
244 {
245 // XXX QUOTE ENTITIES IN PCDATA, OR EMBED IN CDATA BLOCKS!!
246 $indent = $changelog ? " " : "";
247 $ret = "$indent <release>\n";
248 if (!empty($pkginfo['version'])) {
249 $ret .= "$indent <version>$pkginfo[version]</version>\n";
250 }
251 if (!empty($pkginfo['release_date'])) {
252 $ret .= "$indent <date>$pkginfo[release_date]</date>\n";
253 }
254 if (!empty($pkginfo['release_license'])) {
255 $ret .= "$indent <license>$pkginfo[release_license]</license>\n";
256 }
257 if (!empty($pkginfo['release_state'])) {
258 $ret .= "$indent <state>$pkginfo[release_state]</state>\n";
259 }
260 if (!empty($pkginfo['release_notes'])) {
261 $ret .= "$indent <notes>".trim($this->_fixXmlEncoding($pkginfo['release_notes']))
262 ."\n$indent </notes>\n";
263 }
264 if (!empty($pkginfo['release_warnings'])) {
265 $ret .= "$indent <warnings>".$this->_fixXmlEncoding($pkginfo['release_warnings'])."</warnings>\n";
266 }
267 if (isset($pkginfo['release_deps']) && sizeof($pkginfo['release_deps']) > 0) {
268 $ret .= "$indent <deps>\n";
269 foreach ($pkginfo['release_deps'] as $dep) {
270 $ret .= "$indent <dep type=\"$dep[type]\" rel=\"$dep[rel]\"";
271 if (isset($dep['version'])) {
272 $ret .= " version=\"$dep[version]\"";
273 }
274 if (isset($dep['optional'])) {
275 $ret .= " optional=\"$dep[optional]\"";
276 }
277 if (isset($dep['name'])) {
278 $ret .= ">$dep[name]</dep>\n";
279 } else {
280 $ret .= "/>\n";
281 }
282 }
283 $ret .= "$indent </deps>\n";
284 }
285 if (isset($pkginfo['configure_options'])) {
286 $ret .= "$indent <configureoptions>\n";
287 foreach ($pkginfo['configure_options'] as $c) {
288 $ret .= "$indent <configureoption name=\"".
289 $this->_fixXmlEncoding($c['name']) . "\"";
290 if (isset($c['default'])) {
291 $ret .= " default=\"" . $this->_fixXmlEncoding($c['default']) . "\"";
292 }
293 $ret .= " prompt=\"" . $this->_fixXmlEncoding($c['prompt']) . "\"";
294 $ret .= "/>\n";
295 }
296 $ret .= "$indent </configureoptions>\n";
297 }
298 if (isset($pkginfo['provides'])) {
299 foreach ($pkginfo['provides'] as $key => $what) {
300 $ret .= "$indent <provides type=\"$what[type]\" ";
301 $ret .= "name=\"$what[name]\" ";
302 if (isset($what['extends'])) {
303 $ret .= "extends=\"$what[extends]\" ";
304 }
305 $ret .= "/>\n";
306 }
307 }
308 if (isset($pkginfo['filelist'])) {
309 $ret .= "$indent <filelist>\n";
310 if ($state ^ PEAR_VALIDATE_PACKAGING) {
311 $ret .= $this->recursiveXmlFilelist($pkginfo['filelist']);
312 } else {
313 foreach ($pkginfo['filelist'] as $file => $fa) {
314 if (!isset($fa['role'])) {
315 $fa['role'] = '';
316 }
317 $ret .= "$indent <file role=\"$fa[role]\"";
318 if (isset($fa['baseinstalldir'])) {
319 $ret .= ' baseinstalldir="' .
320 $this->_fixXmlEncoding($fa['baseinstalldir']) . '"';
321 }
322 if (isset($fa['md5sum'])) {
323 $ret .= " md5sum=\"$fa[md5sum]\"";
324 }
325 if (isset($fa['platform'])) {
326 $ret .= " platform=\"$fa[platform]\"";
327 }
328 if (!empty($fa['install-as'])) {
329 $ret .= ' install-as="' .
330 $this->_fixXmlEncoding($fa['install-as']) . '"';
331 }
332 $ret .= ' name="' . $this->_fixXmlEncoding($file) . '"';
333 if (empty($fa['replacements'])) {
334 $ret .= "/>\n";
335 } else {
336 $ret .= ">\n";
337 foreach ($fa['replacements'] as $r) {
338 $ret .= "$indent <replace";
339 foreach ($r as $k => $v) {
340 $ret .= " $k=\"" . $this->_fixXmlEncoding($v) .'"';
341 }
342 $ret .= "/>\n";
343 }
344 $ret .= "$indent </file>\n";
345 }
346 }
347 }
348 $ret .= "$indent </filelist>\n";
349 }
350 $ret .= "$indent </release>\n";
351 return $ret;
352 }
353
358 function recursiveXmlFilelist($list)
359 {
360 $this->_dirs = array();
361 foreach ($list as $file => $attributes) {
362 $this->_addDir($this->_dirs, explode('/', dirname($file)), $file, $attributes);
363 }
364 return $this->_formatDir($this->_dirs);
365 }
366
374 function _addDir(&$dirs, $dir, $file = null, $attributes = null)
375 {
376 if ($dir == array() || $dir == array('.')) {
377 $dirs['files'][basename($file)] = $attributes;
378 return;
379 }
380 $curdir = array_shift($dir);
381 if (!isset($dirs['dirs'][$curdir])) {
382 $dirs['dirs'][$curdir] = array();
383 }
384 $this->_addDir($dirs['dirs'][$curdir], $dir, $file, $attributes);
385 }
386
393 function _formatDir($dirs, $indent = '', $curdir = '')
394 {
395 $ret = '';
396 if (!count($dirs)) {
397 return '';
398 }
399 if (isset($dirs['dirs'])) {
400 uksort($dirs['dirs'], 'strnatcasecmp');
401 foreach ($dirs['dirs'] as $dir => $contents) {
402 $usedir = "$curdir/$dir";
403 $ret .= "$indent <dir name=\"$dir\">\n";
404 $ret .= $this->_formatDir($contents, "$indent ", $usedir);
405 $ret .= "$indent </dir> <!-- $usedir -->\n";
406 }
407 }
408 if (isset($dirs['files'])) {
409 uksort($dirs['files'], 'strnatcasecmp');
410 foreach ($dirs['files'] as $file => $attribs) {
411 $ret .= $this->_formatFile($file, $attribs, $indent);
412 }
413 }
414 return $ret;
415 }
416
423 function _formatFile($file, $attributes, $indent)
424 {
425 $ret = "$indent <file role=\"$attributes[role]\"";
426 if (isset($attributes['baseinstalldir'])) {
427 $ret .= ' baseinstalldir="' .
428 $this->_fixXmlEncoding($attributes['baseinstalldir']) . '"';
429 }
430 if (isset($attributes['md5sum'])) {
431 $ret .= " md5sum=\"$attributes[md5sum]\"";
432 }
433 if (isset($attributes['platform'])) {
434 $ret .= " platform=\"$attributes[platform]\"";
435 }
436 if (!empty($attributes['install-as'])) {
437 $ret .= ' install-as="' .
438 $this->_fixXmlEncoding($attributes['install-as']) . '"';
439 }
440 $ret .= ' name="' . $this->_fixXmlEncoding($file) . '"';
441 if (empty($attributes['replacements'])) {
442 $ret .= "/>\n";
443 } else {
444 $ret .= ">\n";
445 foreach ($attributes['replacements'] as $r) {
446 $ret .= "$indent <replace";
447 foreach ($r as $k => $v) {
448 $ret .= " $k=\"" . $this->_fixXmlEncoding($v) .'"';
449 }
450 $ret .= "/>\n";
451 }
452 $ret .= "$indent </file>\n";
453 }
454 return $ret;
455 }
456
457 // {{{ _unIndent()
458
466 function _unIndent($str)
467 {
468 // remove leading newlines
469 $str = preg_replace('/^[\r\n]+/', '', $str);
470 // find whitespace at the beginning of the first line
471 $indent_len = strspn($str, " \t");
472 $indent = substr($str, 0, $indent_len);
473 $data = '';
474 // remove the same amount of whitespace from following lines
475 foreach (explode("\n", $str) as $line) {
476 if (substr($line, 0, $indent_len) == $indent) {
477 $data .= substr($line, $indent_len) . "\n";
478 }
479 }
480 return $data;
481 }
482
487 {
488 $arr = array();
489 $this->_convertDependencies2_0($arr);
490 return $arr['dependencies'];
491 }
492
504 function &toV2($class = 'PEAR_PackageFile_v2', $strict = false)
505 {
506 if ($strict) {
507 if (!$this->_packagefile->validate()) {
508 $a = PEAR::raiseError('invalid package.xml version 1.0 cannot be converted' .
509 ' to version 2.0', null, null, null,
510 $this->_packagefile->getValidationWarnings(true));
511 return $a;
512 }
513 }
514
515 $arr = array(
516 'attribs' => array(
517 'version' => '2.0',
518 'xmlns' => 'http://pear.php.net/dtd/package-2.0',
519 'xmlns:tasks' => 'http://pear.php.net/dtd/tasks-1.0',
520 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
521 'xsi:schemaLocation' => "http://pear.php.net/dtd/tasks-1.0\n" .
522"http://pear.php.net/dtd/tasks-1.0.xsd\n" .
523"http://pear.php.net/dtd/package-2.0\n" .
524'http://pear.php.net/dtd/package-2.0.xsd',
525 ),
526 'name' => $this->_packagefile->getPackage(),
527 'channel' => 'pear.php.net',
528 );
529 $arr['summary'] = $this->_packagefile->getSummary();
530 $arr['description'] = $this->_packagefile->getDescription();
531 $maintainers = $this->_packagefile->getMaintainers();
532 foreach ($maintainers as $maintainer) {
533 if ($maintainer['role'] != 'lead') {
534 continue;
535 }
536 $new = array(
537 'name' => $maintainer['name'],
538 'user' => $maintainer['handle'],
539 'email' => $maintainer['email'],
540 'active' => 'yes',
541 );
542 $arr['lead'][] = $new;
543 }
544
545 if (!isset($arr['lead'])) { // some people... you know?
546 $arr['lead'] = array(
547 'name' => 'unknown',
548 'user' => 'unknown',
549 'email' => 'noleadmaintainer@example.com',
550 'active' => 'no',
551 );
552 }
553
554 if (count($arr['lead']) == 1) {
555 $arr['lead'] = $arr['lead'][0];
556 }
557
558 foreach ($maintainers as $maintainer) {
559 if ($maintainer['role'] == 'lead') {
560 continue;
561 }
562 $new = array(
563 'name' => $maintainer['name'],
564 'user' => $maintainer['handle'],
565 'email' => $maintainer['email'],
566 'active' => 'yes',
567 );
568 $arr[$maintainer['role']][] = $new;
569 }
570
571 if (isset($arr['developer']) && count($arr['developer']) == 1) {
572 $arr['developer'] = $arr['developer'][0];
573 }
574
575 if (isset($arr['contributor']) && count($arr['contributor']) == 1) {
576 $arr['contributor'] = $arr['contributor'][0];
577 }
578
579 if (isset($arr['helper']) && count($arr['helper']) == 1) {
580 $arr['helper'] = $arr['helper'][0];
581 }
582
583 $arr['date'] = $this->_packagefile->getDate();
584 $arr['version'] =
585 array(
586 'release' => $this->_packagefile->getVersion(),
587 'api' => $this->_packagefile->getVersion(),
588 );
589 $arr['stability'] =
590 array(
591 'release' => $this->_packagefile->getState(),
592 'api' => $this->_packagefile->getState(),
593 );
594 $licensemap =
595 array(
596 'php' => 'http://www.php.net/license',
597 'php license' => 'http://www.php.net/license',
598 'lgpl' => 'http://www.gnu.org/copyleft/lesser.html',
599 'bsd' => 'http://www.opensource.org/licenses/bsd-license.php',
600 'bsd style' => 'http://www.opensource.org/licenses/bsd-license.php',
601 'bsd-style' => 'http://www.opensource.org/licenses/bsd-license.php',
602 'mit' => 'http://www.opensource.org/licenses/mit-license.php',
603 'gpl' => 'http://www.gnu.org/copyleft/gpl.html',
604 'apache' => 'http://www.opensource.org/licenses/apache2.0.php'
605 );
606
607 if (isset($licensemap[strtolower($this->_packagefile->getLicense())])) {
608 $arr['license'] = array(
609 'attribs' => array('uri' =>
610 $licensemap[strtolower($this->_packagefile->getLicense())]),
611 '_content' => $this->_packagefile->getLicense()
612 );
613 } else {
614 // don't use bogus uri
615 $arr['license'] = $this->_packagefile->getLicense();
616 }
617
618 $arr['notes'] = $this->_packagefile->getNotes();
619 $temp = array();
620 $arr['contents'] = $this->_convertFilelist2_0($temp);
621 $this->_convertDependencies2_0($arr);
622 $release = ($this->_packagefile->getConfigureOptions() || $this->_isExtension) ?
623 'extsrcrelease' : 'phprelease';
624 if ($release == 'extsrcrelease') {
625 $arr['channel'] = 'pecl.php.net';
626 $arr['providesextension'] = $arr['name']; // assumption
627 }
628
629 $arr[$release] = array();
630 if ($this->_packagefile->getConfigureOptions()) {
631 $arr[$release]['configureoption'] = $this->_packagefile->getConfigureOptions();
632 foreach ($arr[$release]['configureoption'] as $i => $opt) {
633 $arr[$release]['configureoption'][$i] = array('attribs' => $opt);
634 }
635 if (count($arr[$release]['configureoption']) == 1) {
636 $arr[$release]['configureoption'] = $arr[$release]['configureoption'][0];
637 }
638 }
639
640 $this->_convertRelease2_0($arr[$release], $temp);
641 if ($release == 'extsrcrelease' && count($arr[$release]) > 1) {
642 // multiple extsrcrelease tags added in PEAR 1.4.1
643 $arr['dependencies']['required']['pearinstaller']['min'] = '1.4.1';
644 }
645
646 if ($cl = $this->_packagefile->getChangelog()) {
647 foreach ($cl as $release) {
648 $rel = array();
649 $rel['version'] =
650 array(
651 'release' => $release['version'],
652 'api' => $release['version'],
653 );
654 if (!isset($release['release_state'])) {
655 $release['release_state'] = 'stable';
656 }
657
658 $rel['stability'] =
659 array(
660 'release' => $release['release_state'],
661 'api' => $release['release_state'],
662 );
663 if (isset($release['release_date'])) {
664 $rel['date'] = $release['release_date'];
665 } else {
666 $rel['date'] = date('Y-m-d');
667 }
668
669 if (isset($release['release_license'])) {
670 if (isset($licensemap[strtolower($release['release_license'])])) {
671 $uri = $licensemap[strtolower($release['release_license'])];
672 } else {
673 $uri = 'http://www.example.com';
674 }
675 $rel['license'] = array(
676 'attribs' => array('uri' => $uri),
677 '_content' => $release['release_license']
678 );
679 } else {
680 $rel['license'] = $arr['license'];
681 }
682
683 if (!isset($release['release_notes'])) {
684 $release['release_notes'] = 'no release notes';
685 }
686
687 $rel['notes'] = $release['release_notes'];
688 $arr['changelog']['release'][] = $rel;
689 }
690 }
691
692 $ret = new $class;
693 $ret->setConfig($this->_packagefile->_config);
694 if (isset($this->_packagefile->_logger) && is_object($this->_packagefile->_logger)) {
695 $ret->setLogger($this->_packagefile->_logger);
696 }
697
698 $ret->fromArray($arr);
699 return $ret;
700 }
701
707 function _convertDependencies2_0(&$release, $internal = false)
708 {
709 $peardep = array('pearinstaller' =>
710 array('min' => '1.4.0b1')); // this is a lot safer
711 $required = $optional = array();
712 $release['dependencies'] = array('required' => array());
713 if ($this->_packagefile->hasDeps()) {
714 foreach ($this->_packagefile->getDeps() as $dep) {
715 if (!isset($dep['optional']) || $dep['optional'] == 'no') {
716 $required[] = $dep;
717 } else {
718 $optional[] = $dep;
719 }
720 }
721 foreach (array('required', 'optional') as $arr) {
722 $deps = array();
723 foreach ($$arr as $dep) {
724 // organize deps by dependency type and name
725 if (!isset($deps[$dep['type']])) {
726 $deps[$dep['type']] = array();
727 }
728 if (isset($dep['name'])) {
729 $deps[$dep['type']][$dep['name']][] = $dep;
730 } else {
731 $deps[$dep['type']][] = $dep;
732 }
733 }
734 do {
735 if (isset($deps['php'])) {
736 $php = array();
737 if (count($deps['php']) > 1) {
738 $php = $this->_processPhpDeps($deps['php']);
739 } else {
740 if (!isset($deps['php'][0])) {
741 // Buggy versions
742 $key = key($deps['php']);
743 $info = current($deps['php']);
744 $deps['php'] = array($info[0]);
745 }
746 $php = $this->_processDep($deps['php'][0]);
747 if (!$php) {
748 break; // poor mans throw
749 }
750 }
751 $release['dependencies'][$arr]['php'] = $php;
752 }
753 } while (false);
754 do {
755 if (isset($deps['pkg'])) {
756 $pkg = array();
757 $pkg = $this->_processMultipleDepsName($deps['pkg']);
758 if (!$pkg) {
759 break; // poor mans throw
760 }
761 $release['dependencies'][$arr]['package'] = $pkg;
762 }
763 } while (false);
764 do {
765 if (isset($deps['ext'])) {
766 $pkg = array();
767 $pkg = $this->_processMultipleDepsName($deps['ext']);
768 $release['dependencies'][$arr]['extension'] = $pkg;
769 }
770 } while (false);
771 // skip sapi - it's not supported so nobody will have used it
772 // skip os - it's not supported in 1.0
773 }
774 }
775 if (isset($release['dependencies']['required'])) {
776 $release['dependencies']['required'] =
777 array_merge($peardep, $release['dependencies']['required']);
778 } else {
779 $release['dependencies']['required'] = $peardep;
780 }
781 if (!isset($release['dependencies']['required']['php'])) {
782 $release['dependencies']['required']['php'] =
783 array('min' => '4.0.0');
784 }
785 $order = array();
786 $bewm = $release['dependencies']['required'];
787 $order['php'] = $bewm['php'];
788 $order['pearinstaller'] = $bewm['pearinstaller'];
789 isset($bewm['package']) ? $order['package'] = $bewm['package'] :0;
790 isset($bewm['extension']) ? $order['extension'] = $bewm['extension'] :0;
791 $release['dependencies']['required'] = $order;
792 }
793
798 function _convertFilelist2_0(&$package)
799 {
800 $ret = array('dir' =>
801 array(
802 'attribs' => array('name' => '/'),
803 'file' => array()
804 )
805 );
806 $package['platform'] =
807 $package['install-as'] = array();
808 $this->_isExtension = false;
809 foreach ($this->_packagefile->getFilelist() as $name => $file) {
810 $file['name'] = $name;
811 if (isset($file['role']) && $file['role'] == 'src') {
812 $this->_isExtension = true;
813 }
814 if (isset($file['replacements'])) {
815 $repl = $file['replacements'];
816 unset($file['replacements']);
817 } else {
818 unset($repl);
819 }
820 if (isset($file['install-as'])) {
821 $package['install-as'][$name] = $file['install-as'];
822 unset($file['install-as']);
823 }
824 if (isset($file['platform'])) {
825 $package['platform'][$name] = $file['platform'];
826 unset($file['platform']);
827 }
828 $file = array('attribs' => $file);
829 if (isset($repl)) {
830 foreach ($repl as $replace ) {
831 $file['tasks:replace'][] = array('attribs' => $replace);
832 }
833 if (count($repl) == 1) {
834 $file['tasks:replace'] = $file['tasks:replace'][0];
835 }
836 }
837 $ret['dir']['file'][] = $file;
838 }
839 return $ret;
840 }
841
878 function _convertRelease2_0(&$release, $package)
879 {
880 //- if any install-as/platform exist, create a generic release and fill it with
881 if (count($package['platform']) || count($package['install-as'])) {
882 $generic = array();
883 $genericIgnore = array();
884 foreach ($package['install-as'] as $file => $as) {
885 //o <install as=..> tags for <file name=... install-as=...>
886 if (!isset($package['platform'][$file])) {
887 $generic[] = $file;
888 continue;
889 }
890 //o <install as=..> tags for <file name=... platform=!... install-as=..>
891 if (isset($package['platform'][$file]) &&
892 $package['platform'][$file][0] == '!') {
893 $generic[] = $file;
894 continue;
895 }
896 //o <ignore> tags for <file name=... platform=... install-as=..>
897 if (isset($package['platform'][$file]) &&
898 $package['platform'][$file][0] != '!') {
899 $genericIgnore[] = $file;
900 continue;
901 }
902 }
903 foreach ($package['platform'] as $file => $platform) {
904 if (isset($package['install-as'][$file])) {
905 continue;
906 }
907 if ($platform[0] != '!') {
908 //o <ignore> tags for <file name=... platform=...>
909 $genericIgnore[] = $file;
910 }
911 }
912 if (count($package['platform'])) {
913 $oses = $notplatform = $platform = array();
914 foreach ($package['platform'] as $file => $os) {
915 // get a list of oses
916 if ($os[0] == '!') {
917 if (isset($oses[substr($os, 1)])) {
918 continue;
919 }
920 $oses[substr($os, 1)] = count($oses);
921 } else {
922 if (isset($oses[$os])) {
923 continue;
924 }
925 $oses[$os] = count($oses);
926 }
927 }
928 //- create a release for each platform encountered and fill with
929 foreach ($oses as $os => $releaseNum) {
930 $release[$releaseNum]['installconditions']['os']['name'] = $os;
931 $release[$releaseNum]['filelist'] = array('install' => array(),
932 'ignore' => array());
933 foreach ($package['install-as'] as $file => $as) {
934 //o <install as=..> tags for <file name=... install-as=...>
935 if (!isset($package['platform'][$file])) {
936 $release[$releaseNum]['filelist']['install'][] =
937 array(
938 'attribs' => array(
939 'name' => $file,
940 'as' => $as,
941 ),
942 );
943 continue;
944 }
945 //o <install as..> tags for
946 // <file name=... platform=this platform install-as=..>
947 if (isset($package['platform'][$file]) &&
948 $package['platform'][$file] == $os) {
949 $release[$releaseNum]['filelist']['install'][] =
950 array(
951 'attribs' => array(
952 'name' => $file,
953 'as' => $as,
954 ),
955 );
956 continue;
957 }
958 //o <install as..> tags for
959 // <file name=... platform=!other platform install-as=..>
960 if (isset($package['platform'][$file]) &&
961 $package['platform'][$file] != "!$os" &&
962 $package['platform'][$file][0] == '!') {
963 $release[$releaseNum]['filelist']['install'][] =
964 array(
965 'attribs' => array(
966 'name' => $file,
967 'as' => $as,
968 ),
969 );
970 continue;
971 }
972 //o <ignore> tags for
973 // <file name=... platform=!this platform install-as=..>
974 if (isset($package['platform'][$file]) &&
975 $package['platform'][$file] == "!$os") {
976 $release[$releaseNum]['filelist']['ignore'][] =
977 array(
978 'attribs' => array(
979 'name' => $file,
980 ),
981 );
982 continue;
983 }
984 //o <ignore> tags for
985 // <file name=... platform=other platform install-as=..>
986 if (isset($package['platform'][$file]) &&
987 $package['platform'][$file][0] != '!' &&
988 $package['platform'][$file] != $os) {
989 $release[$releaseNum]['filelist']['ignore'][] =
990 array(
991 'attribs' => array(
992 'name' => $file,
993 ),
994 );
995 continue;
996 }
997 }
998 foreach ($package['platform'] as $file => $platform) {
999 if (isset($package['install-as'][$file])) {
1000 continue;
1001 }
1002 //o <ignore> tags for <file name=... platform=!this platform>
1003 if ($platform == "!$os") {
1004 $release[$releaseNum]['filelist']['ignore'][] =
1005 array(
1006 'attribs' => array(
1007 'name' => $file,
1008 ),
1009 );
1010 continue;
1011 }
1012 //o <ignore> tags for <file name=... platform=other platform>
1013 if ($platform[0] != '!' && $platform != $os) {
1014 $release[$releaseNum]['filelist']['ignore'][] =
1015 array(
1016 'attribs' => array(
1017 'name' => $file,
1018 ),
1019 );
1020 }
1021 }
1022 if (!count($release[$releaseNum]['filelist']['install'])) {
1023 unset($release[$releaseNum]['filelist']['install']);
1024 }
1025 if (!count($release[$releaseNum]['filelist']['ignore'])) {
1026 unset($release[$releaseNum]['filelist']['ignore']);
1027 }
1028 }
1029 if (count($generic) || count($genericIgnore)) {
1030 $release[count($oses)] = array();
1031 if (count($generic)) {
1032 foreach ($generic as $file) {
1033 if (isset($package['install-as'][$file])) {
1034 $installas = $package['install-as'][$file];
1035 } else {
1036 $installas = $file;
1037 }
1038 $release[count($oses)]['filelist']['install'][] =
1039 array(
1040 'attribs' => array(
1041 'name' => $file,
1042 'as' => $installas,
1043 )
1044 );
1045 }
1046 }
1047 if (count($genericIgnore)) {
1048 foreach ($genericIgnore as $file) {
1049 $release[count($oses)]['filelist']['ignore'][] =
1050 array(
1051 'attribs' => array(
1052 'name' => $file,
1053 )
1054 );
1055 }
1056 }
1057 }
1058 // cleanup
1059 foreach ($release as $i => $rel) {
1060 if (isset($rel['filelist']['install']) &&
1061 count($rel['filelist']['install']) == 1) {
1062 $release[$i]['filelist']['install'] =
1063 $release[$i]['filelist']['install'][0];
1064 }
1065 if (isset($rel['filelist']['ignore']) &&
1066 count($rel['filelist']['ignore']) == 1) {
1067 $release[$i]['filelist']['ignore'] =
1068 $release[$i]['filelist']['ignore'][0];
1069 }
1070 }
1071 if (count($release) == 1) {
1072 $release = $release[0];
1073 }
1074 } else {
1075 // no platform atts, but some install-as atts
1076 foreach ($package['install-as'] as $file => $value) {
1077 $release['filelist']['install'][] =
1078 array(
1079 'attribs' => array(
1080 'name' => $file,
1081 'as' => $value
1082 )
1083 );
1084 }
1085 if (count($release['filelist']['install']) == 1) {
1086 $release['filelist']['install'] = $release['filelist']['install'][0];
1087 }
1088 }
1089 }
1090 }
1091
1097 function _processDep($dep)
1098 {
1099 if ($dep['type'] == 'php') {
1100 if ($dep['rel'] == 'has') {
1101 // come on - everyone has php!
1102 return false;
1103 }
1104 }
1105 $php = array();
1106 if ($dep['type'] != 'php') {
1107 $php['name'] = $dep['name'];
1108 if ($dep['type'] == 'pkg') {
1109 $php['channel'] = 'pear.php.net';
1110 }
1111 }
1112 switch ($dep['rel']) {
1113 case 'gt' :
1114 $php['min'] = $dep['version'];
1115 $php['exclude'] = $dep['version'];
1116 break;
1117 case 'ge' :
1118 if (!isset($dep['version'])) {
1119 if ($dep['type'] == 'php') {
1120 if (isset($dep['name'])) {
1121 $dep['version'] = $dep['name'];
1122 }
1123 }
1124 }
1125 $php['min'] = $dep['version'];
1126 break;
1127 case 'lt' :
1128 $php['max'] = $dep['version'];
1129 $php['exclude'] = $dep['version'];
1130 break;
1131 case 'le' :
1132 $php['max'] = $dep['version'];
1133 break;
1134 case 'eq' :
1135 $php['min'] = $dep['version'];
1136 $php['max'] = $dep['version'];
1137 break;
1138 case 'ne' :
1139 $php['exclude'] = $dep['version'];
1140 break;
1141 case 'not' :
1142 $php['conflicts'] = 'yes';
1143 break;
1144 }
1145 return $php;
1146 }
1147
1152 function _processPhpDeps($deps)
1153 {
1154 $test = array();
1155 foreach ($deps as $dep) {
1156 $test[] = $this->_processDep($dep);
1157 }
1158 $min = array();
1159 $max = array();
1160 foreach ($test as $dep) {
1161 if (!$dep) {
1162 continue;
1163 }
1164 if (isset($dep['min'])) {
1165 $min[$dep['min']] = count($min);
1166 }
1167 if (isset($dep['max'])) {
1168 $max[$dep['max']] = count($max);
1169 }
1170 }
1171 if (count($min) > 0) {
1172 uksort($min, 'version_compare');
1173 }
1174 if (count($max) > 0) {
1175 uksort($max, 'version_compare');
1176 }
1177 if (count($min)) {
1178 // get the highest minimum
1179 $a = array_flip($min);
1180 $min = array_pop($a);
1181 } else {
1182 $min = false;
1183 }
1184 if (count($max)) {
1185 // get the lowest maximum
1186 $a = array_flip($max);
1187 $max = array_shift($a);
1188 } else {
1189 $max = false;
1190 }
1191 if ($min) {
1192 $php['min'] = $min;
1193 }
1194 if ($max) {
1195 $php['max'] = $max;
1196 }
1197 $exclude = array();
1198 foreach ($test as $dep) {
1199 if (!isset($dep['exclude'])) {
1200 continue;
1201 }
1202 $exclude[] = $dep['exclude'];
1203 }
1204 if (count($exclude)) {
1205 $php['exclude'] = $exclude;
1206 }
1207 return $php;
1208 }
1209
1217 {
1218 $ret = $tests = array();
1219 foreach ($deps as $name => $dep) {
1220 foreach ($dep as $d) {
1221 $tests[$name][] = $this->_processDep($d);
1222 }
1223 }
1224
1225 foreach ($tests as $name => $test) {
1226 $max = $min = $php = array();
1227 $php['name'] = $name;
1228 foreach ($test as $dep) {
1229 if (!$dep) {
1230 continue;
1231 }
1232 if (isset($dep['channel'])) {
1233 $php['channel'] = 'pear.php.net';
1234 }
1235 if (isset($dep['conflicts']) && $dep['conflicts'] == 'yes') {
1236 $php['conflicts'] = 'yes';
1237 }
1238 if (isset($dep['min'])) {
1239 $min[$dep['min']] = count($min);
1240 }
1241 if (isset($dep['max'])) {
1242 $max[$dep['max']] = count($max);
1243 }
1244 }
1245 if (count($min) > 0) {
1246 uksort($min, 'version_compare');
1247 }
1248 if (count($max) > 0) {
1249 uksort($max, 'version_compare');
1250 }
1251 if (count($min)) {
1252 // get the highest minimum
1253 $a = array_flip($min);
1254 $min = array_pop($a);
1255 } else {
1256 $min = false;
1257 }
1258 if (count($max)) {
1259 // get the lowest maximum
1260 $a = array_flip($max);
1261 $max = array_shift($a);
1262 } else {
1263 $max = false;
1264 }
1265 if ($min) {
1266 $php['min'] = $min;
1267 }
1268 if ($max) {
1269 $php['max'] = $max;
1270 }
1271 $exclude = array();
1272 foreach ($test as $dep) {
1273 if (!isset($dep['exclude'])) {
1274 continue;
1275 }
1276 $exclude[] = $dep['exclude'];
1277 }
1278 if (count($exclude)) {
1279 $php['exclude'] = $exclude;
1280 }
1281 $ret[] = $php;
1282 }
1283 return $ret;
1284 }
1285}
1286?>
const PEAR_ERROR_RETURN
Definition PEAR.php:24
const PEAR_VALIDATE_PACKAGING
Definition Validate.php:22
const PEAR_VALIDATE_NORMAL
Definition Validate.php:20
toTgz(&$packager, $compress=true, $where=null)
Definition v1.php:57
_formatDir($dirs, $indent='', $curdir='')
Definition v1.php:393
_formatFile($file, $attributes, $indent)
Definition v1.php:423
__construct(&$packagefile)
Definition v1.php:41
toPackageFile($where=null, $state=PEAR_VALIDATE_NORMAL, $name='package.xml', $nofilechecking=false)
Definition v1.php:135
& toV2($class='PEAR_PackageFile_v2', $strict=false)
Definition v1.php:504
_convertRelease2_0(&$release, $package)
Definition v1.php:878
_convertDependencies2_0(&$release, $internal=false)
Definition v1.php:707
_convertFilelist2_0(&$package)
Definition v1.php:798
_makeReleaseXml($pkginfo, $changelog=false, $state=PEAR_VALIDATE_NORMAL)
Definition v1.php:243
toXml($state=PEAR_VALIDATE_NORMAL, $nofilevalidation=false)
Definition v1.php:184
_addDir(&$dirs, $dir, $file=null, $attributes=null)
Definition v1.php:374