[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 /** 3 * package.xml generation class, package.xml version 1.0 4 * 5 * PHP versions 4 and 5 6 * 7 * LICENSE: This source file is subject to version 3.0 of the PHP license 8 * that is available through the world-wide-web at the following URI: 9 * http://www.php.net/license/3_0.txt. If you did not receive a copy of 10 * the PHP License and are unable to obtain it through the web, please 11 * send a note to license@php.net so we can mail you a copy immediately. 12 * 13 * @category pear 14 * @package PEAR 15 * @author Greg Beaver <cellog@php.net> 16 * @copyright 1997-2006 The PHP Group 17 * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 * @version CVS: $Id: v1.php,v 1.70.2.1 2006/05/10 02:55:06 cellog Exp $ 19 * @link http://pear.php.net/package/PEAR 20 * @since File available since Release 1.4.0a1 21 */ 22 /** 23 * needed for PEAR_VALIDATE_* constants 24 */ 25 require_once 'PEAR/Validate.php'; 26 require_once 'System.php'; 27 require_once 'PEAR/PackageFile/v2.php'; 28 /** 29 * This class converts a PEAR_PackageFile_v1 object into any output format. 30 * 31 * Supported output formats include array, XML string, and a PEAR_PackageFile_v2 32 * object, for converting package.xml 1.0 into package.xml 2.0 with no sweat. 33 * @category pear 34 * @package PEAR 35 * @author Greg Beaver <cellog@php.net> 36 * @copyright 1997-2006 The PHP Group 37 * @license http://www.php.net/license/3_0.txt PHP License 3.0 38 * @version Release: 1.4.11 39 * @link http://pear.php.net/package/PEAR 40 * @since Class available since Release 1.4.0a1 41 */ 42 class PEAR_PackageFile_Generator_v1 43 { 44 /** 45 * @var PEAR_PackageFile_v1 46 */ 47 var $_packagefile; 48 function PEAR_PackageFile_Generator_v1(&$packagefile) 49 { 50 $this->_packagefile = &$packagefile; 51 } 52 53 function getPackagerVersion() 54 { 55 return '1.4.11'; 56 } 57 58 /** 59 * @param PEAR_Packager 60 * @param bool if true, a .tgz is written, otherwise a .tar is written 61 * @param string|null directory in which to save the .tgz 62 * @return string|PEAR_Error location of package or error object 63 */ 64 function toTgz(&$packager, $compress = true, $where = null) 65 { 66 require_once 'Archive/Tar.php'; 67 if ($where === null) { 68 if (!($where = System::mktemp(array('-d')))) { 69 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: mktemp failed'); 70 } 71 } elseif (!@System::mkDir(array('-p', $where))) { 72 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: "' . $where . '" could' . 73 ' not be created'); 74 } 75 if (file_exists($where . DIRECTORY_SEPARATOR . 'package.xml') && 76 !is_file($where . DIRECTORY_SEPARATOR . 'package.xml')) { 77 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: unable to save package.xml as' . 78 ' "' . $where . DIRECTORY_SEPARATOR . 'package.xml"'); 79 } 80 if (!$this->_packagefile->validate(PEAR_VALIDATE_PACKAGING)) { 81 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: invalid package file'); 82 } 83 $pkginfo = $this->_packagefile->getArray(); 84 $ext = $compress ? '.tgz' : '.tar'; 85 $pkgver = $pkginfo['package'] . '-' . $pkginfo['version']; 86 $dest_package = getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext; 87 if (file_exists(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext) && 88 !is_file(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext)) { 89 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: cannot create tgz file "' . 90 getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext . '"'); 91 } 92 if ($pkgfile = $this->_packagefile->getPackageFile()) { 93 $pkgdir = dirname(realpath($pkgfile)); 94 $pkgfile = basename($pkgfile); 95 } else { 96 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: package file object must ' . 97 'be created from a real file'); 98 } 99 // {{{ Create the package file list 100 $filelist = array(); 101 $i = 0; 102 103 foreach ($this->_packagefile->getFilelist() as $fname => $atts) { 104 $file = $pkgdir . DIRECTORY_SEPARATOR . $fname; 105 if (!file_exists($file)) { 106 return PEAR::raiseError("File does not exist: $fname"); 107 } else { 108 $filelist[$i++] = $file; 109 if (!isset($atts['md5sum'])) { 110 $this->_packagefile->setFileAttribute($fname, 'md5sum', md5_file($file)); 111 } 112 $packager->log(2, "Adding file $fname"); 113 } 114 } 115 // }}} 116 $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true); 117 if ($packagexml) { 118 $tar =& new Archive_Tar($dest_package, $compress); 119 $tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors 120 // ----- Creates with the package.xml file 121 $ok = $tar->createModify(array($packagexml), '', $where); 122 if (PEAR::isError($ok)) { 123 return $ok; 124 } elseif (!$ok) { 125 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: tarball creation failed'); 126 } 127 // ----- Add the content of the package 128 if (!$tar->addModify($filelist, $pkgver, $pkgdir)) { 129 return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: tarball creation failed'); 130 } 131 return $dest_package; 132 } 133 } 134 135 /** 136 * @param string|null directory to place the package.xml in, or null for a temporary dir 137 * @param int one of the PEAR_VALIDATE_* constants 138 * @param string name of the generated file 139 * @param bool if true, then no analysis will be performed on role="php" files 140 * @return string|PEAR_Error path to the created file on success 141 */ 142 function toPackageFile($where = null, $state = PEAR_VALIDATE_NORMAL, $name = 'package.xml', 143 $nofilechecking = false) 144 { 145 if (!$this->_packagefile->validate($state, $nofilechecking)) { 146 return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: invalid package.xml', 147 null, null, null, $this->_packagefile->getValidationWarnings()); 148 } 149 if ($where === null) { 150 if (!($where = System::mktemp(array('-d')))) { 151 return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: mktemp failed'); 152 } 153 } elseif (!@System::mkDir(array('-p', $where))) { 154 return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: "' . $where . '" could' . 155 ' not be created'); 156 } 157 $newpkgfile = $where . DIRECTORY_SEPARATOR . $name; 158 $np = @fopen($newpkgfile, 'wb'); 159 if (!$np) { 160 return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: unable to save ' . 161 "$name as $newpkgfile"); 162 } 163 fwrite($np, $this->toXml($state, true)); 164 fclose($np); 165 return $newpkgfile; 166 } 167 168 /** 169 * fix both XML encoding to be UTF8, and replace standard XML entities < > " & ' 170 * 171 * @param string $string 172 * @return string 173 * @access private 174 */ 175 function _fixXmlEncoding($string) 176 { 177 if (version_compare(phpversion(), '5.0.0', 'lt')) { 178 $string = utf8_encode($string); 179 } 180 return strtr($string, array( 181 '&' => '&', 182 '>' => '>', 183 '<' => '<', 184 '"' => '"', 185 '\'' => ''' )); 186 } 187 188 /** 189 * Return an XML document based on the package info (as returned 190 * by the PEAR_Common::infoFrom* methods). 191 * 192 * @return string XML data 193 */ 194 function toXml($state = PEAR_VALIDATE_NORMAL, $nofilevalidation = false) 195 { 196 $this->_packagefile->setDate(date('Y-m-d')); 197 if (!$this->_packagefile->validate($state, $nofilevalidation)) { 198 return false; 199 } 200 $pkginfo = $this->_packagefile->getArray(); 201 static $maint_map = array( 202 "handle" => "user", 203 "name" => "name", 204 "email" => "email", 205 "role" => "role", 206 ); 207 $ret = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; 208 $ret .= "<!DOCTYPE package SYSTEM \"http://pear.php.net/dtd/package-1.0\">\n"; 209 $ret .= "<package version=\"1.0\" packagerversion=\"1.4.11\">\n" . 210 " <name>$pkginfo[package]</name>"; 211 if (isset($pkginfo['extends'])) { 212 $ret .= "\n<extends>$pkginfo[extends]</extends>"; 213 } 214 $ret .= 215 "\n <summary>".$this->_fixXmlEncoding($pkginfo['summary'])."</summary>\n" . 216 " <description>".trim($this->_fixXmlEncoding($pkginfo['description']))."\n </description>\n" . 217 " <maintainers>\n"; 218 foreach ($pkginfo['maintainers'] as $maint) { 219 $ret .= " <maintainer>\n"; 220 foreach ($maint_map as $idx => $elm) { 221 $ret .= " <$elm>"; 222 $ret .= $this->_fixXmlEncoding($maint[$idx]); 223 $ret .= "</$elm>\n"; 224 } 225 $ret .= " </maintainer>\n"; 226 } 227 $ret .= " </maintainers>\n"; 228 $ret .= $this->_makeReleaseXml($pkginfo, false, $state); 229 if (isset($pkginfo['changelog']) && count($pkginfo['changelog']) > 0) { 230 $ret .= " <changelog>\n"; 231 foreach ($pkginfo['changelog'] as $oldrelease) { 232 $ret .= $this->_makeReleaseXml($oldrelease, true); 233 } 234 $ret .= " </changelog>\n"; 235 } 236 $ret .= "</package>\n"; 237 return $ret; 238 } 239 240 // }}} 241 // {{{ _makeReleaseXml() 242 243 /** 244 * Generate part of an XML description with release information. 245 * 246 * @param array $pkginfo array with release information 247 * @param bool $changelog whether the result will be in a changelog element 248 * 249 * @return string XML data 250 * 251 * @access private 252 */ 253 function _makeReleaseXml($pkginfo, $changelog = false, $state = PEAR_VALIDATE_NORMAL) 254 { 255 // XXX QUOTE ENTITIES IN PCDATA, OR EMBED IN CDATA BLOCKS!! 256 $indent = $changelog ? " " : ""; 257 $ret = "$indent <release>\n"; 258 if (!empty($pkginfo['version'])) { 259 $ret .= "$indent <version>$pkginfo[version]</version>\n"; 260 } 261 if (!empty($pkginfo['release_date'])) { 262 $ret .= "$indent <date>$pkginfo[release_date]</date>\n"; 263 } 264 if (!empty($pkginfo['release_license'])) { 265 $ret .= "$indent <license>$pkginfo[release_license]</license>\n"; 266 } 267 if (!empty($pkginfo['release_state'])) { 268 $ret .= "$indent <state>$pkginfo[release_state]</state>\n"; 269 } 270 if (!empty($pkginfo['release_notes'])) { 271 $ret .= "$indent <notes>".trim($this->_fixXmlEncoding($pkginfo['release_notes'])) 272 ."\n$indent </notes>\n"; 273 } 274 if (!empty($pkginfo['release_warnings'])) { 275 $ret .= "$indent <warnings>".$this->_fixXmlEncoding($pkginfo['release_warnings'])."</warnings>\n"; 276 } 277 if (isset($pkginfo['release_deps']) && sizeof($pkginfo['release_deps']) > 0) { 278 $ret .= "$indent <deps>\n"; 279 foreach ($pkginfo['release_deps'] as $dep) { 280 $ret .= "$indent <dep type=\"$dep[type]\" rel=\"$dep[rel]\""; 281 if (isset($dep['version'])) { 282 $ret .= " version=\"$dep[version]\""; 283 } 284 if (isset($dep['optional'])) { 285 $ret .= " optional=\"$dep[optional]\""; 286 } 287 if (isset($dep['name'])) { 288 $ret .= ">$dep[name]</dep>\n"; 289 } else { 290 $ret .= "/>\n"; 291 } 292 } 293 $ret .= "$indent </deps>\n"; 294 } 295 if (isset($pkginfo['configure_options'])) { 296 $ret .= "$indent <configureoptions>\n"; 297 foreach ($pkginfo['configure_options'] as $c) { 298 $ret .= "$indent <configureoption name=\"". 299 $this->_fixXmlEncoding($c['name']) . "\""; 300 if (isset($c['default'])) { 301 $ret .= " default=\"" . $this->_fixXmlEncoding($c['default']) . "\""; 302 } 303 $ret .= " prompt=\"" . $this->_fixXmlEncoding($c['prompt']) . "\""; 304 $ret .= "/>\n"; 305 } 306 $ret .= "$indent </configureoptions>\n"; 307 } 308 if (isset($pkginfo['provides'])) { 309 foreach ($pkginfo['provides'] as $key => $what) { 310 $ret .= "$indent <provides type=\"$what[type]\" "; 311 $ret .= "name=\"$what[name]\" "; 312 if (isset($what['extends'])) { 313 $ret .= "extends=\"$what[extends]\" "; 314 } 315 $ret .= "/>\n"; 316 } 317 } 318 if (isset($pkginfo['filelist'])) { 319 $ret .= "$indent <filelist>\n"; 320 if ($state ^ PEAR_VALIDATE_PACKAGING) { 321 $ret .= $this->recursiveXmlFilelist($pkginfo['filelist']); 322 } else { 323 foreach ($pkginfo['filelist'] as $file => $fa) { 324 @$ret .= "$indent <file role=\"$fa[role]\""; 325 if (isset($fa['baseinstalldir'])) { 326 $ret .= ' baseinstalldir="' . 327 $this->_fixXmlEncoding($fa['baseinstalldir']) . '"'; 328 } 329 if (isset($fa['md5sum'])) { 330 $ret .= " md5sum=\"$fa[md5sum]\""; 331 } 332 if (isset($fa['platform'])) { 333 $ret .= " platform=\"$fa[platform]\""; 334 } 335 if (!empty($fa['install-as'])) { 336 $ret .= ' install-as="' . 337 $this->_fixXmlEncoding($fa['install-as']) . '"'; 338 } 339 $ret .= ' name="' . $this->_fixXmlEncoding($file) . '"'; 340 if (empty($fa['replacements'])) { 341 $ret .= "/>\n"; 342 } else { 343 $ret .= ">\n"; 344 foreach ($fa['replacements'] as $r) { 345 $ret .= "$indent <replace"; 346 foreach ($r as $k => $v) { 347 $ret .= " $k=\"" . $this->_fixXmlEncoding($v) .'"'; 348 } 349 $ret .= "/>\n"; 350 } 351 @$ret .= "$indent </file>\n"; 352 } 353 } 354 } 355 $ret .= "$indent </filelist>\n"; 356 } 357 $ret .= "$indent </release>\n"; 358 return $ret; 359 } 360 361 /** 362 * @param array 363 * @access protected 364 */ 365 function recursiveXmlFilelist($list) 366 { 367 $this->_dirs = array(); 368 foreach ($list as $file => $attributes) { 369 $this->_addDir($this->_dirs, explode('/', dirname($file)), $file, $attributes); 370 } 371 return $this->_formatDir($this->_dirs); 372 } 373 374 /** 375 * @param array 376 * @param array 377 * @param string|null 378 * @param array|null 379 * @access private 380 */ 381 function _addDir(&$dirs, $dir, $file = null, $attributes = null) 382 { 383 if ($dir == array() || $dir == array('.')) { 384 $dirs['files'][basename($file)] = $attributes; 385 return; 386 } 387 $curdir = array_shift($dir); 388 if (!isset($dirs['dirs'][$curdir])) { 389 $dirs['dirs'][$curdir] = array(); 390 } 391 $this->_addDir($dirs['dirs'][$curdir], $dir, $file, $attributes); 392 } 393 394 /** 395 * @param array 396 * @param string 397 * @param string 398 * @access private 399 */ 400 function _formatDir($dirs, $indent = '', $curdir = '') 401 { 402 $ret = ''; 403 if (!count($dirs)) { 404 return ''; 405 } 406 if (isset($dirs['dirs'])) { 407 uksort($dirs['dirs'], 'strnatcasecmp'); 408 foreach ($dirs['dirs'] as $dir => $contents) { 409 $usedir = "$curdir/$dir"; 410 $ret .= "$indent <dir name=\"$dir\">\n"; 411 $ret .= $this->_formatDir($contents, "$indent ", $usedir); 412 $ret .= "$indent </dir> <!-- $usedir -->\n"; 413 } 414 } 415 if (isset($dirs['files'])) { 416 uksort($dirs['files'], 'strnatcasecmp'); 417 foreach ($dirs['files'] as $file => $attribs) { 418 $ret .= $this->_formatFile($file, $attribs, $indent); 419 } 420 } 421 return $ret; 422 } 423 424 /** 425 * @param string 426 * @param array 427 * @param string 428 * @access private 429 */ 430 function _formatFile($file, $attributes, $indent) 431 { 432 $ret = "$indent <file role=\"$attributes[role]\""; 433 if (isset($attributes['baseinstalldir'])) { 434 $ret .= ' baseinstalldir="' . 435 $this->_fixXmlEncoding($attributes['baseinstalldir']) . '"'; 436 } 437 if (isset($attributes['md5sum'])) { 438 $ret .= " md5sum=\"$attributes[md5sum]\""; 439 } 440 if (isset($attributes['platform'])) { 441 $ret .= " platform=\"$attributes[platform]\""; 442 } 443 if (!empty($attributes['install-as'])) { 444 $ret .= ' install-as="' . 445 $this->_fixXmlEncoding($attributes['install-as']) . '"'; 446 } 447 $ret .= ' name="' . $this->_fixXmlEncoding($file) . '"'; 448 if (empty($attributes['replacements'])) { 449 $ret .= "/>\n"; 450 } else { 451 $ret .= ">\n"; 452 foreach ($attributes['replacements'] as $r) { 453 $ret .= "$indent <replace"; 454 foreach ($r as $k => $v) { 455 $ret .= " $k=\"" . $this->_fixXmlEncoding($v) .'"'; 456 } 457 $ret .= "/>\n"; 458 } 459 $ret .= "$indent </file>\n"; 460 } 461 return $ret; 462 } 463 464 // {{{ _unIndent() 465 466 /** 467 * Unindent given string (?) 468 * 469 * @param string $str The string that has to be unindented. 470 * @return string 471 * @access private 472 */ 473 function _unIndent($str) 474 { 475 // remove leading newlines 476 $str = preg_replace('/^[\r\n]+/', '', $str); 477 // find whitespace at the beginning of the first line 478 $indent_len = strspn($str, " \t"); 479 $indent = substr($str, 0, $indent_len); 480 $data = ''; 481 // remove the same amount of whitespace from following lines 482 foreach (explode("\n", $str) as $line) { 483 if (substr($line, 0, $indent_len) == $indent) { 484 $data .= substr($line, $indent_len) . "\n"; 485 } 486 } 487 return $data; 488 } 489 490 /** 491 * @return array 492 */ 493 function dependenciesToV2() 494 { 495 $arr = array(); 496 $this->_convertDependencies2_0($arr); 497 return $arr['dependencies']; 498 } 499 500 /** 501 * Convert a package.xml version 1.0 into version 2.0 502 * 503 * Note that this does a basic conversion, to allow more advanced 504 * features like bundles and multiple releases 505 * @param string the classname to instantiate and return. This must be 506 * PEAR_PackageFile_v2 or a descendant 507 * @param boolean if true, only valid, deterministic package.xml 1.0 as defined by the 508 * strictest parameters will be converted 509 * @return PEAR_PackageFile_v2|PEAR_Error 510 */ 511 function &toV2($class = 'PEAR_PackageFile_v2', $strict = false) 512 { 513 if ($strict) { 514 if (!$this->_packagefile->validate()) { 515 $a = PEAR::raiseError('invalid package.xml version 1.0 cannot be converted' . 516 ' to version 2.0', null, null, null, 517 $this->_packagefile->getValidationWarnings(true)); 518 return $a; 519 } 520 } 521 $arr = array( 522 'attribs' => array( 523 'version' => '2.0', 524 'xmlns' => 'http://pear.php.net/dtd/package-2.0', 525 'xmlns:tasks' => 'http://pear.php.net/dtd/tasks-1.0', 526 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 527 'xsi:schemaLocation' => "http://pear.php.net/dtd/tasks-1.0\n" . 528 "http://pear.php.net/dtd/tasks-1.0.xsd\n" . 529 "http://pear.php.net/dtd/package-2.0\n" . 530 'http://pear.php.net/dtd/package-2.0.xsd', 531 ), 532 'name' => $this->_packagefile->getPackage(), 533 'channel' => 'pear.php.net', 534 ); 535 $arr['summary'] = $this->_packagefile->getSummary(); 536 $arr['description'] = $this->_packagefile->getDescription(); 537 $maintainers = $this->_packagefile->getMaintainers(); 538 foreach ($maintainers as $maintainer) { 539 if ($maintainer['role'] != 'lead') { 540 continue; 541 } 542 $new = array( 543 'name' => $maintainer['name'], 544 'user' => $maintainer['handle'], 545 'email' => $maintainer['email'], 546 'active' => 'yes', 547 ); 548 $arr['lead'][] = $new; 549 } 550 if (!isset($arr['lead'])) { // some people... you know? 551 $arr['lead'] = array( 552 'name' => 'unknown', 553 'user' => 'unknown', 554 'email' => 'noleadmaintainer@example.com', 555 'active' => 'no', 556 ); 557 } 558 if (count($arr['lead']) == 1) { 559 $arr['lead'] = $arr['lead'][0]; 560 } 561 foreach ($maintainers as $maintainer) { 562 if ($maintainer['role'] == 'lead') { 563 continue; 564 } 565 $new = array( 566 'name' => $maintainer['name'], 567 'user' => $maintainer['handle'], 568 'email' => $maintainer['email'], 569 'active' => 'yes', 570 ); 571 $arr[$maintainer['role']][] = $new; 572 } 573 if (isset($arr['developer']) && count($arr['developer']) == 1) { 574 $arr['developer'] = $arr['developer'][0]; 575 } 576 if (isset($arr['contributor']) && count($arr['contributor']) == 1) { 577 $arr['contributor'] = $arr['contributor'][0]; 578 } 579 if (isset($arr['helper']) && count($arr['helper']) == 1) { 580 $arr['helper'] = $arr['helper'][0]; 581 } 582 $arr['date'] = $this->_packagefile->getDate(); 583 $arr['version'] = 584 array( 585 'release' => $this->_packagefile->getVersion(), 586 'api' => $this->_packagefile->getVersion(), 587 ); 588 $arr['stability'] = 589 array( 590 'release' => $this->_packagefile->getState(), 591 'api' => $this->_packagefile->getState(), 592 ); 593 $licensemap = 594 array( 595 'php' => 'http://www.php.net/license', 596 'php license' => 'http://www.php.net/license', 597 'lgpl' => 'http://www.gnu.org/copyleft/lesser.html', 598 'bsd' => 'http://www.opensource.org/licenses/bsd-license.php', 599 'bsd style' => 'http://www.opensource.org/licenses/bsd-license.php', 600 'bsd-style' => 'http://www.opensource.org/licenses/bsd-license.php', 601 'mit' => 'http://www.opensource.org/licenses/mit-license.php', 602 'gpl' => 'http://www.gnu.org/copyleft/gpl.html', 603 'apache' => 'http://www.opensource.org/licenses/apache2.0.php' 604 ); 605 if (isset($licensemap[strtolower($this->_packagefile->getLicense())])) { 606 $arr['license'] = array( 607 'attribs' => array('uri' => 608 $licensemap[strtolower($this->_packagefile->getLicense())]), 609 '_content' => $this->_packagefile->getLicense() 610 ); 611 } else { 612 // don't use bogus uri 613 $arr['license'] = $this->_packagefile->getLicense(); 614 } 615 $arr['notes'] = $this->_packagefile->getNotes(); 616 $temp = array(); 617 $arr['contents'] = $this->_convertFilelist2_0($temp); 618 $this->_convertDependencies2_0($arr); 619 $release = ($this->_packagefile->getConfigureOptions() || $this->_isExtension) ? 620 'extsrcrelease' : 'phprelease'; 621 if ($release == 'extsrcrelease') { 622 $arr['channel'] = 'pecl.php.net'; 623 $arr['providesextension'] = $arr['name']; // assumption 624 } 625 $arr[$release] = array(); 626 if ($this->_packagefile->getConfigureOptions()) { 627 $arr[$release]['configureoption'] = $this->_packagefile->getConfigureOptions(); 628 foreach ($arr[$release]['configureoption'] as $i => $opt) { 629 $arr[$release]['configureoption'][$i] = array('attribs' => $opt); 630 } 631 if (count($arr[$release]['configureoption']) == 1) { 632 $arr[$release]['configureoption'] = $arr[$release]['configureoption'][0]; 633 } 634 } 635 $this->_convertRelease2_0($arr[$release], $temp); 636 if ($release == 'extsrcrelease' && count($arr[$release]) > 1) { 637 // multiple extsrcrelease tags added in PEAR 1.4.1 638 $arr['dependencies']['required']['pearinstaller']['min'] = '1.4.1'; 639 } 640 if ($cl = $this->_packagefile->getChangelog()) { 641 foreach ($cl as $release) { 642 $rel = array(); 643 $rel['version'] = 644 array( 645 'release' => $release['version'], 646 'api' => $release['version'], 647 ); 648 if (!isset($release['release_state'])) { 649 $release['release_state'] = 'stable'; 650 } 651 $rel['stability'] = 652 array( 653 'release' => $release['release_state'], 654 'api' => $release['release_state'], 655 ); 656 if (isset($release['release_date'])) { 657 $rel['date'] = $release['release_date']; 658 } else { 659 $rel['date'] = date('Y-m-d'); 660 } 661 if (isset($release['release_license'])) { 662 if (isset($licensemap[strtolower($release['release_license'])])) { 663 $uri = $licensemap[strtolower($release['release_license'])]; 664 } else { 665 $uri = 'http://www.example.com'; 666 } 667 $rel['license'] = array( 668 'attribs' => array('uri' => $uri), 669 '_content' => $release['release_license'] 670 ); 671 } else { 672 $rel['license'] = $arr['license']; 673 } 674 if (!isset($release['release_notes'])) { 675 $release['release_notes'] = 'no release notes'; 676 } 677 $rel['notes'] = $release['release_notes']; 678 $arr['changelog']['release'][] = $rel; 679 } 680 } 681 $ret = new $class; 682 $ret->setConfig($this->_packagefile->_config); 683 if (isset($this->_packagefile->_logger) && is_object($this->_packagefile->_logger)) { 684 $ret->setLogger($this->_packagefile->_logger); 685 } 686 $ret->fromArray($arr); 687 return $ret; 688 } 689 690 /** 691 * @param array 692 * @param bool 693 * @access private 694 */ 695 function _convertDependencies2_0(&$release, $internal = false) 696 { 697 $peardep = array('pearinstaller' => 698 array('min' => '1.4.0b1')); // this is a lot safer 699 $required = $optional = array(); 700 $release['dependencies'] = array(); 701 if ($this->_packagefile->hasDeps()) { 702 foreach ($this->_packagefile->getDeps() as $dep) { 703 if (!isset($dep['optional']) || $dep['optional'] == 'no') { 704 $required[] = $dep; 705 } else { 706 $optional[] = $dep; 707 } 708 } 709 foreach (array('required', 'optional') as $arr) { 710 $deps = array(); 711 foreach ($$arr as $dep) { 712 // organize deps by dependency type and name 713 if (!isset($deps[$dep['type']])) { 714 $deps[$dep['type']] = array(); 715 } 716 if (isset($dep['name'])) { 717 $deps[$dep['type']][$dep['name']][] = $dep; 718 } else { 719 $deps[$dep['type']][] = $dep; 720 } 721 } 722 do { 723 if (isset($deps['php'])) { 724 $php = array(); 725 if (count($deps['php']) > 1) { 726 $php = $this->_processPhpDeps($deps['php']); 727 } else { 728 if (!isset($deps['php'][0])) { 729 list($key, $blah) = each ($deps['php']); // stupid buggy versions 730 $deps['php'] = array($blah[0]); 731 } 732 $php = $this->_processDep($deps['php'][0]); 733 if (!$php) { 734 break; // poor mans throw 735 } 736 } 737 $release['dependencies'][$arr]['php'] = $php; 738 } 739 } while (false); 740 do { 741 if (isset($deps['pkg'])) { 742 $pkg = array(); 743 $pkg = $this->_processMultipleDepsName($deps['pkg']); 744 if (!$pkg) { 745 break; // poor mans throw 746 } 747 $release['dependencies'][$arr]['package'] = $pkg; 748 } 749 } while (false); 750 do { 751 if (isset($deps['ext'])) { 752 $pkg = array(); 753 $pkg = $this->_processMultipleDepsName($deps['ext']); 754 $release['dependencies'][$arr]['extension'] = $pkg; 755 } 756 } while (false); 757 // skip sapi - it's not supported so nobody will have used it 758 // skip os - it's not supported in 1.0 759 } 760 } 761 if (isset($release['dependencies']['required'])) { 762 $release['dependencies']['required'] = 763 array_merge($peardep, $release['dependencies']['required']); 764 } else { 765 $release['dependencies']['required'] = $peardep; 766 } 767 if (!isset($release['dependencies']['required']['php'])) { 768 $release['dependencies']['required']['php'] = 769 array('min' => '4.0.0'); 770 } 771 $order = array(); 772 $bewm = $release['dependencies']['required']; 773 $order['php'] = $bewm['php']; 774 $order['pearinstaller'] = $bewm['pearinstaller']; 775 isset($bewm['package']) ? $order['package'] = $bewm['package'] :0; 776 isset($bewm['extension']) ? $order['extension'] = $bewm['extension'] :0; 777 $release['dependencies']['required'] = $order; 778 } 779 780 /** 781 * @param array 782 * @access private 783 */ 784 function _convertFilelist2_0(&$package) 785 { 786 $ret = array('dir' => 787 array( 788 'attribs' => array('name' => '/'), 789 'file' => array() 790 ) 791 ); 792 $package['platform'] = 793 $package['install-as'] = array(); 794 $this->_isExtension = false; 795 foreach ($this->_packagefile->getFilelist() as $name => $file) { 796 $file['name'] = $name; 797 if (isset($file['role']) && $file['role'] == 'src') { 798 $this->_isExtension = true; 799 } 800 if (isset($file['replacements'])) { 801 $repl = $file['replacements']; 802 unset($file['replacements']); 803 } else { 804 unset($repl); 805 } 806 if (isset($file['install-as'])) { 807 $package['install-as'][$name] = $file['install-as']; 808 unset($file['install-as']); 809 } 810 if (isset($file['platform'])) { 811 $package['platform'][$name] = $file['platform']; 812 unset($file['platform']); 813 } 814 $file = array('attribs' => $file); 815 if (isset($repl)) { 816 foreach ($repl as $replace ) { 817 $file['tasks:replace'][] = array('attribs' => $replace); 818 } 819 if (count($repl) == 1) { 820 $file['tasks:replace'] = $file['tasks:replace'][0]; 821 } 822 } 823 $ret['dir']['file'][] = $file; 824 } 825 return $ret; 826 } 827 828 /** 829 * Post-process special files with install-as/platform attributes and 830 * make the release tag. 831 * 832 * This complex method follows this work-flow to create the release tags: 833 * 834 * <pre> 835 * - if any install-as/platform exist, create a generic release and fill it with 836 * o <install as=..> tags for <file name=... install-as=...> 837 * o <install as=..> tags for <file name=... platform=!... install-as=..> 838 * o <ignore> tags for <file name=... platform=...> 839 * o <ignore> tags for <file name=... platform=... install-as=..> 840 * - create a release for each platform encountered and fill with 841 * o <install as..> tags for <file name=... install-as=...> 842 * o <install as..> tags for <file name=... platform=this platform install-as=..> 843 * o <install as..> tags for <file name=... platform=!other platform install-as=..> 844 * o <ignore> tags for <file name=... platform=!this platform> 845 * o <ignore> tags for <file name=... platform=other platform> 846 * o <ignore> tags for <file name=... platform=other platform install-as=..> 847 * o <ignore> tags for <file name=... platform=!this platform install-as=..> 848 * </pre> 849 * 850 * It does this by accessing the $package parameter, which contains an array with 851 * indices: 852 * 853 * - platform: mapping of file => OS the file should be installed on 854 * - install-as: mapping of file => installed name 855 * - osmap: mapping of OS => list of files that should be installed 856 * on that OS 857 * - notosmap: mapping of OS => list of files that should not be 858 * installed on that OS 859 * 860 * @param array 861 * @param array 862 * @access private 863 */ 864 function _convertRelease2_0(&$release, $package) 865 { 866 //- if any install-as/platform exist, create a generic release and fill it with 867 if (count($package['platform']) || count($package['install-as'])) { 868 $generic = array(); 869 $genericIgnore = array(); 870 foreach ($package['install-as'] as $file => $as) { 871 //o <install as=..> tags for <file name=... install-as=...> 872 if (!isset($package['platform'][$file])) { 873 $generic[] = $file; 874 continue; 875 } 876 //o <install as=..> tags for <file name=... platform=!... install-as=..> 877 if (isset($package['platform'][$file]) && 878 $package['platform'][$file]{0} == '!') { 879 $generic[] = $file; 880 continue; 881 } 882 //o <ignore> tags for <file name=... platform=... install-as=..> 883 if (isset($package['platform'][$file]) && 884 $package['platform'][$file]{0} != '!') { 885 $genericIgnore[] = $file; 886 continue; 887 } 888 } 889 foreach ($package['platform'] as $file => $platform) { 890 if (isset($package['install-as'][$file])) { 891 continue; 892 } 893 if ($platform{0} != '!') { 894 //o <ignore> tags for <file name=... platform=...> 895 $genericIgnore[] = $file; 896 } 897 } 898 if (count($package['platform'])) { 899 $oses = $notplatform = $platform = array(); 900 foreach ($package['platform'] as $file => $os) { 901 // get a list of oses 902 if ($os{0} == '!') { 903 if (isset($oses[substr($os, 1)])) { 904 continue; 905 } 906 $oses[substr($os, 1)] = count($oses); 907 } else { 908 if (isset($oses[$os])) { 909 continue; 910 } 911 $oses[$os] = count($oses); 912 } 913 } 914 //- create a release for each platform encountered and fill with 915 foreach ($oses as $os => $releaseNum) { 916 $release[$releaseNum]['installconditions']['os']['name'] = $os; 917 $release[$releaseNum]['filelist'] = array('install' => array(), 918 'ignore' => array()); 919 foreach ($package['install-as'] as $file => $as) { 920 //o <install as=..> tags for <file name=... install-as=...> 921 if (!isset($package['platform'][$file])) { 922 $release[$releaseNum]['filelist']['install'][] = 923 array( 924 'attribs' => array( 925 'name' => $file, 926 'as' => $as, 927 ), 928 ); 929 continue; 930 } 931 //o <install as..> tags for 932 // <file name=... platform=this platform install-as=..> 933 if (isset($package['platform'][$file]) && 934 $package['platform'][$file] == $os) { 935 $release[$releaseNum]['filelist']['install'][] = 936 array( 937 'attribs' => array( 938 'name' => $file, 939 'as' => $as, 940 ), 941 ); 942 continue; 943 } 944 //o <install as..> tags for 945 // <file name=... platform=!other platform install-as=..> 946 if (isset($package['platform'][$file]) && 947 $package['platform'][$file] != "!$os" && 948 $package['platform'][$file]{0} == '!') { 949 $release[$releaseNum]['filelist']['install'][] = 950 array( 951 'attribs' => array( 952 'name' => $file, 953 'as' => $as, 954 ), 955 ); 956 continue; 957 } 958 //o <ignore> tags for 959 // <file name=... platform=!this platform install-as=..> 960 if (isset($package['platform'][$file]) && 961 $package['platform'][$file] == "!$os") { 962 $release[$releaseNum]['filelist']['ignore'][] = 963 array( 964 'attribs' => array( 965 'name' => $file, 966 ), 967 ); 968 continue; 969 } 970 //o <ignore> tags for 971 // <file name=... platform=other platform install-as=..> 972 if (isset($package['platform'][$file]) && 973 $package['platform'][$file]{0} != '!' && 974 $package['platform'][$file] != $os) { 975 $release[$releaseNum]['filelist']['ignore'][] = 976 array( 977 'attribs' => array( 978 'name' => $file, 979 ), 980 ); 981 continue; 982 } 983 } 984 foreach ($package['platform'] as $file => $platform) { 985 if (isset($package['install-as'][$file])) { 986 continue; 987 } 988 //o <ignore> tags for <file name=... platform=!this platform> 989 if ($platform == "!$os") { 990 $release[$releaseNum]['filelist']['ignore'][] = 991 array( 992 'attribs' => array( 993 'name' => $file, 994 ), 995 ); 996 continue; 997 } 998 //o <ignore> tags for <file name=... platform=other platform> 999 if ($platform{0} != '!' && $platform != $os) { 1000 $release[$releaseNum]['filelist']['ignore'][] = 1001 array( 1002 'attribs' => array( 1003 'name' => $file, 1004 ), 1005 ); 1006 } 1007 } 1008 if (!count($release[$releaseNum]['filelist']['install'])) { 1009 unset($release[$releaseNum]['filelist']['install']); 1010 } 1011 if (!count($release[$releaseNum]['filelist']['ignore'])) { 1012 unset($release[$releaseNum]['filelist']['ignore']); 1013 } 1014 } 1015 if (count($generic) || count($genericIgnore)) { 1016 $release[count($oses)] = array(); 1017 if (count($generic)) { 1018 foreach ($generic as $file) { 1019 if (isset($package['install-as'][$file])) { 1020 $installas = $package['install-as'][$file]; 1021 } else { 1022 $installas = $file; 1023 } 1024 $release[count($oses)]['filelist']['install'][] = 1025 array( 1026 'attribs' => array( 1027 'name' => $file, 1028 'as' => $installas, 1029 ) 1030 ); 1031 } 1032 } 1033 if (count($genericIgnore)) { 1034 foreach ($genericIgnore as $file) { 1035 $release[count($oses)]['filelist']['ignore'][] = 1036 array( 1037 'attribs' => array( 1038 'name' => $file, 1039 ) 1040 ); 1041 } 1042 } 1043 } 1044 // cleanup 1045 foreach ($release as $i => $rel) { 1046 if (isset($rel['filelist']['install']) && 1047 count($rel['filelist']['install']) == 1) { 1048 $release[$i]['filelist']['install'] = 1049 $release[$i]['filelist']['install'][0]; 1050 } 1051 if (isset($rel['filelist']['ignore']) && 1052 count($rel['filelist']['ignore']) == 1) { 1053 $release[$i]['filelist']['ignore'] = 1054 $release[$i]['filelist']['ignore'][0]; 1055 } 1056 } 1057 if (count($release) == 1) { 1058 $release = $release[0]; 1059 } 1060 } else { 1061 // no platform atts, but some install-as atts 1062 foreach ($package['install-as'] as $file => $value) { 1063 $release['filelist']['install'][] = 1064 array( 1065 'attribs' => array( 1066 'name' => $file, 1067 'as' => $value 1068 ) 1069 ); 1070 } 1071 if (count($release['filelist']['install']) == 1) { 1072 $release['filelist']['install'] = $release['filelist']['install'][0]; 1073 } 1074 } 1075 } 1076 } 1077 1078 /** 1079 * @param array 1080 * @return array 1081 * @access private 1082 */ 1083 function _processDep($dep) 1084 { 1085 if ($dep['type'] == 'php') { 1086 if ($dep['rel'] == 'has') { 1087 // come on - everyone has php! 1088 return false; 1089 } 1090 } 1091 $php = array(); 1092 if ($dep['type'] != 'php') { 1093 $php['name'] = $dep['name']; 1094 if ($dep['type'] == 'pkg') { 1095 $php['channel'] = 'pear.php.net'; 1096 } 1097 } 1098 switch ($dep['rel']) { 1099 case 'gt' : 1100 $php['min'] = $dep['version']; 1101 $php['exclude'] = $dep['version']; 1102 break; 1103 case 'ge' : 1104 if (!isset($dep['version'])) { 1105 if ($dep['type'] == 'php') { 1106 if (isset($dep['name'])) { 1107 $dep['version'] = $dep['name']; 1108 } 1109 } 1110 } 1111 $php['min'] = $dep['version']; 1112 break; 1113 case 'lt' : 1114 $php['max'] = $dep['version']; 1115 $php['exclude'] = $dep['version']; 1116 break; 1117 case 'le' : 1118 $php['max'] = $dep['version']; 1119 break; 1120 case 'eq' : 1121 $php['min'] = $dep['version']; 1122 $php['max'] = $dep['version']; 1123 break; 1124 case 'ne' : 1125 $php['exclude'] = $dep['version']; 1126 break; 1127 case 'not' : 1128 $php['conflicts'] = 'yes'; 1129 break; 1130 } 1131 return $php; 1132 } 1133 1134 /** 1135 * @param array 1136 * @return array 1137 */ 1138 function _processPhpDeps($deps) 1139 { 1140 $test = array(); 1141 foreach ($deps as $dep) { 1142 $test[] = $this->_processDep($dep); 1143 } 1144 $min = array(); 1145 $max = array(); 1146 foreach ($test as $dep) { 1147 if (!$dep) { 1148 continue; 1149 } 1150 if (isset($dep['min'])) { 1151 $min[$dep['min']] = count($min); 1152 } 1153 if (isset($dep['max'])) { 1154 $max[$dep['max']] = count($max); 1155 } 1156 } 1157 if (count($min) > 0) { 1158 uksort($min, 'version_compare'); 1159 } 1160 if (count($max) > 0) { 1161 uksort($max, 'version_compare'); 1162 } 1163 if (count($min)) { 1164 // get the highest minimum 1165 $min = array_pop($a = array_flip($min)); 1166 } else { 1167 $min = false; 1168 } 1169 if (count($max)) { 1170 // get the lowest maximum 1171 $max = array_shift($a = array_flip($max)); 1172 } else { 1173 $max = false; 1174 } 1175 if ($min) { 1176 $php['min'] = $min; 1177 } 1178 if ($max) { 1179 $php['max'] = $max; 1180 } 1181 $exclude = array(); 1182 foreach ($test as $dep) { 1183 if (!isset($dep['exclude'])) { 1184 continue; 1185 } 1186 $exclude[] = $dep['exclude']; 1187 } 1188 if (count($exclude)) { 1189 $php['exclude'] = $exclude; 1190 } 1191 return $php; 1192 } 1193 1194 /** 1195 * process multiple dependencies that have a name, like package deps 1196 * @param array 1197 * @return array 1198 * @access private 1199 */ 1200 function _processMultipleDepsName($deps) 1201 { 1202 $tests = array(); 1203 foreach ($deps as $name => $dep) { 1204 foreach ($dep as $d) { 1205 $tests[$name][] = $this->_processDep($d); 1206 } 1207 } 1208 foreach ($tests as $name => $test) { 1209 $php = array(); 1210 $min = array(); 1211 $max = array(); 1212 $php['name'] = $name; 1213 foreach ($test as $dep) { 1214 if (!$dep) { 1215 continue; 1216 } 1217 if (isset($dep['channel'])) { 1218 $php['channel'] = 'pear.php.net'; 1219 } 1220 if (isset($dep['conflicts']) && $dep['conflicts'] == 'yes') { 1221 $php['conflicts'] = 'yes'; 1222 } 1223 if (isset($dep['min'])) { 1224 $min[$dep['min']] = count($min); 1225 } 1226 if (isset($dep['max'])) { 1227 $max[$dep['max']] = count($max); 1228 } 1229 } 1230 if (count($min) > 0) { 1231 uksort($min, 'version_compare'); 1232 } 1233 if (count($max) > 0) { 1234 uksort($max, 'version_compare'); 1235 } 1236 if (count($min)) { 1237 // get the highest minimum 1238 $min = array_pop($a = array_flip($min)); 1239 } else { 1240 $min = false; 1241 } 1242 if (count($max)) { 1243 // get the lowest maximum 1244 $max = array_shift($a = array_flip($max)); 1245 } else { 1246 $max = false; 1247 } 1248 if ($min) { 1249 $php['min'] = $min; 1250 } 1251 if ($max) { 1252 $php['max'] = $max; 1253 } 1254 $exclude = array(); 1255 foreach ($test as $dep) { 1256 if (!isset($dep['exclude'])) { 1257 continue; 1258 } 1259 $exclude[] = $dep['exclude']; 1260 } 1261 if (count($exclude)) { 1262 $php['exclude'] = $exclude; 1263 } 1264 $ret[] = $php; 1265 } 1266 return $ret; 1267 } 1268 } 1269 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |