3 * package.xml generation class, package.xml version 1.0
9 * @author Greg Beaver <cellog@php.net>
10 * @copyright 1997-2009 The Authors
11 * @license http://opensource.org/licenses/bsd-license.php New BSD License
12 * @version CVS: $Id: v1.php 313023 2011-07-06 19:17:11Z dufuz $
13 * @link http://pear.php.net/package/PEAR
14 * @since File available since Release 1.4.0a1
17 * needed for PEAR_VALIDATE_* constants
19 require_once 'PEAR/Validate.php';
20 require_once 'System.php';
21 require_once 'PEAR/PackageFile/v2.php';
23 * This class converts a PEAR_PackageFile_v1 object into any output format.
25 * Supported output formats include array, XML string, and a PEAR_PackageFile_v2
26 * object, for converting package.xml 1.0 into package.xml 2.0 with no sweat.
29 * @author Greg Beaver <cellog@php.net>
30 * @copyright 1997-2009 The Authors
31 * @license http://opensource.org/licenses/bsd-license.php New BSD License
32 * @version Release: 1.9.4
33 * @link http://pear.php.net/package/PEAR
34 * @since Class available since Release 1.4.0a1
36 class PEAR_PackageFile_Generator_v1
39 * @var PEAR_PackageFile_v1
42 function PEAR_PackageFile_Generator_v1(&$packagefile)
44 $this->_packagefile = &$packagefile;
47 function getPackagerVersion()
53 * @param PEAR_Packager
54 * @param bool if true, a .tgz is written, otherwise a .tar is written
55 * @param string|null directory in which to save the .tgz
56 * @return string|PEAR_Error location of package or error object
58 function toTgz(&$packager, $compress = true, $where = null)
60 require_once 'Archive/Tar.php';
61 if ($where === null) {
62 if (!($where = System::mktemp(array('-d')))) {
63 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: mktemp failed');
65 } elseif (!@System::mkDir(array('-p', $where))) {
66 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: "' . $where . '" could' .
69 if (file_exists($where . DIRECTORY_SEPARATOR . 'package.xml') &&
70 !is_file($where . DIRECTORY_SEPARATOR . 'package.xml')) {
71 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: unable to save package.xml as' .
72 ' "' . $where . DIRECTORY_SEPARATOR . 'package.xml"');
74 if (!$this->_packagefile->validate(PEAR_VALIDATE_PACKAGING)) {
75 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: invalid package file');
77 $pkginfo = $this->_packagefile->getArray();
78 $ext = $compress ? '.tgz' : '.tar';
79 $pkgver = $pkginfo['package'] . '-' . $pkginfo['version'];
80 $dest_package = getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext;
81 if (file_exists(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext) &&
82 !is_file(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext)) {
83 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: cannot create tgz file "' .
84 getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext . '"');
86 if ($pkgfile = $this->_packagefile->getPackageFile()) {
87 $pkgdir = dirname(realpath($pkgfile));
88 $pkgfile = basename($pkgfile);
90 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: package file object must ' .
91 'be created from a real file');
93 // {{{ Create the package file list
97 foreach ($this->_packagefile->getFilelist() as $fname => $atts) {
98 $file = $pkgdir . DIRECTORY_SEPARATOR . $fname;
99 if (!file_exists($file)) {
100 return PEAR::raiseError("File does not exist: $fname");
102 $filelist[$i++] = $file;
103 if (!isset($atts['md5sum'])) {
104 $this->_packagefile->setFileAttribute($fname, 'md5sum', md5_file($file));
106 $packager->log(2, "Adding file $fname");
110 $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true);
112 $tar =& new Archive_Tar($dest_package, $compress);
113 $tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
114 // ----- Creates with the package.xml file
115 $ok = $tar->createModify(array($packagexml), '', $where);
116 if (PEAR::isError($ok)) {
119 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: tarball creation failed');
121 // ----- Add the content of the package
122 if (!$tar->addModify($filelist, $pkgver, $pkgdir)) {
123 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: tarball creation failed');
125 return $dest_package;
130 * @param string|null directory to place the package.xml in, or null for a temporary dir
131 * @param int one of the PEAR_VALIDATE_* constants
132 * @param string name of the generated file
133 * @param bool if true, then no analysis will be performed on role="php" files
134 * @return string|PEAR_Error path to the created file on success
136 function toPackageFile($where = null, $state = PEAR_VALIDATE_NORMAL, $name = 'package.xml',
137 $nofilechecking = false)
139 if (!$this->_packagefile->validate($state, $nofilechecking)) {
140 return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: invalid package.xml',
141 null, null, null, $this->_packagefile->getValidationWarnings());
143 if ($where === null) {
144 if (!($where = System::mktemp(array('-d')))) {
145 return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: mktemp failed');
147 } elseif (!@System::mkDir(array('-p', $where))) {
148 return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: "' . $where . '" could' .
151 $newpkgfile = $where . DIRECTORY_SEPARATOR . $name;
152 $np = @fopen($newpkgfile, 'wb');
154 return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: unable to save ' .
155 "$name as $newpkgfile");
157 fwrite($np, $this->toXml($state, true));
163 * fix both XML encoding to be UTF8, and replace standard XML entities < > " & '
165 * @param string $string
169 function _fixXmlEncoding($string)
171 if (version_compare(phpversion(), '5.0.0', 'lt')) {
172 $string = utf8_encode($string);
174 return strtr($string, array(
183 * Return an XML document based on the package info (as returned
184 * by the PEAR_Common::infoFrom* methods).
186 * @return string XML data
188 function toXml($state = PEAR_VALIDATE_NORMAL, $nofilevalidation = false)
190 $this->_packagefile->setDate(date('Y-m-d'));
191 if (!$this->_packagefile->validate($state, $nofilevalidation)) {
194 $pkginfo = $this->_packagefile->getArray();
195 static $maint_map = array(
201 $ret = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
202 $ret .= "<!DOCTYPE package SYSTEM \"http://pear.php.net/dtd/package-1.0\">\n";
203 $ret .= "<package version=\"1.0\" packagerversion=\"1.9.4\">\n" .
204 " <name>$pkginfo[package]</name>";
205 if (isset($pkginfo['extends'])) {
206 $ret .= "\n<extends>$pkginfo[extends]</extends>";
209 "\n <summary>".$this->_fixXmlEncoding($pkginfo['summary'])."</summary>\n" .
210 " <description>".trim($this->_fixXmlEncoding($pkginfo['description']))."\n </description>\n" .
212 foreach ($pkginfo['maintainers'] as $maint) {
213 $ret .= " <maintainer>\n";
214 foreach ($maint_map as $idx => $elm) {
216 $ret .= $this->_fixXmlEncoding($maint[$idx]);
219 $ret .= " </maintainer>\n";
221 $ret .= " </maintainers>\n";
222 $ret .= $this->_makeReleaseXml($pkginfo, false, $state);
223 if (isset($pkginfo['changelog']) && count($pkginfo['changelog']) > 0) {
224 $ret .= " <changelog>\n";
225 foreach ($pkginfo['changelog'] as $oldrelease) {
226 $ret .= $this->_makeReleaseXml($oldrelease, true);
228 $ret .= " </changelog>\n";
230 $ret .= "</package>\n";
235 // {{{ _makeReleaseXml()
238 * Generate part of an XML description with release information.
240 * @param array $pkginfo array with release information
241 * @param bool $changelog whether the result will be in a changelog element
243 * @return string XML data
247 function _makeReleaseXml($pkginfo, $changelog = false, $state = PEAR_VALIDATE_NORMAL)
249 // XXX QUOTE ENTITIES IN PCDATA, OR EMBED IN CDATA BLOCKS!!
250 $indent = $changelog ? " " : "";
251 $ret = "$indent <release>\n";
252 if (!empty($pkginfo['version'])) {
253 $ret .= "$indent <version>$pkginfo[version]</version>\n";
255 if (!empty($pkginfo['release_date'])) {
256 $ret .= "$indent <date>$pkginfo[release_date]</date>\n";
258 if (!empty($pkginfo['release_license'])) {
259 $ret .= "$indent <license>$pkginfo[release_license]</license>\n";
261 if (!empty($pkginfo['release_state'])) {
262 $ret .= "$indent <state>$pkginfo[release_state]</state>\n";
264 if (!empty($pkginfo['release_notes'])) {
265 $ret .= "$indent <notes>".trim($this->_fixXmlEncoding($pkginfo['release_notes']))
266 ."\n$indent </notes>\n";
268 if (!empty($pkginfo['release_warnings'])) {
269 $ret .= "$indent <warnings>".$this->_fixXmlEncoding($pkginfo['release_warnings'])."</warnings>\n";
271 if (isset($pkginfo['release_deps']) && sizeof($pkginfo['release_deps']) > 0) {
272 $ret .= "$indent <deps>\n";
273 foreach ($pkginfo['release_deps'] as $dep) {
274 $ret .= "$indent <dep type=\"$dep[type]\" rel=\"$dep[rel]\"";
275 if (isset($dep['version'])) {
276 $ret .= " version=\"$dep[version]\"";
278 if (isset($dep['optional'])) {
279 $ret .= " optional=\"$dep[optional]\"";
281 if (isset($dep['name'])) {
282 $ret .= ">$dep[name]</dep>\n";
287 $ret .= "$indent </deps>\n";
289 if (isset($pkginfo['configure_options'])) {
290 $ret .= "$indent <configureoptions>\n";
291 foreach ($pkginfo['configure_options'] as $c) {
292 $ret .= "$indent <configureoption name=\"".
293 $this->_fixXmlEncoding($c['name']) . "\"";
294 if (isset($c['default'])) {
295 $ret .= " default=\"" . $this->_fixXmlEncoding($c['default']) . "\"";
297 $ret .= " prompt=\"" . $this->_fixXmlEncoding($c['prompt']) . "\"";
300 $ret .= "$indent </configureoptions>\n";
302 if (isset($pkginfo['provides'])) {
303 foreach ($pkginfo['provides'] as $key => $what) {
304 $ret .= "$indent <provides type=\"$what[type]\" ";
305 $ret .= "name=\"$what[name]\" ";
306 if (isset($what['extends'])) {
307 $ret .= "extends=\"$what[extends]\" ";
312 if (isset($pkginfo['filelist'])) {
313 $ret .= "$indent <filelist>\n";
314 if ($state ^ PEAR_VALIDATE_PACKAGING) {
315 $ret .= $this->recursiveXmlFilelist($pkginfo['filelist']);
317 foreach ($pkginfo['filelist'] as $file => $fa) {
318 if (!isset($fa['role'])) {
321 $ret .= "$indent <file role=\"$fa[role]\"";
322 if (isset($fa['baseinstalldir'])) {
323 $ret .= ' baseinstalldir="' .
324 $this->_fixXmlEncoding($fa['baseinstalldir']) . '"';
326 if (isset($fa['md5sum'])) {
327 $ret .= " md5sum=\"$fa[md5sum]\"";
329 if (isset($fa['platform'])) {
330 $ret .= " platform=\"$fa[platform]\"";
332 if (!empty($fa['install-as'])) {
333 $ret .= ' install-as="' .
334 $this->_fixXmlEncoding($fa['install-as']) . '"';
336 $ret .= ' name="' . $this->_fixXmlEncoding($file) . '"';
337 if (empty($fa['replacements'])) {
341 foreach ($fa['replacements'] as $r) {
342 $ret .= "$indent <replace";
343 foreach ($r as $k => $v) {
344 $ret .= " $k=\"" . $this->_fixXmlEncoding($v) .'"';
348 $ret .= "$indent </file>\n";
352 $ret .= "$indent </filelist>\n";
354 $ret .= "$indent </release>\n";
362 function recursiveXmlFilelist($list)
364 $this->_dirs = array();
365 foreach ($list as $file => $attributes) {
366 $this->_addDir($this->_dirs, explode('/', dirname($file)), $file, $attributes);
368 return $this->_formatDir($this->_dirs);
378 function _addDir(&$dirs, $dir, $file = null, $attributes = null)
380 if ($dir == array() || $dir == array('.')) {
381 $dirs['files'][basename($file)] = $attributes;
384 $curdir = array_shift($dir);
385 if (!isset($dirs['dirs'][$curdir])) {
386 $dirs['dirs'][$curdir] = array();
388 $this->_addDir($dirs['dirs'][$curdir], $dir, $file, $attributes);
397 function _formatDir($dirs, $indent = '', $curdir = '')
403 if (isset($dirs['dirs'])) {
404 uksort($dirs['dirs'], 'strnatcasecmp');
405 foreach ($dirs['dirs'] as $dir => $contents) {
406 $usedir = "$curdir/$dir";
407 $ret .= "$indent <dir name=\"$dir\">\n";
408 $ret .= $this->_formatDir($contents, "$indent ", $usedir);
409 $ret .= "$indent </dir> <!-- $usedir -->\n";
412 if (isset($dirs['files'])) {
413 uksort($dirs['files'], 'strnatcasecmp');
414 foreach ($dirs['files'] as $file => $attribs) {
415 $ret .= $this->_formatFile($file, $attribs, $indent);
427 function _formatFile($file, $attributes, $indent)
429 $ret = "$indent <file role=\"$attributes[role]\"";
430 if (isset($attributes['baseinstalldir'])) {
431 $ret .= ' baseinstalldir="' .
432 $this->_fixXmlEncoding($attributes['baseinstalldir']) . '"';
434 if (isset($attributes['md5sum'])) {
435 $ret .= " md5sum=\"$attributes[md5sum]\"";
437 if (isset($attributes['platform'])) {
438 $ret .= " platform=\"$attributes[platform]\"";
440 if (!empty($attributes['install-as'])) {
441 $ret .= ' install-as="' .
442 $this->_fixXmlEncoding($attributes['install-as']) . '"';
444 $ret .= ' name="' . $this->_fixXmlEncoding($file) . '"';
445 if (empty($attributes['replacements'])) {
449 foreach ($attributes['replacements'] as $r) {
450 $ret .= "$indent <replace";
451 foreach ($r as $k => $v) {
452 $ret .= " $k=\"" . $this->_fixXmlEncoding($v) .'"';
456 $ret .= "$indent </file>\n";
464 * Unindent given string (?)
466 * @param string $str The string that has to be unindented.
470 function _unIndent($str)
472 // remove leading newlines
473 $str = preg_replace('/^[\r\n]+/', '', $str);
474 // find whitespace at the beginning of the first line
475 $indent_len = strspn($str, " \t");
476 $indent = substr($str, 0, $indent_len);
478 // remove the same amount of whitespace from following lines
479 foreach (explode("\n", $str) as $line) {
480 if (substr($line, 0, $indent_len) == $indent) {
481 $data .= substr($line, $indent_len) . "\n";
490 function dependenciesToV2()
493 $this->_convertDependencies2_0($arr);
494 return $arr['dependencies'];
498 * Convert a package.xml version 1.0 into version 2.0
500 * Note that this does a basic conversion, to allow more advanced
501 * features like bundles and multiple releases
502 * @param string the classname to instantiate and return. This must be
503 * PEAR_PackageFile_v2 or a descendant
504 * @param boolean if true, only valid, deterministic package.xml 1.0 as defined by the
505 * strictest parameters will be converted
506 * @return PEAR_PackageFile_v2|PEAR_Error
508 function &toV2($class = 'PEAR_PackageFile_v2', $strict = false)
511 if (!$this->_packagefile->validate()) {
512 $a = PEAR::raiseError('invalid package.xml version 1.0 cannot be converted' .
513 ' to version 2.0', null, null, null,
514 $this->_packagefile->getValidationWarnings(true));
522 'xmlns' => 'http://pear.php.net/dtd/package-2.0',
523 'xmlns:tasks' => 'http://pear.php.net/dtd/tasks-1.0',
524 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
525 'xsi:schemaLocation' => "http://pear.php.net/dtd/tasks-1.0\n" .
526 "http://pear.php.net/dtd/tasks-1.0.xsd\n" .
527 "http://pear.php.net/dtd/package-2.0\n" .
528 'http://pear.php.net/dtd/package-2.0.xsd',
530 'name' => $this->_packagefile->getPackage(),
531 'channel' => 'pear.php.net',
533 $arr['summary'] = $this->_packagefile->getSummary();
534 $arr['description'] = $this->_packagefile->getDescription();
535 $maintainers = $this->_packagefile->getMaintainers();
536 foreach ($maintainers as $maintainer) {
537 if ($maintainer['role'] != 'lead') {
541 'name' => $maintainer['name'],
542 'user' => $maintainer['handle'],
543 'email' => $maintainer['email'],
546 $arr['lead'][] = $new;
549 if (!isset($arr['lead'])) { // some people... you know?
550 $arr['lead'] = array(
553 'email' => 'noleadmaintainer@example.com',
558 if (count($arr['lead']) == 1) {
559 $arr['lead'] = $arr['lead'][0];
562 foreach ($maintainers as $maintainer) {
563 if ($maintainer['role'] == 'lead') {
567 'name' => $maintainer['name'],
568 'user' => $maintainer['handle'],
569 'email' => $maintainer['email'],
572 $arr[$maintainer['role']][] = $new;
575 if (isset($arr['developer']) && count($arr['developer']) == 1) {
576 $arr['developer'] = $arr['developer'][0];
579 if (isset($arr['contributor']) && count($arr['contributor']) == 1) {
580 $arr['contributor'] = $arr['contributor'][0];
583 if (isset($arr['helper']) && count($arr['helper']) == 1) {
584 $arr['helper'] = $arr['helper'][0];
587 $arr['date'] = $this->_packagefile->getDate();
590 'release' => $this->_packagefile->getVersion(),
591 'api' => $this->_packagefile->getVersion(),
595 'release' => $this->_packagefile->getState(),
596 'api' => $this->_packagefile->getState(),
600 'php' => 'http://www.php.net/license',
601 'php license' => 'http://www.php.net/license',
602 'lgpl' => 'http://www.gnu.org/copyleft/lesser.html',
603 'bsd' => 'http://www.opensource.org/licenses/bsd-license.php',
604 'bsd style' => 'http://www.opensource.org/licenses/bsd-license.php',
605 'bsd-style' => 'http://www.opensource.org/licenses/bsd-license.php',
606 'mit' => 'http://www.opensource.org/licenses/mit-license.php',
607 'gpl' => 'http://www.gnu.org/copyleft/gpl.html',
608 'apache' => 'http://www.opensource.org/licenses/apache2.0.php'
611 if (isset($licensemap[strtolower($this->_packagefile->getLicense())])) {
612 $arr['license'] = array(
613 'attribs' => array('uri' =>
614 $licensemap[strtolower($this->_packagefile->getLicense())]),
615 '_content' => $this->_packagefile->getLicense()
618 // don't use bogus uri
619 $arr['license'] = $this->_packagefile->getLicense();
622 $arr['notes'] = $this->_packagefile->getNotes();
624 $arr['contents'] = $this->_convertFilelist2_0($temp);
625 $this->_convertDependencies2_0($arr);
626 $release = ($this->_packagefile->getConfigureOptions() || $this->_isExtension) ?
627 'extsrcrelease' : 'phprelease';
628 if ($release == 'extsrcrelease') {
629 $arr['channel'] = 'pecl.php.net';
630 $arr['providesextension'] = $arr['name']; // assumption
633 $arr[$release] = array();
634 if ($this->_packagefile->getConfigureOptions()) {
635 $arr[$release]['configureoption'] = $this->_packagefile->getConfigureOptions();
636 foreach ($arr[$release]['configureoption'] as $i => $opt) {
637 $arr[$release]['configureoption'][$i] = array('attribs' => $opt);
639 if (count($arr[$release]['configureoption']) == 1) {
640 $arr[$release]['configureoption'] = $arr[$release]['configureoption'][0];
644 $this->_convertRelease2_0($arr[$release], $temp);
645 if ($release == 'extsrcrelease' && count($arr[$release]) > 1) {
646 // multiple extsrcrelease tags added in PEAR 1.4.1
647 $arr['dependencies']['required']['pearinstaller']['min'] = '1.4.1';
650 if ($cl = $this->_packagefile->getChangelog()) {
651 foreach ($cl as $release) {
655 'release' => $release['version'],
656 'api' => $release['version'],
658 if (!isset($release['release_state'])) {
659 $release['release_state'] = 'stable';
664 'release' => $release['release_state'],
665 'api' => $release['release_state'],
667 if (isset($release['release_date'])) {
668 $rel['date'] = $release['release_date'];
670 $rel['date'] = date('Y-m-d');
673 if (isset($release['release_license'])) {
674 if (isset($licensemap[strtolower($release['release_license'])])) {
675 $uri = $licensemap[strtolower($release['release_license'])];
677 $uri = 'http://www.example.com';
679 $rel['license'] = array(
680 'attribs' => array('uri' => $uri),
681 '_content' => $release['release_license']
684 $rel['license'] = $arr['license'];
687 if (!isset($release['release_notes'])) {
688 $release['release_notes'] = 'no release notes';
691 $rel['notes'] = $release['release_notes'];
692 $arr['changelog']['release'][] = $rel;
697 $ret->setConfig($this->_packagefile->_config);
698 if (isset($this->_packagefile->_logger) && is_object($this->_packagefile->_logger)) {
699 $ret->setLogger($this->_packagefile->_logger);
702 $ret->fromArray($arr);
711 function _convertDependencies2_0(&$release, $internal = false)
713 $peardep = array('pearinstaller' =>
714 array('min' => '1.4.0b1')); // this is a lot safer
715 $required = $optional = array();
716 $release['dependencies'] = array('required' => array());
717 if ($this->_packagefile->hasDeps()) {
718 foreach ($this->_packagefile->getDeps() as $dep) {
719 if (!isset($dep['optional']) || $dep['optional'] == 'no') {
725 foreach (array('required', 'optional') as $arr) {
727 foreach ($$arr as $dep) {
728 // organize deps by dependency type and name
729 if (!isset($deps[$dep['type']])) {
730 $deps[$dep['type']] = array();
732 if (isset($dep['name'])) {
733 $deps[$dep['type']][$dep['name']][] = $dep;
735 $deps[$dep['type']][] = $dep;
739 if (isset($deps['php'])) {
741 if (count($deps['php']) > 1) {
742 $php = $this->_processPhpDeps($deps['php']);
744 if (!isset($deps['php'][0])) {
745 list($key, $blah) = each ($deps['php']); // stupid buggy versions
746 $deps['php'] = array($blah[0]);
748 $php = $this->_processDep($deps['php'][0]);
750 break; // poor mans throw
753 $release['dependencies'][$arr]['php'] = $php;
757 if (isset($deps['pkg'])) {
759 $pkg = $this->_processMultipleDepsName($deps['pkg']);
761 break; // poor mans throw
763 $release['dependencies'][$arr]['package'] = $pkg;
767 if (isset($deps['ext'])) {
769 $pkg = $this->_processMultipleDepsName($deps['ext']);
770 $release['dependencies'][$arr]['extension'] = $pkg;
773 // skip sapi - it's not supported so nobody will have used it
774 // skip os - it's not supported in 1.0
777 if (isset($release['dependencies']['required'])) {
778 $release['dependencies']['required'] =
779 array_merge($peardep, $release['dependencies']['required']);
781 $release['dependencies']['required'] = $peardep;
783 if (!isset($release['dependencies']['required']['php'])) {
784 $release['dependencies']['required']['php'] =
785 array('min' => '4.0.0');
788 $bewm = $release['dependencies']['required'];
789 $order['php'] = $bewm['php'];
790 $order['pearinstaller'] = $bewm['pearinstaller'];
791 isset($bewm['package']) ? $order['package'] = $bewm['package'] :0;
792 isset($bewm['extension']) ? $order['extension'] = $bewm['extension'] :0;
793 $release['dependencies']['required'] = $order;
800 function _convertFilelist2_0(&$package)
802 $ret = array('dir' =>
804 'attribs' => array('name' => '/'),
808 $package['platform'] =
809 $package['install-as'] = array();
810 $this->_isExtension = false;
811 foreach ($this->_packagefile->getFilelist() as $name => $file) {
812 $file['name'] = $name;
813 if (isset($file['role']) && $file['role'] == 'src') {
814 $this->_isExtension = true;
816 if (isset($file['replacements'])) {
817 $repl = $file['replacements'];
818 unset($file['replacements']);
822 if (isset($file['install-as'])) {
823 $package['install-as'][$name] = $file['install-as'];
824 unset($file['install-as']);
826 if (isset($file['platform'])) {
827 $package['platform'][$name] = $file['platform'];
828 unset($file['platform']);
830 $file = array('attribs' => $file);
832 foreach ($repl as $replace ) {
833 $file['tasks:replace'][] = array('attribs' => $replace);
835 if (count($repl) == 1) {
836 $file['tasks:replace'] = $file['tasks:replace'][0];
839 $ret['dir']['file'][] = $file;
845 * Post-process special files with install-as/platform attributes and
846 * make the release tag.
848 * This complex method follows this work-flow to create the release tags:
851 * - if any install-as/platform exist, create a generic release and fill it with
852 * o <install as=..> tags for <file name=... install-as=...>
853 * o <install as=..> tags for <file name=... platform=!... install-as=..>
854 * o <ignore> tags for <file name=... platform=...>
855 * o <ignore> tags for <file name=... platform=... install-as=..>
856 * - create a release for each platform encountered and fill with
857 * o <install as..> tags for <file name=... install-as=...>
858 * o <install as..> tags for <file name=... platform=this platform install-as=..>
859 * o <install as..> tags for <file name=... platform=!other platform install-as=..>
860 * o <ignore> tags for <file name=... platform=!this platform>
861 * o <ignore> tags for <file name=... platform=other platform>
862 * o <ignore> tags for <file name=... platform=other platform install-as=..>
863 * o <ignore> tags for <file name=... platform=!this platform install-as=..>
866 * It does this by accessing the $package parameter, which contains an array with
869 * - platform: mapping of file => OS the file should be installed on
870 * - install-as: mapping of file => installed name
871 * - osmap: mapping of OS => list of files that should be installed
873 * - notosmap: mapping of OS => list of files that should not be
874 * installed on that OS
880 function _convertRelease2_0(&$release, $package)
882 //- if any install-as/platform exist, create a generic release and fill it with
883 if (count($package['platform']) || count($package['install-as'])) {
885 $genericIgnore = array();
886 foreach ($package['install-as'] as $file => $as) {
887 //o <install as=..> tags for <file name=... install-as=...>
888 if (!isset($package['platform'][$file])) {
892 //o <install as=..> tags for <file name=... platform=!... install-as=..>
893 if (isset($package['platform'][$file]) &&
894 $package['platform'][$file]{0} == '!') {
898 //o <ignore> tags for <file name=... platform=... install-as=..>
899 if (isset($package['platform'][$file]) &&
900 $package['platform'][$file]{0} != '!') {
901 $genericIgnore[] = $file;
905 foreach ($package['platform'] as $file => $platform) {
906 if (isset($package['install-as'][$file])) {
909 if ($platform{0} != '!') {
910 //o <ignore> tags for <file name=... platform=...>
911 $genericIgnore[] = $file;
914 if (count($package['platform'])) {
915 $oses = $notplatform = $platform = array();
916 foreach ($package['platform'] as $file => $os) {
917 // get a list of oses
919 if (isset($oses[substr($os, 1)])) {
922 $oses[substr($os, 1)] = count($oses);
924 if (isset($oses[$os])) {
927 $oses[$os] = count($oses);
930 //- create a release for each platform encountered and fill with
931 foreach ($oses as $os => $releaseNum) {
932 $release[$releaseNum]['installconditions']['os']['name'] = $os;
933 $release[$releaseNum]['filelist'] = array('install' => array(),
934 'ignore' => array());
935 foreach ($package['install-as'] as $file => $as) {
936 //o <install as=..> tags for <file name=... install-as=...>
937 if (!isset($package['platform'][$file])) {
938 $release[$releaseNum]['filelist']['install'][] =
947 //o <install as..> tags for
948 // <file name=... platform=this platform install-as=..>
949 if (isset($package['platform'][$file]) &&
950 $package['platform'][$file] == $os) {
951 $release[$releaseNum]['filelist']['install'][] =
960 //o <install as..> tags for
961 // <file name=... platform=!other platform install-as=..>
962 if (isset($package['platform'][$file]) &&
963 $package['platform'][$file] != "!$os" &&
964 $package['platform'][$file]{0} == '!') {
965 $release[$releaseNum]['filelist']['install'][] =
974 //o <ignore> tags for
975 // <file name=... platform=!this platform install-as=..>
976 if (isset($package['platform'][$file]) &&
977 $package['platform'][$file] == "!$os") {
978 $release[$releaseNum]['filelist']['ignore'][] =
986 //o <ignore> tags for
987 // <file name=... platform=other platform install-as=..>
988 if (isset($package['platform'][$file]) &&
989 $package['platform'][$file]{0} != '!' &&
990 $package['platform'][$file] != $os) {
991 $release[$releaseNum]['filelist']['ignore'][] =
1000 foreach ($package['platform'] as $file => $platform) {
1001 if (isset($package['install-as'][$file])) {
1004 //o <ignore> tags for <file name=... platform=!this platform>
1005 if ($platform == "!$os") {
1006 $release[$releaseNum]['filelist']['ignore'][] =
1014 //o <ignore> tags for <file name=... platform=other platform>
1015 if ($platform{0} != '!' && $platform != $os) {
1016 $release[$releaseNum]['filelist']['ignore'][] =
1024 if (!count($release[$releaseNum]['filelist']['install'])) {
1025 unset($release[$releaseNum]['filelist']['install']);
1027 if (!count($release[$releaseNum]['filelist']['ignore'])) {
1028 unset($release[$releaseNum]['filelist']['ignore']);
1031 if (count($generic) || count($genericIgnore)) {
1032 $release[count($oses)] = array();
1033 if (count($generic)) {
1034 foreach ($generic as $file) {
1035 if (isset($package['install-as'][$file])) {
1036 $installas = $package['install-as'][$file];
1040 $release[count($oses)]['filelist']['install'][] =
1049 if (count($genericIgnore)) {
1050 foreach ($genericIgnore as $file) {
1051 $release[count($oses)]['filelist']['ignore'][] =
1061 foreach ($release as $i => $rel) {
1062 if (isset($rel['filelist']['install']) &&
1063 count($rel['filelist']['install']) == 1) {
1064 $release[$i]['filelist']['install'] =
1065 $release[$i]['filelist']['install'][0];
1067 if (isset($rel['filelist']['ignore']) &&
1068 count($rel['filelist']['ignore']) == 1) {
1069 $release[$i]['filelist']['ignore'] =
1070 $release[$i]['filelist']['ignore'][0];
1073 if (count($release) == 1) {
1074 $release = $release[0];
1077 // no platform atts, but some install-as atts
1078 foreach ($package['install-as'] as $file => $value) {
1079 $release['filelist']['install'][] =
1087 if (count($release['filelist']['install']) == 1) {
1088 $release['filelist']['install'] = $release['filelist']['install'][0];
1099 function _processDep($dep)
1101 if ($dep['type'] == 'php') {
1102 if ($dep['rel'] == 'has') {
1103 // come on - everyone has php!
1108 if ($dep['type'] != 'php') {
1109 $php['name'] = $dep['name'];
1110 if ($dep['type'] == 'pkg') {
1111 $php['channel'] = 'pear.php.net';
1114 switch ($dep['rel']) {
1116 $php['min'] = $dep['version'];
1117 $php['exclude'] = $dep['version'];
1120 if (!isset($dep['version'])) {
1121 if ($dep['type'] == 'php') {
1122 if (isset($dep['name'])) {
1123 $dep['version'] = $dep['name'];
1127 $php['min'] = $dep['version'];
1130 $php['max'] = $dep['version'];
1131 $php['exclude'] = $dep['version'];
1134 $php['max'] = $dep['version'];
1137 $php['min'] = $dep['version'];
1138 $php['max'] = $dep['version'];
1141 $php['exclude'] = $dep['version'];
1144 $php['conflicts'] = 'yes';
1154 function _processPhpDeps($deps)
1157 foreach ($deps as $dep) {
1158 $test[] = $this->_processDep($dep);
1162 foreach ($test as $dep) {
1166 if (isset($dep['min'])) {
1167 $min[$dep['min']] = count($min);
1169 if (isset($dep['max'])) {
1170 $max[$dep['max']] = count($max);
1173 if (count($min) > 0) {
1174 uksort($min, 'version_compare');
1176 if (count($max) > 0) {
1177 uksort($max, 'version_compare');
1180 // get the highest minimum
1181 $min = array_pop($a = array_flip($min));
1186 // get the lowest maximum
1187 $max = array_shift($a = array_flip($max));
1198 foreach ($test as $dep) {
1199 if (!isset($dep['exclude'])) {
1202 $exclude[] = $dep['exclude'];
1204 if (count($exclude)) {
1205 $php['exclude'] = $exclude;
1211 * process multiple dependencies that have a name, like package deps
1216 function _processMultipleDepsName($deps)
1218 $ret = $tests = array();
1219 foreach ($deps as $name => $dep) {
1220 foreach ($dep as $d) {
1221 $tests[$name][] = $this->_processDep($d);
1225 foreach ($tests as $name => $test) {
1226 $max = $min = $php = array();
1227 $php['name'] = $name;
1228 foreach ($test as $dep) {
1232 if (isset($dep['channel'])) {
1233 $php['channel'] = 'pear.php.net';
1235 if (isset($dep['conflicts']) && $dep['conflicts'] == 'yes') {
1236 $php['conflicts'] = 'yes';
1238 if (isset($dep['min'])) {
1239 $min[$dep['min']] = count($min);
1241 if (isset($dep['max'])) {
1242 $max[$dep['max']] = count($max);
1245 if (count($min) > 0) {
1246 uksort($min, 'version_compare');
1248 if (count($max) > 0) {
1249 uksort($max, 'version_compare');
1252 // get the highest minimum
1253 $min = array_pop($a = array_flip($min));
1258 // get the lowest maximum
1259 $max = array_shift($a = array_flip($max));
1270 foreach ($test as $dep) {
1271 if (!isset($dep['exclude'])) {
1274 $exclude[] = $dep['exclude'];
1276 if (count($exclude)) {
1277 $php['exclude'] = $exclude;