[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/system/pear/PEAR/PackageFile/v2/ -> rw.php (source)

   1  <?php
   2  /**
   3   * PEAR_PackageFile_v2, package.xml version 2.0, read/write version
   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: rw.php,v 1.15 2006/01/28 17:35:11 cellog Exp $
  19   * @link       http://pear.php.net/package/PEAR
  20   * @since      File available since Release 1.4.0a8
  21   */
  22  /**
  23   * For base class
  24   */
  25  require_once 'PEAR/PackageFile/v2.php';
  26  /**
  27   * @category   pear
  28   * @package    PEAR
  29   * @author     Greg Beaver <cellog@php.net>
  30   * @copyright  1997-2006 The PHP Group
  31   * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  32   * @version    Release: 1.4.11
  33   * @link       http://pear.php.net/package/PEAR
  34   * @since      Class available since Release 1.4.0a8
  35   */
  36  class PEAR_PackageFile_v2_rw extends PEAR_PackageFile_v2
  37  {
  38      /**
  39       * @param string Extension name
  40       * @return bool success of operation
  41       */
  42      function setProvidesExtension($extension)
  43      {
  44          if (in_array($this->getPackageType(), array('extsrc', 'extbin'))) {
  45              if (!isset($this->_packageInfo['providesextension'])) {
  46                  // ensure that the channel tag is set up in the right location
  47                  $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
  48                      array('usesrole', 'usestask', 'srcpackage', 'srcuri', 'phprelease',
  49                      'extsrcrelease', 'extbinrelease', 'bundle', 'changelog'),
  50                      $extension, 'providesextension');
  51              }
  52              $this->_packageInfo['providesextension'] = $extension;
  53              return true;
  54          }
  55          return false;
  56      }
  57  
  58      function setPackage($package)
  59      {
  60          $this->_isValid = 0;
  61          if (!isset($this->_packageInfo['attribs'])) {
  62              $this->_packageInfo = array_merge(array('attribs' => array(
  63                                   'version' => '2.0',
  64                                   'xmlns' => 'http://pear.php.net/dtd/package-2.0',
  65                                   'xmlns:tasks' => 'http://pear.php.net/dtd/tasks-1.0',
  66                                   'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
  67                                   'xsi:schemaLocation' => 'http://pear.php.net/dtd/tasks-1.0
  68      http://pear.php.net/dtd/tasks-1.0.xsd
  69      http://pear.php.net/dtd/package-2.0
  70      http://pear.php.net/dtd/package-2.0.xsd',
  71                               )), $this->_packageInfo);
  72          }
  73          if (!isset($this->_packageInfo['name'])) {
  74              return $this->_packageInfo = array_merge(array('name' => $package),
  75                  $this->_packageInfo);
  76          }
  77          $this->_packageInfo['name'] = $package;
  78      }
  79  
  80      function setUri($uri)
  81      {
  82          unset($this->_packageInfo['channel']);
  83          $this->_isValid = 0;
  84          if (!isset($this->_packageInfo['uri'])) {
  85              // ensure that the uri tag is set up in the right location
  86              $this->_packageInfo = $this->_insertBefore($this->_packageInfo, 
  87                  array('extends', 'summary', 'description', 'lead',
  88                  'developer', 'contributor', 'helper', 'date', 'time', 'version',
  89                  'stability', 'license', 'notes', 'contents', 'compatible',
  90                  'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
  91                  'phprelease', 'extsrcrelease',
  92                  'extbinrelease', 'bundle', 'changelog'), $uri, 'uri');
  93          }
  94          $this->_packageInfo['uri'] = $uri;
  95      }
  96  
  97      function setChannel($channel)
  98      {
  99          unset($this->_packageInfo['uri']);
 100          $this->_isValid = 0;
 101          if (!isset($this->_packageInfo['channel'])) {
 102              // ensure that the channel tag is set up in the right location
 103              $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
 104                  array('extends', 'summary', 'description', 'lead',
 105                  'developer', 'contributor', 'helper', 'date', 'time', 'version',
 106                  'stability', 'license', 'notes', 'contents', 'compatible',
 107                  'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
 108                  'phprelease', 'extsrcrelease',
 109                  'extbinrelease', 'bundle', 'changelog'), $channel, 'channel');
 110          }
 111          $this->_packageInfo['channel'] = $channel;
 112      }
 113  
 114      function setExtends($extends)
 115      {
 116          $this->_isValid = 0;
 117          if (!isset($this->_packageInfo['extends'])) {
 118              // ensure that the extends tag is set up in the right location
 119              $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
 120                  array('summary', 'description', 'lead',
 121                  'developer', 'contributor', 'helper', 'date', 'time', 'version',
 122                  'stability', 'license', 'notes', 'contents', 'compatible',
 123                  'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
 124                  'phprelease', 'extsrcrelease',
 125                  'extbinrelease', 'bundle', 'changelog'), $extends, 'extends');
 126          }
 127          $this->_packageInfo['extends'] = $extends;
 128      }
 129  
 130      function setSummary($summary)
 131      {
 132          $this->_isValid = 0;
 133          if (!isset($this->_packageInfo['summary'])) {
 134              // ensure that the summary tag is set up in the right location
 135              $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
 136                  array('description', 'lead',
 137                  'developer', 'contributor', 'helper', 'date', 'time', 'version',
 138                  'stability', 'license', 'notes', 'contents', 'compatible',
 139                  'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
 140                  'phprelease', 'extsrcrelease',
 141                  'extbinrelease', 'bundle', 'changelog'), $summary, 'summary');
 142          }
 143          $this->_packageInfo['summary'] = $summary;
 144      }
 145  
 146      function setDescription($desc)
 147      {
 148          $this->_isValid = 0;
 149          if (!isset($this->_packageInfo['description'])) {
 150              // ensure that the description tag is set up in the right location
 151              $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
 152                  array('lead',
 153                  'developer', 'contributor', 'helper', 'date', 'time', 'version',
 154                  'stability', 'license', 'notes', 'contents', 'compatible',
 155                  'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
 156                  'phprelease', 'extsrcrelease',
 157                  'extbinrelease', 'bundle', 'changelog'), $desc, 'description');
 158          }
 159          $this->_packageInfo['description'] = $desc;
 160      }
 161  
 162      /**
 163       * Adds a new maintainer - no checking of duplicates is performed, use
 164       * updatemaintainer for that purpose.
 165       */
 166      function addMaintainer($role, $handle, $name, $email, $active = 'yes')
 167      {
 168          if (!in_array($role, array('lead', 'developer', 'contributor', 'helper'))) {
 169              return false;
 170          }
 171          if (isset($this->_packageInfo[$role])) {
 172              if (!isset($this->_packageInfo[$role][0])) {
 173                  $this->_packageInfo[$role] = array($this->_packageInfo[$role]);
 174              }
 175              $this->_packageInfo[$role][] =
 176                  array(
 177                      'name' => $name,
 178                      'user' => $handle,
 179                      'email' => $email,
 180                      'active' => $active,
 181                  );
 182          } else {
 183              $testarr = array('lead',
 184                      'developer', 'contributor', 'helper', 'date', 'time', 'version',
 185                      'stability', 'license', 'notes', 'contents', 'compatible',
 186                      'dependencies', 'providesextension', 'usesrole', 'usestask',
 187                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease',
 188                      'extbinrelease', 'bundle', 'changelog');
 189              foreach (array('lead', 'developer', 'contributor', 'helper') as $testrole) {
 190                  array_shift($testarr);
 191                  if ($role == $testrole) {
 192                      break;
 193                  }
 194              }
 195              if (!isset($this->_packageInfo[$role])) {
 196                  // ensure that the extends tag is set up in the right location
 197                  $this->_packageInfo = $this->_insertBefore($this->_packageInfo, $testarr,
 198                      array(), $role);
 199              }
 200              $this->_packageInfo[$role] =
 201                  array(
 202                      'name' => $name,
 203                      'user' => $handle,
 204                      'email' => $email,
 205                      'active' => $active,
 206                  );
 207          }
 208          $this->_isValid = 0;
 209      }
 210  
 211      function updateMaintainer($newrole, $handle, $name, $email, $active = 'yes')
 212      {
 213          $found = false;
 214          foreach (array('lead', 'developer', 'contributor', 'helper') as $role) {
 215              if (!isset($this->_packageInfo[$role])) {
 216                  continue;
 217              }
 218              $info = $this->_packageInfo[$role];
 219              if (!isset($info[0])) {
 220                  if ($info['user'] == $handle) {
 221                      $found = true;
 222                      break;
 223                  }
 224              }
 225              foreach ($info as $i => $maintainer) {
 226                  if ($maintainer['user'] == $handle) {
 227                      $found = $i;
 228                      break 2;
 229                  }
 230              }
 231          }
 232          if ($found === false) {
 233              return $this->addMaintainer($newrole, $handle, $name, $email, $active);
 234          }
 235          if ($found !== false) {
 236              if ($found === true) {
 237                  unset($this->_packageInfo[$role]);
 238              } else {
 239                  unset($this->_packageInfo[$role][$found]);
 240                  $this->_packageInfo[$role] = array_values($this->_packageInfo[$role]);
 241              }
 242          }
 243          $this->addMaintainer($newrole, $handle, $name, $email, $active);
 244          $this->_isValid = 0;
 245      }
 246  
 247      function deleteMaintainer($handle)
 248      {
 249          $found = false;
 250          foreach (array('lead', 'developer', 'contributor', 'helper') as $role) {
 251              if (!isset($this->_packageInfo[$role])) {
 252                  continue;
 253              }
 254              if (!isset($this->_packageInfo[$role][0])) {
 255                  $this->_packageInfo[$role] = array($this->_packageInfo[$role]);
 256              }
 257              foreach ($this->_packageInfo[$role] as $i => $maintainer) {
 258                  if ($maintainer['user'] == $handle) {
 259                      $found = $i;
 260                      break;
 261                  }
 262              }
 263              if ($found !== false) {
 264                  unset($this->_packageInfo[$role][$found]);
 265                  if (!count($this->_packageInfo[$role]) && $role == 'lead') {
 266                      $this->_isValid = 0;
 267                  }
 268                  if (!count($this->_packageInfo[$role])) {
 269                      unset($this->_packageInfo[$role]);
 270                      return true;
 271                  }
 272                  $this->_packageInfo[$role] =
 273                      array_values($this->_packageInfo[$role]);
 274                  if (count($this->_packageInfo[$role]) == 1) {
 275                      $this->_packageInfo[$role] = $this->_packageInfo[$role][0];
 276                  }
 277                  return true;
 278              }
 279              if (count($this->_packageInfo[$role]) == 1) {
 280                  $this->_packageInfo[$role] = $this->_packageInfo[$role][0];
 281              }
 282          }
 283          return false;
 284      }
 285  
 286      function setReleaseVersion($version)
 287      {
 288          if (isset($this->_packageInfo['version']) &&
 289                isset($this->_packageInfo['version']['release'])) {
 290              unset($this->_packageInfo['version']['release']);
 291          }
 292          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $version, array(
 293              'version' => array('stability', 'license', 'notes', 'contents', 'compatible',
 294                  'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
 295                  'phprelease', 'extsrcrelease',
 296                  'extbinrelease', 'bundle', 'changelog'),
 297              'release' => array('api')));
 298          $this->_isValid = 0;
 299      }
 300  
 301      function setAPIVersion($version)
 302      {
 303          if (isset($this->_packageInfo['version']) &&
 304                isset($this->_packageInfo['version']['api'])) {
 305              unset($this->_packageInfo['version']['api']);
 306          }
 307          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $version, array(
 308              'version' => array('stability', 'license', 'notes', 'contents', 'compatible',
 309                  'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
 310                  'phprelease', 'extsrcrelease',
 311                  'extbinrelease', 'bundle', 'changelog'),
 312              'api' => array()));
 313          $this->_isValid = 0;
 314      }
 315  
 316      /**
 317       * snapshot|devel|alpha|beta|stable
 318       */
 319      function setReleaseStability($state)
 320      {
 321          if (isset($this->_packageInfo['stability']) &&
 322                isset($this->_packageInfo['stability']['release'])) {
 323              unset($this->_packageInfo['stability']['release']);
 324          }
 325          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $state, array(
 326              'stability' => array('license', 'notes', 'contents', 'compatible',
 327                  'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
 328                  'phprelease', 'extsrcrelease',
 329                  'extbinrelease', 'bundle', 'changelog'),
 330              'release' => array('api')));
 331          $this->_isValid = 0;
 332      }
 333  
 334      /**
 335       * @param devel|alpha|beta|stable
 336       */
 337      function setAPIStability($state)
 338      {
 339          if (isset($this->_packageInfo['stability']) &&
 340                isset($this->_packageInfo['stability']['api'])) {
 341              unset($this->_packageInfo['stability']['api']);
 342          }
 343          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $state, array(
 344              'stability' => array('license', 'notes', 'contents', 'compatible',
 345                  'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
 346                  'phprelease', 'extsrcrelease',
 347                  'extbinrelease', 'bundle', 'changelog'),
 348              'api' => array()));
 349          $this->_isValid = 0;
 350      }
 351  
 352      function setLicense($license, $uri = false, $filesource = false)
 353      {
 354          if (!isset($this->_packageInfo['license'])) {
 355              // ensure that the license tag is set up in the right location
 356              $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
 357                  array('notes', 'contents', 'compatible',
 358                  'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
 359                  'phprelease', 'extsrcrelease',
 360                  'extbinrelease', 'bundle', 'changelog'), 0, 'license');
 361          }
 362          if ($uri || $filesource) {
 363              $attribs = array();
 364              if ($uri) {
 365                  $attribs['uri'] = $uri;
 366              }
 367              $uri = true; // for test below
 368              if ($filesource) {
 369                  $attribs['filesource'] = $filesource;
 370              }
 371          }
 372          $license = $uri ? array('attribs' => $attribs, '_content' => $license) : $license;
 373          $this->_packageInfo['license'] = $license;
 374          $this->_isValid = 0;
 375      }
 376  
 377      function setNotes($notes)
 378      {
 379          $this->_isValid = 0;
 380          if (!isset($this->_packageInfo['notes'])) {
 381              // ensure that the notes tag is set up in the right location
 382              $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
 383                  array('contents', 'compatible',
 384                  'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
 385                  'phprelease', 'extsrcrelease',
 386                  'extbinrelease', 'bundle', 'changelog'), $notes, 'notes');
 387          }
 388          $this->_packageInfo['notes'] = $notes;
 389      }
 390  
 391      /**
 392       * This is only used at install-time, after all serialization
 393       * is over.
 394       * @param string file name
 395       * @param string installed path
 396       */
 397      function setInstalledAs($file, $path)
 398      {
 399          if ($path) {
 400              return $this->_packageInfo['filelist'][$file]['installed_as'] = $path;
 401          }
 402          unset($this->_packageInfo['filelist'][$file]['installed_as']);
 403      }
 404  
 405      /**
 406       * This is only used at install-time, after all serialization
 407       * is over.
 408       */
 409      function installedFile($file, $atts)
 410      {
 411          if (isset($this->_packageInfo['filelist'][$file])) {
 412              $this->_packageInfo['filelist'][$file] =
 413                  array_merge($this->_packageInfo['filelist'][$file], $atts['attribs']);
 414          } else {
 415              $this->_packageInfo['filelist'][$file] = $atts['attribs'];
 416          }
 417      }
 418  
 419      /**
 420       * Reset the listing of package contents
 421       * @param string base installation dir for the whole package, if any
 422       */
 423      function clearContents($baseinstall = false)
 424      {
 425          $this->_filesValid = false;
 426          $this->_isValid = 0;
 427          if (!isset($this->_packageInfo['contents'])) {
 428              $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
 429                  array('compatible',
 430                      'dependencies', 'providesextension', 'usesrole', 'usestask',
 431                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease',
 432                      'extbinrelease', 'bundle', 'changelog'), array(), 'contents');
 433          }
 434          if ($this->getPackageType() != 'bundle') {
 435              $this->_packageInfo['contents'] = 
 436                  array('dir' => array('attribs' => array('name' => '/')));
 437              if ($baseinstall) {
 438                  $this->_packageInfo['contents']['dir']['attribs']['baseinstalldir'] = $baseinstall;
 439              }
 440          }
 441      }
 442  
 443      /**
 444       * @param string relative path of the bundled package.
 445       */
 446      function addBundledPackage($path)
 447      {
 448          if ($this->getPackageType() != 'bundle') {
 449              return false;
 450          }
 451          $this->_filesValid = false;
 452          $this->_isValid = 0;
 453          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $path, array(
 454                  'contents' => array('compatible', 'dependencies', 'providesextension',
 455                  'usesrole', 'usestask', 'srcpackage', 'srcuri', 'phprelease',
 456                  'extsrcrelease', 'extbinrelease', 'bundle', 'changelog'),
 457                  'bundledpackage' => array()));
 458      }
 459  
 460      /**
 461       * @param string file name
 462       * @param PEAR_Task_Common a read/write task
 463       */
 464      function addTaskToFile($filename, $task)
 465      {
 466          if (!method_exists($task, 'getXml')) {
 467              return false;
 468          }
 469          if (!method_exists($task, 'getName')) {
 470              return false;
 471          }
 472          if (!method_exists($task, 'validate')) {
 473              return false;
 474          }
 475          if (!$task->validate()) {
 476              return false;
 477          }
 478          if (!isset($this->_packageInfo['contents']['dir']['file'])) {
 479              return false;
 480          }
 481          $this->getTasksNs(); // discover the tasks namespace if not done already
 482          $files = $this->_packageInfo['contents']['dir']['file'];
 483          if (!isset($files[0])) {
 484              $files = array($files);
 485              $ind = false;
 486          } else {
 487              $ind = true;
 488          }
 489          foreach ($files as $i => $file) {
 490              if (isset($file['attribs'])) {
 491                  if ($file['attribs']['name'] == $filename) {
 492                      if ($ind) {
 493                          $t = isset($this->_packageInfo['contents']['dir']['file'][$i]
 494                                ['attribs'][$this->_tasksNs .
 495                                ':' . $task->getName()]) ?
 496                                $this->_packageInfo['contents']['dir']['file'][$i]
 497                                ['attribs'][$this->_tasksNs .
 498                                ':' . $task->getName()] : false;
 499                          if ($t && !isset($t[0])) {
 500                              $this->_packageInfo['contents']['dir']['file'][$i]
 501                                  [$this->_tasksNs . ':' . $task->getName()] = array($t);
 502                          }
 503                          $this->_packageInfo['contents']['dir']['file'][$i][$this->_tasksNs .
 504                              ':' . $task->getName()][] = $task->getXml();
 505                      } else {
 506                          $t = isset($this->_packageInfo['contents']['dir']['file']
 507                                ['attribs'][$this->_tasksNs .
 508                                ':' . $task->getName()]) ? $this->_packageInfo['contents']['dir']['file']
 509                                ['attribs'][$this->_tasksNs .
 510                                ':' . $task->getName()] : false;
 511                          if ($t && !isset($t[0])) {
 512                              $this->_packageInfo['contents']['dir']['file']
 513                                  [$this->_tasksNs . ':' . $task->getName()] = array($t);
 514                          }
 515                          $this->_packageInfo['contents']['dir']['file'][$this->_tasksNs .
 516                              ':' . $task->getName()][] = $task->getXml();
 517                      }
 518                      return true;
 519                  }
 520              }
 521          }
 522          return false;
 523      }
 524  
 525      /**
 526       * @param string path to the file
 527       * @param string filename
 528       * @param array extra attributes
 529       */
 530      function addFile($dir, $file, $attrs)
 531      {
 532          if ($this->getPackageType() == 'bundle') {
 533              return false;
 534          }
 535          $this->_filesValid = false;
 536          $this->_isValid = 0;
 537          $dir = preg_replace(array('!\\\\+!', '!/+!'), array('/', '/'), $dir);
 538          if ($dir == '/' || $dir == '') {
 539              $dir = '';
 540          } else {
 541              $dir .= '/';
 542          }
 543          $attrs['name'] = $dir . $file;
 544          if (!isset($this->_packageInfo['contents'])) {
 545              // ensure that the contents tag is set up
 546              $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
 547                  array('compatible', 'dependencies', 'providesextension', 'usesrole', 'usestask',
 548                  'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease',
 549                  'extbinrelease', 'bundle', 'changelog'), array(), 'contents');
 550          }
 551          if (isset($this->_packageInfo['contents']['dir']['file'])) {
 552              if (!isset($this->_packageInfo['contents']['dir']['file'][0])) {
 553                  $this->_packageInfo['contents']['dir']['file'] =
 554                      array($this->_packageInfo['contents']['dir']['file']);
 555              }
 556              $this->_packageInfo['contents']['dir']['file'][]['attribs'] = $attrs;
 557          } else {
 558              $this->_packageInfo['contents']['dir']['file']['attribs'] = $attrs;
 559          }
 560      }
 561  
 562      /**
 563       * @param string Dependent package name
 564       * @param string Dependent package's channel name
 565       * @param string minimum version of specified package that this release is guaranteed to be
 566       *               compatible with
 567       * @param string maximum version of specified package that this release is guaranteed to be
 568       *               compatible with
 569       * @param string versions of specified package that this release is not compatible with
 570       */
 571      function addCompatiblePackage($name, $channel, $min, $max, $exclude = false)
 572      {
 573          $this->_isValid = 0;
 574          $set = array(
 575              'name' => $name,
 576              'channel' => $channel,
 577              'min' => $min,
 578              'max' => $max,
 579          );
 580          if ($exclude) {
 581              $set['exclude'] = $exclude;
 582          }
 583          $this->_isValid = 0;
 584          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $set, array(
 585                  'compatible' => array('dependencies', 'providesextension', 'usesrole', 'usestask',
 586                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
 587                      'bundle', 'changelog')
 588              ));
 589      }
 590  
 591      /**
 592       * Removes the <usesrole> tag entirely
 593       */
 594      function resetUsesrole()
 595      {
 596          if (isset($this->_packageInfo['usesrole'])) {
 597              unset($this->_packageInfo['usesrole']);
 598          }
 599      }
 600  
 601      /**
 602       * @param string
 603       * @param string package name or uri
 604       * @param string channel name if non-uri
 605       */
 606      function addUsesrole($role, $packageOrUri, $channel = false) {
 607          $set = array('role' => $role);
 608          if ($channel) {
 609              $set['package'] = $packageOrUri;
 610              $set['channel'] = $channel;
 611          } else {
 612              $set['uri'] = $packageOrUri;
 613          }
 614          $this->_isValid = 0;
 615          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $set, array(
 616                  'usesrole' => array('usestask', 'srcpackage', 'srcuri',
 617                      'phprelease', 'extsrcrelease', 'extbinrelease', 'bundle', 'changelog')
 618              ));
 619      }
 620  
 621      /**
 622       * Removes the <usestask> tag entirely
 623       */
 624      function resetUsestask()
 625      {
 626          if (isset($this->_packageInfo['usestask'])) {
 627              unset($this->_packageInfo['usestask']);
 628          }
 629      }
 630  
 631  
 632      /**
 633       * @param string
 634       * @param string package name or uri
 635       * @param string channel name if non-uri
 636       */
 637      function addUsestask($task, $packageOrUri, $channel = false) {
 638          $set = array('task' => $task);
 639          if ($channel) {
 640              $set['package'] = $packageOrUri;
 641              $set['channel'] = $channel;
 642          } else {
 643              $set['uri'] = $packageOrUri;
 644          }
 645          $this->_isValid = 0;
 646          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $set, array(
 647                  'usestask' => array('srcpackage', 'srcuri',
 648                      'phprelease', 'extsrcrelease', 'extbinrelease', 'bundle', 'changelog')
 649              ));
 650      }
 651  
 652      /**
 653       * Remove all compatible tags
 654       */
 655      function clearCompatible()
 656      {
 657          unset($this->_packageInfo['compatible']);
 658      }
 659  
 660      /**
 661       * Reset dependencies prior to adding new ones
 662       */
 663      function clearDeps()
 664      {
 665          if (!isset($this->_packageInfo['dependencies'])) {
 666              $this->_packageInfo = $this->_mergeTag($this->_packageInfo, array(),
 667                  array(
 668                      'dependencies' => array('providesextension', 'usesrole', 'usestask',
 669                          'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
 670                          'bundle', 'changelog')));
 671          }
 672          $this->_packageInfo['dependencies'] = array();
 673      }
 674  
 675      /**
 676       * @param string minimum PHP version allowed
 677       * @param string maximum PHP version allowed
 678       * @param array $exclude incompatible PHP versions
 679       */
 680      function setPhpDep($min, $max = false, $exclude = false)
 681      {
 682          $this->_isValid = 0;
 683          $dep =
 684              array(
 685                  'min' => $min,
 686              );
 687          if ($max) {
 688              $dep['max'] = $max;
 689          }
 690          if ($exclude) {
 691              if (count($exclude) == 1) {
 692                  $exclude = $exclude[0];
 693              }
 694              $dep['exclude'] = $exclude;
 695          }
 696          if (isset($this->_packageInfo['dependencies']['required']['php'])) {
 697              $this->_stack->push(__FUNCTION__, 'warning', array('dep' =>
 698              $this->_packageInfo['dependencies']['required']['php']),
 699                  'warning: PHP dependency already exists, overwriting');
 700              unset($this->_packageInfo['dependencies']['required']['php']);
 701          }
 702          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
 703              array(
 704                  'dependencies' => array('providesextension', 'usesrole', 'usestask',
 705                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
 706                      'bundle', 'changelog'),
 707                  'required' => array('optional', 'group'),
 708                  'php' => array('pearinstaller', 'package', 'subpackage', 'extension', 'os', 'arch')
 709              ));
 710          return true;
 711      }
 712  
 713      /**
 714       * @param string minimum allowed PEAR installer version
 715       * @param string maximum allowed PEAR installer version
 716       * @param string recommended PEAR installer version
 717       * @param array incompatible version of the PEAR installer
 718       */
 719      function setPearinstallerDep($min, $max = false, $recommended = false, $exclude = false)
 720      {
 721          $this->_isValid = 0;
 722          $dep =
 723              array(
 724                  'min' => $min,
 725              );
 726          if ($max) {
 727              $dep['max'] = $max;
 728          }
 729          if ($recommended) {
 730              $dep['recommended'] = $recommended;
 731          }
 732          if ($exclude) {
 733              if (count($exclude) == 1) {
 734                  $exclude = $exclude[0];
 735              }
 736              $dep['exclude'] = $exclude;
 737          }
 738          if (isset($this->_packageInfo['dependencies']['required']['pearinstaller'])) {
 739              $this->_stack->push(__FUNCTION__, 'warning', array('dep' =>
 740              $this->_packageInfo['dependencies']['required']['pearinstaller']),
 741                  'warning: PEAR Installer dependency already exists, overwriting');
 742              unset($this->_packageInfo['dependencies']['required']['pearinstaller']);
 743          }
 744          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
 745              array(
 746                  'dependencies' => array('providesextension', 'usesrole', 'usestask',
 747                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
 748                      'bundle', 'changelog'),
 749                  'required' => array('optional', 'group'),
 750                  'pearinstaller' => array('package', 'subpackage', 'extension', 'os', 'arch')
 751              ));
 752      }
 753  
 754      /**
 755       * Mark a package as conflicting with this package
 756       * @param string package name
 757       * @param string package channel
 758       * @param string extension this package provides, if any
 759       */
 760      function addConflictingPackageDepWithChannel($name, $channel, $providesextension = false)
 761      {
 762          $this->_isValid = 0;
 763          $dep =
 764              array(
 765                  'name' => $name,
 766                  'channel' => $channel,
 767                  'conflicts' => '',
 768              );
 769          if ($providesextension) {
 770              $dep['providesextension'] = $providesextension;
 771          }
 772          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
 773              array(
 774                  'dependencies' => array('providesextension', 'usesrole', 'usestask',
 775                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
 776                      'bundle', 'changelog'),
 777                  'required' => array('optional', 'group'),
 778                  'package' => array('subpackage', 'extension', 'os', 'arch')
 779              ));
 780      }
 781  
 782      /**
 783       * Mark a package as conflicting with this package
 784       * @param string package name
 785       * @param string package channel
 786       * @param string extension this package provides, if any
 787       */
 788      function addConflictingPackageDepWithUri($name, $uri, $providesextension = false)
 789      {
 790          $this->_isValid = 0;
 791          $dep =
 792              array(
 793                  'name' => $name,
 794                  'uri' => $uri,
 795                  'conflicts' => '',
 796              );
 797          if ($providesextension) {
 798              $dep['providesextension'] = $providesextension;
 799          }
 800          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
 801              array(
 802                  'dependencies' => array('providesextension', 'usesrole', 'usestask',
 803                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
 804                      'bundle', 'changelog'),
 805                  'required' => array('optional', 'group'),
 806                  'package' => array('subpackage', 'extension', 'os', 'arch')
 807              ));
 808      }
 809  
 810      function addDependencyGroup($name, $hint)
 811      {
 812          $this->_isValid = 0;
 813          $this->_packageInfo = $this->_mergeTag($this->_packageInfo,
 814              array('attribs' => array('name' => $name, 'hint' => $hint)),
 815              array(
 816                  'dependencies' => array('providesextension', 'usesrole', 'usestask',
 817                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
 818                      'bundle', 'changelog'),
 819                  'group' => array(),
 820              ));
 821      }
 822  
 823      /**
 824       * @param string package name
 825       * @param string|false channel name, false if this is a uri
 826       * @param string|false uri name, false if this is a channel
 827       * @param string|false minimum version required
 828       * @param string|false maximum version allowed
 829       * @param string|false recommended installation version
 830       * @param array|false versions to exclude from installation
 831       * @param string extension this package provides, if any
 832       * @param bool if true, tells the installer to ignore the default optional dependency group
 833       *             when installing this package
 834       * @return array
 835       * @access private
 836       */
 837      function _constructDep($name, $channel, $uri, $min, $max, $recommended, $exclude,
 838                             $providesextension = false, $nodefault = false)
 839      {
 840          $dep =
 841              array(
 842                  'name' => $name,
 843              );
 844          if ($channel) {
 845              $dep['channel'] = $channel;
 846          } elseif ($uri) {
 847              $dep['uri'] = $uri;
 848          }
 849          if ($min) {
 850              $dep['min'] = $min;
 851          }
 852          if ($max) {
 853              $dep['max'] = $max;
 854          }
 855          if ($recommended) {
 856              $dep['recommended'] = $recommended;
 857          }
 858          if ($exclude) {
 859              if (is_array($exclude) && count($exclude) == 1) {
 860                  $exclude = $exclude[0];
 861              }
 862              $dep['exclude'] = $exclude;
 863          }
 864          if ($nodefault) {
 865              $dep['nodefault'] = '';
 866          }
 867          if ($providesextension) {
 868              $dep['providesextension'] = $providesextension;
 869          }
 870          return $dep;
 871      }
 872  
 873      /**
 874       * @param package|subpackage
 875       * @param string group name
 876       * @param string package name
 877       * @param string package channel
 878       * @param string minimum version
 879       * @param string maximum version
 880       * @param string recommended version
 881       * @param array|false optional excluded versions
 882       * @param string extension this package provides, if any
 883       * @param bool if true, tells the installer to ignore the default optional dependency group
 884       *             when installing this package
 885       * @return bool false if the dependency group has not been initialized with
 886       *              {@link addDependencyGroup()}, or a subpackage is added with
 887       *              a providesextension
 888       */
 889      function addGroupPackageDepWithChannel($type, $groupname, $name, $channel, $min = false,
 890                                        $max = false, $recommended = false, $exclude = false,
 891                                        $providesextension = false, $nodefault = false)
 892      {
 893          if ($type == 'subpackage' && $providesextension) {
 894              return false; // subpackages must be php packages
 895          }
 896          $dep = $this->_constructDep($name, $channel, false, $min, $max, $recommended, $exclude,
 897              $providesextension, $nodefault);
 898          return $this->_addGroupDependency($type, $dep, $groupname);
 899      }
 900  
 901      /**
 902       * @param package|subpackage
 903       * @param string group name
 904       * @param string package name
 905       * @param string package uri
 906       * @param string extension this package provides, if any
 907       * @param bool if true, tells the installer to ignore the default optional dependency group
 908       *             when installing this package
 909       * @return bool false if the dependency group has not been initialized with
 910       *              {@link addDependencyGroup()}
 911       */
 912      function addGroupPackageDepWithURI($type, $groupname, $name, $uri, $providesextension = false,
 913                                         $nodefault = false)
 914      {
 915          if ($type == 'subpackage' && $providesextension) {
 916              return false; // subpackages must be php packages
 917          }
 918          $dep = $this->_constructDep($name, false, $uri, false, false, false, false,
 919              $providesextension, $nodefault);
 920          return $this->_addGroupDependency($type, $dep, $groupname);
 921      }
 922  
 923      /**
 924       * @param string group name (must be pre-existing)
 925       * @param string extension name
 926       * @param string minimum version allowed
 927       * @param string maximum version allowed
 928       * @param string recommended version
 929       * @param array incompatible versions
 930       */
 931      function addGroupExtensionDep($groupname, $name, $min = false, $max = false,
 932                                           $recommended = false, $exclude = false)
 933      {
 934          $this->_isValid = 0;
 935          $dep = $this->_constructDep($name, false, false, $min, $max, $recommended, $exclude);
 936          return $this->_addGroupDependency('extension', $dep, $groupname);
 937      }
 938  
 939      /**
 940       * @param package|subpackage|extension
 941       * @param array dependency contents
 942       * @param string name of the dependency group to add this to
 943       * @return boolean
 944       * @access private
 945       */
 946      function _addGroupDependency($type, $dep, $groupname)
 947      {
 948          $arr = array('subpackage', 'extension');
 949          if ($type != 'package') {
 950              array_shift($arr);
 951          }
 952          if ($type == 'extension') {
 953              array_shift($arr);
 954          }
 955          if (!isset($this->_packageInfo['dependencies']['group'])) {
 956              return false;
 957          } else {
 958              if (!isset($this->_packageInfo['dependencies']['group'][0])) {
 959                  if ($this->_packageInfo['dependencies']['group']['attribs']['name'] == $groupname) {
 960                      $this->_packageInfo['dependencies']['group'] = $this->_mergeTag(
 961                          $this->_packageInfo['dependencies']['group'], $dep,
 962                          array(
 963                              $type => $arr
 964                          ));
 965                      $this->_isValid = 0;
 966                      return true;
 967                  } else {
 968                      return false;
 969                  }
 970              } else {
 971                  foreach ($this->_packageInfo['dependencies']['group'] as $i => $group) {
 972                      if ($group['attribs']['name'] == $groupname) {
 973                      $this->_packageInfo['dependencies']['group'][$i] = $this->_mergeTag(
 974                          $this->_packageInfo['dependencies']['group'][$i], $dep,
 975                          array(
 976                              $type => $arr
 977                          ));
 978                          $this->_isValid = 0;
 979                          return true;
 980                      }
 981                  }
 982                  return false;
 983              }
 984          }
 985      }
 986  
 987      /**
 988       * @param optional|required
 989       * @param string package name
 990       * @param string package channel
 991       * @param string minimum version
 992       * @param string maximum version
 993       * @param string recommended version
 994       * @param string extension this package provides, if any
 995       * @param bool if true, tells the installer to ignore the default optional dependency group
 996       *             when installing this package
 997       * @param array|false optional excluded versions
 998       */
 999      function addPackageDepWithChannel($type, $name, $channel, $min = false, $max = false,
1000                                        $recommended = false, $exclude = false,
1001                                        $providesextension = false, $nodefault = false)
1002      {
1003          $this->_isValid = 0;
1004          $arr = array('optional', 'group');
1005          if ($type != 'required') {
1006              array_shift($arr);
1007          }
1008          $dep = $this->_constructDep($name, $channel, false, $min, $max, $recommended, $exclude,
1009              $providesextension, $nodefault);
1010          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1011              array(
1012                  'dependencies' => array('providesextension', 'usesrole', 'usestask',
1013                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1014                      'bundle', 'changelog'),
1015                  $type => $arr,
1016                  'package' => array('subpackage', 'extension', 'os', 'arch')
1017              ));
1018      }
1019  
1020      /**
1021       * @param optional|required
1022       * @param string name of the package
1023       * @param string uri of the package
1024       * @param string extension this package provides, if any
1025       * @param bool if true, tells the installer to ignore the default optional dependency group
1026       *             when installing this package
1027       */
1028      function addPackageDepWithUri($type, $name, $uri, $providesextension = false,
1029                                    $nodefault = false)
1030      {
1031          $this->_isValid = 0;
1032          $arr = array('optional', 'group');
1033          if ($type != 'required') {
1034              array_shift($arr);
1035          }
1036          $dep = $this->_constructDep($name, false, $uri, false, false, false, false,
1037              $providesextension, $nodefault);
1038          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1039              array(
1040                  'dependencies' => array('providesextension', 'usesrole', 'usestask',
1041                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1042                      'bundle', 'changelog'),
1043                  $type => $arr,
1044                  'package' => array('subpackage', 'extension', 'os', 'arch')
1045              ));
1046      }
1047  
1048      /**
1049       * @param optional|required optional, required
1050       * @param string package name
1051       * @param string package channel
1052       * @param string minimum version
1053       * @param string maximum version
1054       * @param string recommended version
1055       * @param array incompatible versions
1056       * @param bool if true, tells the installer to ignore the default optional dependency group
1057       *             when installing this package
1058       */
1059      function addSubpackageDepWithChannel($type, $name, $channel, $min = false, $max = false,
1060                                           $recommended = false, $exclude = false,
1061                                           $nodefault = false)
1062      {
1063          $this->_isValid = 0;
1064          $arr = array('optional', 'group');
1065          if ($type != 'required') {
1066              array_shift($arr);
1067          }
1068          $dep = $this->_constructDep($name, $channel, false, $min, $max, $recommended, $exclude,
1069              $nodefault);
1070          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1071              array(
1072                  'dependencies' => array('providesextension', 'usesrole', 'usestask',
1073                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1074                      'bundle', 'changelog'),
1075                  $type => $arr,
1076                  'subpackage' => array('extension', 'os', 'arch')
1077              ));
1078      }
1079  
1080      /**
1081       * @param optional|required optional, required
1082       * @param string package name
1083       * @param string package uri for download
1084       * @param bool if true, tells the installer to ignore the default optional dependency group
1085       *             when installing this package
1086       */
1087      function addSubpackageDepWithUri($type, $name, $uri, $nodefault = false)
1088      {
1089          $this->_isValid = 0;
1090          $arr = array('optional', 'group');
1091          if ($type != 'required') {
1092              array_shift($arr);
1093          }
1094          $dep = $this->_constructDep($name, false, $uri, false, false, false, false, $nodefault);
1095          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1096              array(
1097                  'dependencies' => array('providesextension', 'usesrole', 'usestask',
1098                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1099                      'bundle', 'changelog'),
1100                  $type => $arr,
1101                  'subpackage' => array('extension', 'os', 'arch')
1102              ));
1103      }
1104  
1105      /**
1106       * @param optional|required optional, required
1107       * @param string extension name
1108       * @param string minimum version
1109       * @param string maximum version
1110       * @param string recommended version
1111       * @param array incompatible versions
1112       */
1113      function addExtensionDep($type, $name, $min = false, $max = false, $recommended = false,
1114                               $exclude = false)
1115      {
1116          $this->_isValid = 0;
1117          $arr = array('optional', 'group');
1118          if ($type != 'required') {
1119              array_shift($arr);
1120          }
1121          $dep = $this->_constructDep($name, false, false, $min, $max, $recommended, $exclude);
1122          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1123              array(
1124                  'dependencies' => array('providesextension', 'usesrole', 'usestask',
1125                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1126                      'bundle', 'changelog'),
1127                  $type => $arr,
1128                  'extension' => array('os', 'arch')
1129              ));
1130      }
1131  
1132      /**
1133       * @param string Operating system name
1134       * @param boolean true if this package cannot be installed on this OS
1135       */
1136      function addOsDep($name, $conflicts = false)
1137      {
1138          $this->_isValid = 0;
1139          $dep = array('name' => $name);
1140          if ($conflicts) {
1141              $dep['conflicts'] = '';
1142          }
1143          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1144              array(
1145                  'dependencies' => array('providesextension', 'usesrole', 'usestask',
1146                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1147                      'bundle', 'changelog'),
1148                  'required' => array('optional', 'group'),
1149                  'os' => array('arch')
1150              ));
1151      }
1152  
1153      /**
1154       * @param string Architecture matching pattern
1155       * @param boolean true if this package cannot be installed on this architecture
1156       */
1157      function addArchDep($pattern, $conflicts = false)
1158      {
1159          $this->_isValid = 0;
1160          $dep = array('pattern' => $pattern);
1161          if ($conflicts) {
1162              $dep['conflicts'] = '';
1163          }
1164          $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1165              array(
1166                  'dependencies' => array('providesextension', 'usesrole', 'usestask',
1167                      'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1168                      'bundle', 'changelog'),
1169                  'required' => array('optional', 'group'),
1170                  'arch' => array()
1171              ));
1172      }
1173  
1174      /**
1175       * Set the kind of package, and erase all release tags
1176       *
1177       * - a php package is a PEAR-style package
1178       * - an extbin package is a PECL-style extension binary
1179       * - an extsrc package is a PECL-style source for a binary
1180       * - a bundle package is a collection of other pre-packaged packages
1181       * @param php|extbin|extsrc|bundle
1182       * @return bool success
1183       */
1184      function setPackageType($type)
1185      {
1186          $this->_isValid = 0;
1187          if (!in_array($type, array('php', 'extbin', 'extsrc', 'bundle'))) {
1188              return false;
1189          }
1190          if ($type != 'bundle') {
1191              $type .= 'release';
1192          }
1193          foreach (array('phprelease', 'extbinrelease', 'extsrcrelease', 'bundle') as $test) {
1194              unset($this->_packageInfo[$test]);
1195          }
1196          if (!isset($this->_packageInfo[$type])) {
1197              // ensure that the release tag is set up
1198              $this->_packageInfo = $this->_insertBefore($this->_packageInfo, array('changelog'),
1199                  array(), $type);
1200          }
1201          $this->_packageInfo[$type] = array();
1202          return true;
1203      }
1204  
1205      /**
1206       * @return bool true if package type is set up
1207       */
1208      function addRelease()
1209      {
1210          if ($type = $this->getPackageType()) {
1211              if ($type != 'bundle') {
1212                  $type .= 'release';
1213              }
1214              $this->_packageInfo = $this->_mergeTag($this->_packageInfo, array(),
1215                  array($type => array('changelog')));
1216              return true;
1217          }
1218          return false;
1219      }
1220  
1221      /**
1222       * Get the current release tag in order to add to it
1223       * @param bool returns only releases that have installcondition if true
1224       * @return array|null
1225       */
1226      function &_getCurrentRelease($strict = true)
1227      {
1228          if ($p = $this->getPackageType()) {
1229              if ($strict) {
1230                  if ($p == 'extsrc') {
1231                      $a = null;
1232                      return $a;
1233                  }
1234              }
1235              if ($p != 'bundle') {
1236                  $p .= 'release';
1237              }
1238              if (isset($this->_packageInfo[$p][0])) {
1239                  return $this->_packageInfo[$p][count($this->_packageInfo[$p]) - 1];
1240              } else {
1241                  return $this->_packageInfo[$p];
1242              }
1243          } else {
1244              $a = null;
1245              return $a;
1246          }
1247      }
1248  
1249      /**
1250       * Add a file to the current release that should be installed under a different name
1251       * @param string <contents> path to file
1252       * @param string name the file should be installed as
1253       */
1254      function addInstallAs($path, $as)
1255      {
1256          $r = &$this->_getCurrentRelease();
1257          if ($r === null) {
1258              return false;
1259          }
1260          $this->_isValid = 0;
1261          $r = $this->_mergeTag($r, array('attribs' => array('name' => $path, 'as' => $as)),
1262              array(
1263                  'filelist' => array(),
1264                  'install' => array('ignore')
1265              ));
1266      }
1267  
1268      /**
1269       * Add a file to the current release that should be ignored
1270       * @param string <contents> path to file
1271       * @return bool success of operation
1272       */
1273      function addIgnore($path)
1274      {
1275          $r = &$this->_getCurrentRelease();
1276          if ($r === null) {
1277              return false;
1278          }
1279          $this->_isValid = 0;
1280          $r = $this->_mergeTag($r, array('attribs' => array('name' => $path)),
1281              array(
1282                  'filelist' => array(),
1283                  'ignore' => array()
1284              ));
1285      }
1286  
1287      /**
1288       * Add an extension binary package for this extension source code release
1289       *
1290       * Note that the package must be from the same channel as the extension source package
1291       * @param string
1292       */
1293      function addBinarypackage($package)
1294      {
1295          if ($this->getPackageType() != 'extsrc') {
1296              return false;
1297          }
1298          $r = &$this->_getCurrentRelease(false);
1299          if ($r === null) {
1300              return false;
1301          }
1302          $this->_isValid = 0;
1303          $r = $this->_mergeTag($r, $package,
1304              array(
1305                  'binarypackage' => array('filelist'),
1306              ));
1307      }
1308  
1309      /**
1310       * Add a configureoption to an extension source package
1311       * @param string
1312       * @param string
1313       * @param string
1314       */
1315      function addConfigureOption($name, $prompt, $default = null)
1316      {
1317          if ($this->getPackageType() != 'extsrc') {
1318              return false;
1319          }
1320          $r = &$this->_getCurrentRelease(false);
1321          if ($r === null) {
1322              return false;
1323          }
1324          $opt = array('attribs' => array('name' => $name, 'prompt' => $prompt));
1325          if ($default !== null) {
1326              $opt['default'] = $default;
1327          }
1328          $this->_isValid = 0;
1329          $r = $this->_mergeTag($r, $opt,
1330              array(
1331                  'configureoption' => array('binarypackage', 'filelist'),
1332              ));
1333      }
1334  
1335      /**
1336       * Set an installation condition based on php version for the current release set
1337       * @param string minimum version
1338       * @param string maximum version
1339       * @param false|array incompatible versions of PHP
1340       */
1341      function setPhpInstallCondition($min, $max, $exclude = false)
1342      {
1343          $r = &$this->_getCurrentRelease();
1344          if ($r === null) {
1345              return false;
1346          }
1347          $this->_isValid = 0;
1348          if (isset($r['installconditions']['php'])) {
1349              unset($r['installconditions']['php']);
1350          }
1351          $dep = array('min' => $min, 'max' => $max);
1352          if ($exclude) {
1353              if (is_array($exclude) && count($exclude) == 1) {
1354                  $exclude = $exclude[0];
1355              }
1356              $dep['exclude'] = $exclude;
1357          }
1358          if ($this->getPackageType() == 'extsrc') {
1359              $r = $this->_mergeTag($r, $dep,
1360                  array(
1361                      'installconditions' => array('configureoption', 'binarypackage',
1362                          'filelist'),
1363                      'php' => array('extension', 'os', 'arch')
1364                  ));
1365          } else {
1366              $r = $this->_mergeTag($r, $dep,
1367                  array(
1368                      'installconditions' => array('filelist'),
1369                      'php' => array('extension', 'os', 'arch')
1370                  ));
1371          }
1372      }
1373  
1374      /**
1375       * @param optional|required optional, required
1376       * @param string extension name
1377       * @param string minimum version
1378       * @param string maximum version
1379       * @param string recommended version
1380       * @param array incompatible versions
1381       */
1382      function addExtensionInstallCondition($name, $min = false, $max = false, $recommended = false,
1383                                            $exclude = false)
1384      {
1385          $r = &$this->_getCurrentRelease();
1386          if ($r === null) {
1387              return false;
1388          }
1389          $this->_isValid = 0;
1390          $dep = $this->_constructDep($name, false, false, $min, $max, $recommended, $exclude);
1391          if ($this->getPackageType() == 'extsrc') {
1392              $r = $this->_mergeTag($r, $dep,
1393                  array(
1394                      'installconditions' => array('configureoption', 'binarypackage',
1395                          'filelist'),
1396                      'extension' => array('os', 'arch')
1397                  ));
1398          } else {
1399              $r = $this->_mergeTag($r, $dep,
1400                  array(
1401                      'installconditions' => array('filelist'),
1402                      'extension' => array('os', 'arch')
1403                  ));
1404          }
1405      }
1406  
1407      /**
1408       * Set an installation condition based on operating system for the current release set
1409       * @param string OS name
1410       * @param bool whether this OS is incompatible with the current release
1411       */
1412      function setOsInstallCondition($name, $conflicts = false)
1413      {
1414          $r = &$this->_getCurrentRelease();
1415          if ($r === null) {
1416              return false;
1417          }
1418          $this->_isValid = 0;
1419          if (isset($r['installconditions']['os'])) {
1420              unset($r['installconditions']['os']);
1421          }
1422          $dep = array('name' => $name);
1423          if ($conflicts) {
1424              $dep['conflicts'] = '';
1425          }
1426          if ($this->getPackageType() == 'extsrc') {
1427              $r = $this->_mergeTag($r, $dep,
1428                  array(
1429                      'installconditions' => array('configureoption', 'binarypackage',
1430                          'filelist'),
1431                      'os' => array('arch')
1432                  ));
1433          } else {
1434              $r = $this->_mergeTag($r, $dep,
1435                  array(
1436                      'installconditions' => array('filelist'),
1437                      'os' => array('arch')
1438                  ));
1439          }
1440      }
1441  
1442      /**
1443       * Set an installation condition based on architecture for the current release set
1444       * @param string architecture pattern
1445       * @param bool whether this arch is incompatible with the current release
1446       */
1447      function setArchInstallCondition($pattern, $conflicts = false)
1448      {
1449          $r = &$this->_getCurrentRelease();
1450          if ($r === null) {
1451              return false;
1452          }
1453          $this->_isValid = 0;
1454          if (isset($r['installconditions']['arch'])) {
1455              unset($r['installconditions']['arch']);
1456          }
1457          $dep = array('pattern' => $pattern);
1458          if ($conflicts) {
1459              $dep['conflicts'] = '';
1460          }
1461          if ($this->getPackageType() == 'extsrc') {
1462              $r = $this->_mergeTag($r, $dep,
1463                  array(
1464                      'installconditions' => array('configureoption', 'binarypackage',
1465                          'filelist'),
1466                      'arch' => array()
1467                  ));
1468          } else {
1469              $r = $this->_mergeTag($r, $dep,
1470                  array(
1471                      'installconditions' => array('filelist'),
1472                      'arch' => array()
1473                  ));
1474          }
1475      }
1476  
1477      /**
1478       * For extension binary releases, this is used to specify either the
1479       * static URI to a source package, or the package name and channel of the extsrc
1480       * package it is based on.
1481       * @param string Package name, or full URI to source package (extsrc type)
1482       */
1483      function setSourcePackage($packageOrUri)
1484      {
1485          $this->_isValid = 0;
1486          if (isset($this->_packageInfo['channel'])) {
1487              $this->_packageInfo = $this->_insertBefore($this->_packageInfo, array('phprelease',
1488                  'extsrcrelease', 'extbinrelease', 'bundle', 'changelog'),
1489                  $packageOrUri, 'srcpackage');
1490          } else {
1491              $this->_packageInfo = $this->_insertBefore($this->_packageInfo, array('phprelease',
1492                  'extsrcrelease', 'extbinrelease', 'bundle', 'changelog'), $packageOrUri, 'srcuri');
1493          }
1494      }
1495  
1496      /**
1497       * Generate a valid change log entry from the current package.xml
1498       * @param string|false
1499       */
1500      function generateChangeLogEntry($notes = false)
1501      {
1502          return array(
1503              'version' => 
1504                  array(
1505                      'release' => $this->getVersion('release'),
1506                      'api' => $this->getVersion('api'),
1507                      ),
1508              'stability' =>
1509                  $this->getStability(),
1510              'date' => $this->getDate(),
1511              'license' => $this->getLicense(true),
1512              'notes' => $notes ? $notes : $this->getNotes()
1513              );
1514      }
1515  
1516      /**
1517       * @param string release version to set change log notes for
1518       * @param array output of {@link generateChangeLogEntry()}
1519       */
1520      function setChangelogEntry($releaseversion, $contents)
1521      {
1522          if (!isset($this->_packageInfo['changelog'])) {
1523              $this->_packageInfo['changelog']['release'] = $contents;
1524              return;
1525          }
1526          if (!isset($this->_packageInfo['changelog']['release'][0])) {
1527              if ($this->_packageInfo['changelog']['release']['version']['release'] == $releaseversion) {
1528                  $this->_packageInfo['changelog']['release'] = array(
1529                      $this->_packageInfo['changelog']['release']);
1530              } else {
1531                  $this->_packageInfo['changelog']['release'] = array(
1532                      $this->_packageInfo['changelog']['release']);
1533                  return $this->_packageInfo['changelog']['release'][] = $contents;
1534              }
1535          }
1536          foreach($this->_packageInfo['changelog']['release'] as $index => $changelog) {
1537              if (isset($changelog['version']) &&
1538                    strnatcasecmp($changelog['version']['release'], $releaseversion) == 0) {
1539                  $curlog = $index;
1540              }
1541          }
1542          if (isset($curlog)) {
1543              $this->_packageInfo['changelog']['release'][$curlog] = $contents;
1544          } else {
1545              $this->_packageInfo['changelog']['release'][] = $contents;
1546          }
1547      }
1548  
1549      /**
1550       * Remove the changelog entirely
1551       */
1552      function clearChangeLog()
1553      {
1554          unset($this->_packageInfo['changelog']);
1555      }
1556  }
1557  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics