3 * PEAR_PackageFile_v2, package.xml version 2.0, read/write version
9 * @author Greg Beaver <cellog@php.net>
10 * @copyright 1997-2009 The Authors
11 * @license http://opensource.org/licenses/bsd-license.php New BSD License
12 * @version CVS: $Id: rw.php 313023 2011-07-06 19:17:11Z dufuz $
13 * @link http://pear.php.net/package/PEAR
14 * @since File available since Release 1.4.0a8
19 require_once 'PEAR/PackageFile/v2.php';
23 * @author Greg Beaver <cellog@php.net>
24 * @copyright 1997-2009 The Authors
25 * @license http://opensource.org/licenses/bsd-license.php New BSD License
26 * @version Release: 1.9.4
27 * @link http://pear.php.net/package/PEAR
28 * @since Class available since Release 1.4.0a8
30 class PEAR_PackageFile_v2_rw extends PEAR_PackageFile_v2
33 * @param string Extension name
34 * @return bool success of operation
36 function setProvidesExtension($extension)
38 if (in_array($this->getPackageType(),
39 array('extsrc', 'extbin', 'zendextsrc', 'zendextbin'))) {
40 if (!isset($this->_packageInfo['providesextension'])) {
41 // ensure that the channel tag is set up in the right location
42 $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
43 array('usesrole', 'usestask', 'srcpackage', 'srcuri', 'phprelease',
44 'extsrcrelease', 'extbinrelease', 'zendextsrcrelease', 'zendextbinrelease',
45 'bundle', 'changelog'),
46 $extension, 'providesextension');
48 $this->_packageInfo['providesextension'] = $extension;
54 function setPackage($package)
57 if (!isset($this->_packageInfo['attribs'])) {
58 $this->_packageInfo = array_merge(array('attribs' => array(
60 'xmlns' => 'http://pear.php.net/dtd/package-2.0',
61 'xmlns:tasks' => 'http://pear.php.net/dtd/tasks-1.0',
62 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
63 'xsi:schemaLocation' => 'http://pear.php.net/dtd/tasks-1.0
64 http://pear.php.net/dtd/tasks-1.0.xsd
65 http://pear.php.net/dtd/package-2.0
66 http://pear.php.net/dtd/package-2.0.xsd',
67 )), $this->_packageInfo);
69 if (!isset($this->_packageInfo['name'])) {
70 return $this->_packageInfo = array_merge(array('name' => $package),
73 $this->_packageInfo['name'] = $package;
77 * set this as a package.xml version 2.1
80 function _setPackageVersion2_1()
84 'xmlns' => 'http://pear.php.net/dtd/package-2.1',
85 'xmlns:tasks' => 'http://pear.php.net/dtd/tasks-1.0',
86 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
87 'xsi:schemaLocation' => 'http://pear.php.net/dtd/tasks-1.0
88 http://pear.php.net/dtd/tasks-1.0.xsd
89 http://pear.php.net/dtd/package-2.1
90 http://pear.php.net/dtd/package-2.1.xsd',
92 if (!isset($this->_packageInfo['attribs'])) {
93 $this->_packageInfo = array_merge(array('attribs' => $info), $this->_packageInfo);
95 $this->_packageInfo['attribs'] = $info;
101 unset($this->_packageInfo['channel']);
103 if (!isset($this->_packageInfo['uri'])) {
104 // ensure that the uri tag is set up in the right location
105 $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
106 array('extends', 'summary', 'description', 'lead',
107 'developer', 'contributor', 'helper', 'date', 'time', 'version',
108 'stability', 'license', 'notes', 'contents', 'compatible',
109 'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
110 'phprelease', 'extsrcrelease', 'zendextsrcrelease', 'zendextbinrelease',
111 'extbinrelease', 'bundle', 'changelog'), $uri, 'uri');
113 $this->_packageInfo['uri'] = $uri;
116 function setChannel($channel)
118 unset($this->_packageInfo['uri']);
120 if (!isset($this->_packageInfo['channel'])) {
121 // ensure that the channel tag is set up in the right location
122 $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
123 array('extends', 'summary', 'description', 'lead',
124 'developer', 'contributor', 'helper', 'date', 'time', 'version',
125 'stability', 'license', 'notes', 'contents', 'compatible',
126 'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
127 'phprelease', 'extsrcrelease', 'zendextsrcrelease', 'zendextbinrelease',
128 'extbinrelease', 'bundle', 'changelog'), $channel, 'channel');
130 $this->_packageInfo['channel'] = $channel;
133 function setExtends($extends)
136 if (!isset($this->_packageInfo['extends'])) {
137 // ensure that the extends tag is set up in the right location
138 $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
139 array('summary', 'description', 'lead',
140 'developer', 'contributor', 'helper', 'date', 'time', 'version',
141 'stability', 'license', 'notes', 'contents', 'compatible',
142 'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
143 'phprelease', 'extsrcrelease', 'zendextsrcrelease', 'zendextbinrelease',
144 'extbinrelease', 'bundle', 'changelog'), $extends, 'extends');
146 $this->_packageInfo['extends'] = $extends;
149 function setSummary($summary)
152 if (!isset($this->_packageInfo['summary'])) {
153 // ensure that the summary tag is set up in the right location
154 $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
155 array('description', 'lead',
156 'developer', 'contributor', 'helper', 'date', 'time', 'version',
157 'stability', 'license', 'notes', 'contents', 'compatible',
158 'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
159 'phprelease', 'extsrcrelease', 'zendextsrcrelease', 'zendextbinrelease',
160 'extbinrelease', 'bundle', 'changelog'), $summary, 'summary');
162 $this->_packageInfo['summary'] = $summary;
165 function setDescription($desc)
168 if (!isset($this->_packageInfo['description'])) {
169 // ensure that the description tag is set up in the right location
170 $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
172 'developer', 'contributor', 'helper', 'date', 'time', 'version',
173 'stability', 'license', 'notes', 'contents', 'compatible',
174 'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
175 'phprelease', 'extsrcrelease', 'zendextsrcrelease', 'zendextbinrelease',
176 'extbinrelease', 'bundle', 'changelog'), $desc, 'description');
178 $this->_packageInfo['description'] = $desc;
182 * Adds a new maintainer - no checking of duplicates is performed, use
183 * updatemaintainer for that purpose.
185 function addMaintainer($role, $handle, $name, $email, $active = 'yes')
187 if (!in_array($role, array('lead', 'developer', 'contributor', 'helper'))) {
190 if (isset($this->_packageInfo[$role])) {
191 if (!isset($this->_packageInfo[$role][0])) {
192 $this->_packageInfo[$role] = array($this->_packageInfo[$role]);
194 $this->_packageInfo[$role][] =
202 $testarr = array('lead',
203 'developer', 'contributor', 'helper', 'date', 'time', 'version',
204 'stability', 'license', 'notes', 'contents', 'compatible',
205 'dependencies', 'providesextension', 'usesrole', 'usestask',
206 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease',
207 'extbinrelease', 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog');
208 foreach (array('lead', 'developer', 'contributor', 'helper') as $testrole) {
209 array_shift($testarr);
210 if ($role == $testrole) {
214 if (!isset($this->_packageInfo[$role])) {
215 // ensure that the extends tag is set up in the right location
216 $this->_packageInfo = $this->_insertBefore($this->_packageInfo, $testarr,
219 $this->_packageInfo[$role] =
230 function updateMaintainer($newrole, $handle, $name, $email, $active = 'yes')
233 foreach (array('lead', 'developer', 'contributor', 'helper') as $role) {
234 if (!isset($this->_packageInfo[$role])) {
237 $info = $this->_packageInfo[$role];
238 if (!isset($info[0])) {
239 if ($info['user'] == $handle) {
244 foreach ($info as $i => $maintainer) {
245 if ($maintainer['user'] == $handle) {
251 if ($found === false) {
252 return $this->addMaintainer($newrole, $handle, $name, $email, $active);
254 if ($found !== false) {
255 if ($found === true) {
256 unset($this->_packageInfo[$role]);
258 unset($this->_packageInfo[$role][$found]);
259 $this->_packageInfo[$role] = array_values($this->_packageInfo[$role]);
262 $this->addMaintainer($newrole, $handle, $name, $email, $active);
266 function deleteMaintainer($handle)
269 foreach (array('lead', 'developer', 'contributor', 'helper') as $role) {
270 if (!isset($this->_packageInfo[$role])) {
273 if (!isset($this->_packageInfo[$role][0])) {
274 $this->_packageInfo[$role] = array($this->_packageInfo[$role]);
276 foreach ($this->_packageInfo[$role] as $i => $maintainer) {
277 if ($maintainer['user'] == $handle) {
282 if ($found !== false) {
283 unset($this->_packageInfo[$role][$found]);
284 if (!count($this->_packageInfo[$role]) && $role == 'lead') {
287 if (!count($this->_packageInfo[$role])) {
288 unset($this->_packageInfo[$role]);
291 $this->_packageInfo[$role] =
292 array_values($this->_packageInfo[$role]);
293 if (count($this->_packageInfo[$role]) == 1) {
294 $this->_packageInfo[$role] = $this->_packageInfo[$role][0];
298 if (count($this->_packageInfo[$role]) == 1) {
299 $this->_packageInfo[$role] = $this->_packageInfo[$role][0];
305 function setReleaseVersion($version)
307 if (isset($this->_packageInfo['version']) &&
308 isset($this->_packageInfo['version']['release'])) {
309 unset($this->_packageInfo['version']['release']);
311 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $version, array(
312 'version' => array('stability', 'license', 'notes', 'contents', 'compatible',
313 'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
314 'phprelease', 'extsrcrelease', 'zendextsrcrelease', 'zendextbinrelease',
315 'extbinrelease', 'bundle', 'changelog'),
316 'release' => array('api')));
320 function setAPIVersion($version)
322 if (isset($this->_packageInfo['version']) &&
323 isset($this->_packageInfo['version']['api'])) {
324 unset($this->_packageInfo['version']['api']);
326 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $version, array(
327 'version' => array('stability', 'license', 'notes', 'contents', 'compatible',
328 'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
329 'phprelease', 'extsrcrelease', 'zendextsrcrelease', 'zendextbinrelease',
330 'extbinrelease', 'bundle', 'changelog'),
336 * snapshot|devel|alpha|beta|stable
338 function setReleaseStability($state)
340 if (isset($this->_packageInfo['stability']) &&
341 isset($this->_packageInfo['stability']['release'])) {
342 unset($this->_packageInfo['stability']['release']);
344 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $state, array(
345 'stability' => array('license', 'notes', 'contents', 'compatible',
346 'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
347 'phprelease', 'extsrcrelease', 'zendextsrcrelease', 'zendextbinrelease',
348 'extbinrelease', 'bundle', 'changelog'),
349 'release' => array('api')));
354 * @param devel|alpha|beta|stable
356 function setAPIStability($state)
358 if (isset($this->_packageInfo['stability']) &&
359 isset($this->_packageInfo['stability']['api'])) {
360 unset($this->_packageInfo['stability']['api']);
362 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $state, array(
363 'stability' => array('license', 'notes', 'contents', 'compatible',
364 'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
365 'phprelease', 'extsrcrelease', 'zendextsrcrelease', 'zendextbinrelease',
366 'extbinrelease', 'bundle', 'changelog'),
371 function setLicense($license, $uri = false, $filesource = false)
373 if (!isset($this->_packageInfo['license'])) {
374 // ensure that the license tag is set up in the right location
375 $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
376 array('notes', 'contents', 'compatible',
377 'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
378 'phprelease', 'extsrcrelease', 'zendextsrcrelease', 'zendextbinrelease',
379 'extbinrelease', 'bundle', 'changelog'), 0, 'license');
381 if ($uri || $filesource) {
384 $attribs['uri'] = $uri;
386 $uri = true; // for test below
388 $attribs['filesource'] = $filesource;
391 $license = $uri ? array('attribs' => $attribs, '_content' => $license) : $license;
392 $this->_packageInfo['license'] = $license;
396 function setNotes($notes)
399 if (!isset($this->_packageInfo['notes'])) {
400 // ensure that the notes tag is set up in the right location
401 $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
402 array('contents', 'compatible',
403 'dependencies', 'providesextension', 'usesrole', 'usestask', 'srcpackage', 'srcuri',
404 'phprelease', 'extsrcrelease', 'zendextsrcrelease', 'zendextbinrelease',
405 'extbinrelease', 'bundle', 'changelog'), $notes, 'notes');
407 $this->_packageInfo['notes'] = $notes;
411 * This is only used at install-time, after all serialization
413 * @param string file name
414 * @param string installed path
416 function setInstalledAs($file, $path)
419 return $this->_packageInfo['filelist'][$file]['installed_as'] = $path;
421 unset($this->_packageInfo['filelist'][$file]['installed_as']);
425 * This is only used at install-time, after all serialization
428 function installedFile($file, $atts)
430 if (isset($this->_packageInfo['filelist'][$file])) {
431 $this->_packageInfo['filelist'][$file] =
432 array_merge($this->_packageInfo['filelist'][$file], $atts['attribs']);
434 $this->_packageInfo['filelist'][$file] = $atts['attribs'];
439 * Reset the listing of package contents
440 * @param string base installation dir for the whole package, if any
442 function clearContents($baseinstall = false)
444 $this->_filesValid = false;
446 if (!isset($this->_packageInfo['contents'])) {
447 $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
449 'dependencies', 'providesextension', 'usesrole', 'usestask',
450 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease',
451 'extbinrelease', 'zendextsrcrelease', 'zendextbinrelease',
452 'bundle', 'changelog'), array(), 'contents');
454 if ($this->getPackageType() != 'bundle') {
455 $this->_packageInfo['contents'] =
456 array('dir' => array('attribs' => array('name' => '/')));
458 $this->_packageInfo['contents']['dir']['attribs']['baseinstalldir'] = $baseinstall;
461 $this->_packageInfo['contents'] = array('bundledpackage' => array());
466 * @param string relative path of the bundled package.
468 function addBundledPackage($path)
470 if ($this->getPackageType() != 'bundle') {
473 $this->_filesValid = false;
475 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $path, array(
476 'contents' => array('compatible', 'dependencies', 'providesextension',
477 'usesrole', 'usestask', 'srcpackage', 'srcuri', 'phprelease',
478 'extsrcrelease', 'extbinrelease', 'zendextsrcrelease', 'zendextbinrelease',
479 'bundle', 'changelog'),
480 'bundledpackage' => array()));
484 * @param string file name
485 * @param PEAR_Task_Common a read/write task
487 function addTaskToFile($filename, $task)
489 if (!method_exists($task, 'getXml')) {
492 if (!method_exists($task, 'getName')) {
495 if (!method_exists($task, 'validate')) {
498 if (!$task->validate()) {
501 if (!isset($this->_packageInfo['contents']['dir']['file'])) {
504 $this->getTasksNs(); // discover the tasks namespace if not done already
505 $files = $this->_packageInfo['contents']['dir']['file'];
506 if (!isset($files[0])) {
507 $files = array($files);
512 foreach ($files as $i => $file) {
513 if (isset($file['attribs'])) {
514 if ($file['attribs']['name'] == $filename) {
516 $t = isset($this->_packageInfo['contents']['dir']['file'][$i]
517 ['attribs'][$this->_tasksNs .
518 ':' . $task->getName()]) ?
519 $this->_packageInfo['contents']['dir']['file'][$i]
520 ['attribs'][$this->_tasksNs .
521 ':' . $task->getName()] : false;
522 if ($t && !isset($t[0])) {
523 $this->_packageInfo['contents']['dir']['file'][$i]
524 [$this->_tasksNs . ':' . $task->getName()] = array($t);
526 $this->_packageInfo['contents']['dir']['file'][$i][$this->_tasksNs .
527 ':' . $task->getName()][] = $task->getXml();
529 $t = isset($this->_packageInfo['contents']['dir']['file']
530 ['attribs'][$this->_tasksNs .
531 ':' . $task->getName()]) ? $this->_packageInfo['contents']['dir']['file']
532 ['attribs'][$this->_tasksNs .
533 ':' . $task->getName()] : false;
534 if ($t && !isset($t[0])) {
535 $this->_packageInfo['contents']['dir']['file']
536 [$this->_tasksNs . ':' . $task->getName()] = array($t);
538 $this->_packageInfo['contents']['dir']['file'][$this->_tasksNs .
539 ':' . $task->getName()][] = $task->getXml();
549 * @param string path to the file
550 * @param string filename
551 * @param array extra attributes
553 function addFile($dir, $file, $attrs)
555 if ($this->getPackageType() == 'bundle') {
558 $this->_filesValid = false;
560 $dir = preg_replace(array('!\\\\+!', '!/+!'), array('/', '/'), $dir);
561 if ($dir == '/' || $dir == '') {
566 $attrs['name'] = $dir . $file;
567 if (!isset($this->_packageInfo['contents'])) {
568 // ensure that the contents tag is set up
569 $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
570 array('compatible', 'dependencies', 'providesextension', 'usesrole', 'usestask',
571 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease',
572 'extbinrelease', 'zendextsrcrelease', 'zendextbinrelease',
573 'bundle', 'changelog'), array(), 'contents');
575 if (isset($this->_packageInfo['contents']['dir']['file'])) {
576 if (!isset($this->_packageInfo['contents']['dir']['file'][0])) {
577 $this->_packageInfo['contents']['dir']['file'] =
578 array($this->_packageInfo['contents']['dir']['file']);
580 $this->_packageInfo['contents']['dir']['file'][]['attribs'] = $attrs;
582 $this->_packageInfo['contents']['dir']['file']['attribs'] = $attrs;
587 * @param string Dependent package name
588 * @param string Dependent package's channel name
589 * @param string minimum version of specified package that this release is guaranteed to be
591 * @param string maximum version of specified package that this release is guaranteed to be
593 * @param string versions of specified package that this release is not compatible with
595 function addCompatiblePackage($name, $channel, $min, $max, $exclude = false)
600 'channel' => $channel,
605 $set['exclude'] = $exclude;
608 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $set, array(
609 'compatible' => array('dependencies', 'providesextension', 'usesrole', 'usestask',
610 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
611 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog')
616 * Removes the <usesrole> tag entirely
618 function resetUsesrole()
620 if (isset($this->_packageInfo['usesrole'])) {
621 unset($this->_packageInfo['usesrole']);
627 * @param string package name or uri
628 * @param string channel name if non-uri
630 function addUsesrole($role, $packageOrUri, $channel = false) {
631 $set = array('role' => $role);
633 $set['package'] = $packageOrUri;
634 $set['channel'] = $channel;
636 $set['uri'] = $packageOrUri;
639 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $set, array(
640 'usesrole' => array('usestask', 'srcpackage', 'srcuri',
641 'phprelease', 'extsrcrelease', 'extbinrelease',
642 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog')
647 * Removes the <usestask> tag entirely
649 function resetUsestask()
651 if (isset($this->_packageInfo['usestask'])) {
652 unset($this->_packageInfo['usestask']);
659 * @param string package name or uri
660 * @param string channel name if non-uri
662 function addUsestask($task, $packageOrUri, $channel = false) {
663 $set = array('task' => $task);
665 $set['package'] = $packageOrUri;
666 $set['channel'] = $channel;
668 $set['uri'] = $packageOrUri;
671 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $set, array(
672 'usestask' => array('srcpackage', 'srcuri',
673 'phprelease', 'extsrcrelease', 'extbinrelease',
674 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog')
679 * Remove all compatible tags
681 function clearCompatible()
683 unset($this->_packageInfo['compatible']);
687 * Reset dependencies prior to adding new ones
691 if (!isset($this->_packageInfo['dependencies'])) {
692 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, array(),
694 'dependencies' => array('providesextension', 'usesrole', 'usestask',
695 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
696 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog')));
698 $this->_packageInfo['dependencies'] = array();
702 * @param string minimum PHP version allowed
703 * @param string maximum PHP version allowed
704 * @param array $exclude incompatible PHP versions
706 function setPhpDep($min, $max = false, $exclude = false)
717 if (count($exclude) == 1) {
718 $exclude = $exclude[0];
720 $dep['exclude'] = $exclude;
722 if (isset($this->_packageInfo['dependencies']['required']['php'])) {
723 $this->_stack->push(__FUNCTION__, 'warning', array('dep' =>
724 $this->_packageInfo['dependencies']['required']['php']),
725 'warning: PHP dependency already exists, overwriting');
726 unset($this->_packageInfo['dependencies']['required']['php']);
728 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
730 'dependencies' => array('providesextension', 'usesrole', 'usestask',
731 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
732 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog'),
733 'required' => array('optional', 'group'),
734 'php' => array('pearinstaller', 'package', 'subpackage', 'extension', 'os', 'arch')
740 * @param string minimum allowed PEAR installer version
741 * @param string maximum allowed PEAR installer version
742 * @param string recommended PEAR installer version
743 * @param array incompatible version of the PEAR installer
745 function setPearinstallerDep($min, $max = false, $recommended = false, $exclude = false)
756 $dep['recommended'] = $recommended;
759 if (count($exclude) == 1) {
760 $exclude = $exclude[0];
762 $dep['exclude'] = $exclude;
764 if (isset($this->_packageInfo['dependencies']['required']['pearinstaller'])) {
765 $this->_stack->push(__FUNCTION__, 'warning', array('dep' =>
766 $this->_packageInfo['dependencies']['required']['pearinstaller']),
767 'warning: PEAR Installer dependency already exists, overwriting');
768 unset($this->_packageInfo['dependencies']['required']['pearinstaller']);
770 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
772 'dependencies' => array('providesextension', 'usesrole', 'usestask',
773 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
774 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog'),
775 'required' => array('optional', 'group'),
776 'pearinstaller' => array('package', 'subpackage', 'extension', 'os', 'arch')
781 * Mark a package as conflicting with this package
782 * @param string package name
783 * @param string package channel
784 * @param string extension this package provides, if any
785 * @param string|false minimum version required
786 * @param string|false maximum version allowed
787 * @param array|false versions to exclude from installation
789 function addConflictingPackageDepWithChannel($name, $channel,
790 $providesextension = false, $min = false, $max = false, $exclude = false)
793 $dep = $this->_constructDep($name, $channel, false, $min, $max, false,
794 $exclude, $providesextension, false, true);
795 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
797 'dependencies' => array('providesextension', 'usesrole', 'usestask',
798 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
799 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog'),
800 'required' => array('optional', 'group'),
801 'package' => array('subpackage', 'extension', 'os', 'arch')
806 * Mark a package as conflicting with this package
807 * @param string package name
808 * @param string package channel
809 * @param string extension this package provides, if any
811 function addConflictingPackageDepWithUri($name, $uri, $providesextension = false)
820 if ($providesextension) {
821 $dep['providesextension'] = $providesextension;
823 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
825 'dependencies' => array('providesextension', 'usesrole', 'usestask',
826 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
827 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog'),
828 'required' => array('optional', 'group'),
829 'package' => array('subpackage', 'extension', 'os', 'arch')
833 function addDependencyGroup($name, $hint)
836 $this->_packageInfo = $this->_mergeTag($this->_packageInfo,
837 array('attribs' => array('name' => $name, 'hint' => $hint)),
839 'dependencies' => array('providesextension', 'usesrole', 'usestask',
840 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
841 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog'),
847 * @param string package name
848 * @param string|false channel name, false if this is a uri
849 * @param string|false uri name, false if this is a channel
850 * @param string|false minimum version required
851 * @param string|false maximum version allowed
852 * @param string|false recommended installation version
853 * @param array|false versions to exclude from installation
854 * @param string extension this package provides, if any
855 * @param bool if true, tells the installer to ignore the default optional dependency group
856 * when installing this package
857 * @param bool if true, tells the installer to negate this dependency (conflicts)
861 function _constructDep($name, $channel, $uri, $min, $max, $recommended, $exclude,
862 $providesextension = false, $nodefault = false,
870 $dep['channel'] = $channel;
881 $dep['recommended'] = $recommended;
884 if (is_array($exclude) && count($exclude) == 1) {
885 $exclude = $exclude[0];
887 $dep['exclude'] = $exclude;
890 $dep['conflicts'] = '';
893 $dep['nodefault'] = '';
895 if ($providesextension) {
896 $dep['providesextension'] = $providesextension;
902 * @param package|subpackage
903 * @param string group name
904 * @param string package name
905 * @param string package channel
906 * @param string minimum version
907 * @param string maximum version
908 * @param string recommended version
909 * @param array|false optional excluded versions
910 * @param string extension this package provides, if any
911 * @param bool if true, tells the installer to ignore the default optional dependency group
912 * when installing this package
913 * @return bool false if the dependency group has not been initialized with
914 * {@link addDependencyGroup()}, or a subpackage is added with
915 * a providesextension
917 function addGroupPackageDepWithChannel($type, $groupname, $name, $channel, $min = false,
918 $max = false, $recommended = false, $exclude = false,
919 $providesextension = false, $nodefault = false)
921 if ($type == 'subpackage' && $providesextension) {
922 return false; // subpackages must be php packages
924 $dep = $this->_constructDep($name, $channel, false, $min, $max, $recommended, $exclude,
925 $providesextension, $nodefault);
926 return $this->_addGroupDependency($type, $dep, $groupname);
930 * @param package|subpackage
931 * @param string group name
932 * @param string package name
933 * @param string package uri
934 * @param string extension this package provides, if any
935 * @param bool if true, tells the installer to ignore the default optional dependency group
936 * when installing this package
937 * @return bool false if the dependency group has not been initialized with
938 * {@link addDependencyGroup()}
940 function addGroupPackageDepWithURI($type, $groupname, $name, $uri, $providesextension = false,
943 if ($type == 'subpackage' && $providesextension) {
944 return false; // subpackages must be php packages
946 $dep = $this->_constructDep($name, false, $uri, false, false, false, false,
947 $providesextension, $nodefault);
948 return $this->_addGroupDependency($type, $dep, $groupname);
952 * @param string group name (must be pre-existing)
953 * @param string extension name
954 * @param string minimum version allowed
955 * @param string maximum version allowed
956 * @param string recommended version
957 * @param array incompatible versions
959 function addGroupExtensionDep($groupname, $name, $min = false, $max = false,
960 $recommended = false, $exclude = false)
963 $dep = $this->_constructDep($name, false, false, $min, $max, $recommended, $exclude);
964 return $this->_addGroupDependency('extension', $dep, $groupname);
968 * @param package|subpackage|extension
969 * @param array dependency contents
970 * @param string name of the dependency group to add this to
974 function _addGroupDependency($type, $dep, $groupname)
976 $arr = array('subpackage', 'extension');
977 if ($type != 'package') {
980 if ($type == 'extension') {
983 if (!isset($this->_packageInfo['dependencies']['group'])) {
986 if (!isset($this->_packageInfo['dependencies']['group'][0])) {
987 if ($this->_packageInfo['dependencies']['group']['attribs']['name'] == $groupname) {
988 $this->_packageInfo['dependencies']['group'] = $this->_mergeTag(
989 $this->_packageInfo['dependencies']['group'], $dep,
999 foreach ($this->_packageInfo['dependencies']['group'] as $i => $group) {
1000 if ($group['attribs']['name'] == $groupname) {
1001 $this->_packageInfo['dependencies']['group'][$i] = $this->_mergeTag(
1002 $this->_packageInfo['dependencies']['group'][$i], $dep,
1006 $this->_isValid = 0;
1016 * @param optional|required
1017 * @param string package name
1018 * @param string package channel
1019 * @param string minimum version
1020 * @param string maximum version
1021 * @param string recommended version
1022 * @param string extension this package provides, if any
1023 * @param bool if true, tells the installer to ignore the default optional dependency group
1024 * when installing this package
1025 * @param array|false optional excluded versions
1027 function addPackageDepWithChannel($type, $name, $channel, $min = false, $max = false,
1028 $recommended = false, $exclude = false,
1029 $providesextension = false, $nodefault = false)
1031 if (!in_array($type, array('optional', 'required'), true)) {
1034 $this->_isValid = 0;
1035 $arr = array('optional', 'group');
1036 if ($type != 'required') {
1039 $dep = $this->_constructDep($name, $channel, false, $min, $max, $recommended, $exclude,
1040 $providesextension, $nodefault);
1041 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1043 'dependencies' => array('providesextension', 'usesrole', 'usestask',
1044 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1045 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog'),
1047 'package' => array('subpackage', 'extension', 'os', 'arch')
1052 * @param optional|required
1053 * @param string name of the package
1054 * @param string uri of the package
1055 * @param string extension this package provides, if any
1056 * @param bool if true, tells the installer to ignore the default optional dependency group
1057 * when installing this package
1059 function addPackageDepWithUri($type, $name, $uri, $providesextension = false,
1062 $this->_isValid = 0;
1063 $arr = array('optional', 'group');
1064 if ($type != 'required') {
1067 $dep = $this->_constructDep($name, false, $uri, false, false, false, false,
1068 $providesextension, $nodefault);
1069 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1071 'dependencies' => array('providesextension', 'usesrole', 'usestask',
1072 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1073 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog'),
1075 'package' => array('subpackage', 'extension', 'os', 'arch')
1080 * @param optional|required optional, required
1081 * @param string package name
1082 * @param string package channel
1083 * @param string minimum version
1084 * @param string maximum version
1085 * @param string recommended version
1086 * @param array incompatible versions
1087 * @param bool if true, tells the installer to ignore the default optional dependency group
1088 * when installing this package
1090 function addSubpackageDepWithChannel($type, $name, $channel, $min = false, $max = false,
1091 $recommended = false, $exclude = false,
1094 $this->_isValid = 0;
1095 $arr = array('optional', 'group');
1096 if ($type != 'required') {
1099 $dep = $this->_constructDep($name, $channel, false, $min, $max, $recommended, $exclude,
1101 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1103 'dependencies' => array('providesextension', 'usesrole', 'usestask',
1104 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1105 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog'),
1107 'subpackage' => array('extension', 'os', 'arch')
1112 * @param optional|required optional, required
1113 * @param string package name
1114 * @param string package uri for download
1115 * @param bool if true, tells the installer to ignore the default optional dependency group
1116 * when installing this package
1118 function addSubpackageDepWithUri($type, $name, $uri, $nodefault = false)
1120 $this->_isValid = 0;
1121 $arr = array('optional', 'group');
1122 if ($type != 'required') {
1125 $dep = $this->_constructDep($name, false, $uri, false, false, false, false, $nodefault);
1126 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1128 'dependencies' => array('providesextension', 'usesrole', 'usestask',
1129 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1130 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog'),
1132 'subpackage' => array('extension', 'os', 'arch')
1137 * @param optional|required optional, required
1138 * @param string extension name
1139 * @param string minimum version
1140 * @param string maximum version
1141 * @param string recommended version
1142 * @param array incompatible versions
1144 function addExtensionDep($type, $name, $min = false, $max = false, $recommended = false,
1147 $this->_isValid = 0;
1148 $arr = array('optional', 'group');
1149 if ($type != 'required') {
1152 $dep = $this->_constructDep($name, false, false, $min, $max, $recommended, $exclude);
1153 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1155 'dependencies' => array('providesextension', 'usesrole', 'usestask',
1156 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1157 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog'),
1159 'extension' => array('os', 'arch')
1164 * @param string Operating system name
1165 * @param boolean true if this package cannot be installed on this OS
1167 function addOsDep($name, $conflicts = false)
1169 $this->_isValid = 0;
1170 $dep = array('name' => $name);
1172 $dep['conflicts'] = '';
1174 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1176 'dependencies' => array('providesextension', 'usesrole', 'usestask',
1177 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1178 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog'),
1179 'required' => array('optional', 'group'),
1180 'os' => array('arch')
1185 * @param string Architecture matching pattern
1186 * @param boolean true if this package cannot be installed on this architecture
1188 function addArchDep($pattern, $conflicts = false)
1190 $this->_isValid = 0;
1191 $dep = array('pattern' => $pattern);
1193 $dep['conflicts'] = '';
1195 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, $dep,
1197 'dependencies' => array('providesextension', 'usesrole', 'usestask',
1198 'srcpackage', 'srcuri', 'phprelease', 'extsrcrelease', 'extbinrelease',
1199 'zendextsrcrelease', 'zendextbinrelease', 'bundle', 'changelog'),
1200 'required' => array('optional', 'group'),
1206 * Set the kind of package, and erase all release tags
1208 * - a php package is a PEAR-style package
1209 * - an extbin package is a PECL-style extension binary
1210 * - an extsrc package is a PECL-style source for a binary
1211 * - an zendextbin package is a PECL-style zend extension binary
1212 * - an zendextsrc package is a PECL-style source for a zend extension binary
1213 * - a bundle package is a collection of other pre-packaged packages
1214 * @param php|extbin|extsrc|zendextsrc|zendextbin|bundle
1215 * @return bool success
1217 function setPackageType($type)
1219 $this->_isValid = 0;
1220 if (!in_array($type, array('php', 'extbin', 'extsrc', 'zendextsrc',
1221 'zendextbin', 'bundle'))) {
1225 if (in_array($type, array('zendextsrc', 'zendextbin'))) {
1226 $this->_setPackageVersion2_1();
1229 if ($type != 'bundle') {
1233 foreach (array('phprelease', 'extbinrelease', 'extsrcrelease',
1234 'zendextsrcrelease', 'zendextbinrelease', 'bundle') as $test) {
1235 unset($this->_packageInfo[$test]);
1238 if (!isset($this->_packageInfo[$type])) {
1239 // ensure that the release tag is set up
1240 $this->_packageInfo = $this->_insertBefore($this->_packageInfo, array('changelog'),
1244 $this->_packageInfo[$type] = array();
1249 * @return bool true if package type is set up
1251 function addRelease()
1253 if ($type = $this->getPackageType()) {
1254 if ($type != 'bundle') {
1257 $this->_packageInfo = $this->_mergeTag($this->_packageInfo, array(),
1258 array($type => array('changelog')));
1265 * Get the current release tag in order to add to it
1266 * @param bool returns only releases that have installcondition if true
1267 * @return array|null
1269 function &_getCurrentRelease($strict = true)
1271 if ($p = $this->getPackageType()) {
1273 if ($p == 'extsrc' || $p == 'zendextsrc') {
1278 if ($p != 'bundle') {
1281 if (isset($this->_packageInfo[$p][0])) {
1282 return $this->_packageInfo[$p][count($this->_packageInfo[$p]) - 1];
1284 return $this->_packageInfo[$p];
1293 * Add a file to the current release that should be installed under a different name
1294 * @param string <contents> path to file
1295 * @param string name the file should be installed as
1297 function addInstallAs($path, $as)
1299 $r = &$this->_getCurrentRelease();
1303 $this->_isValid = 0;
1304 $r = $this->_mergeTag($r, array('attribs' => array('name' => $path, 'as' => $as)),
1306 'filelist' => array(),
1307 'install' => array('ignore')
1312 * Add a file to the current release that should be ignored
1313 * @param string <contents> path to file
1314 * @return bool success of operation
1316 function addIgnore($path)
1318 $r = &$this->_getCurrentRelease();
1322 $this->_isValid = 0;
1323 $r = $this->_mergeTag($r, array('attribs' => array('name' => $path)),
1325 'filelist' => array(),
1331 * Add an extension binary package for this extension source code release
1333 * Note that the package must be from the same channel as the extension source package
1336 function addBinarypackage($package)
1338 if ($this->getPackageType() != 'extsrc' && $this->getPackageType() != 'zendextsrc') {
1341 $r = &$this->_getCurrentRelease(false);
1345 $this->_isValid = 0;
1346 $r = $this->_mergeTag($r, $package,
1348 'binarypackage' => array('filelist'),
1353 * Add a configureoption to an extension source package
1358 function addConfigureOption($name, $prompt, $default = null)
1360 if ($this->getPackageType() != 'extsrc' && $this->getPackageType() != 'zendextsrc') {
1364 $r = &$this->_getCurrentRelease(false);
1369 $opt = array('attribs' => array('name' => $name, 'prompt' => $prompt));
1370 if ($default !== null) {
1371 $opt['attribs']['default'] = $default;
1374 $this->_isValid = 0;
1375 $r = $this->_mergeTag($r, $opt,
1377 'configureoption' => array('binarypackage', 'filelist'),
1382 * Set an installation condition based on php version for the current release set
1383 * @param string minimum version
1384 * @param string maximum version
1385 * @param false|array incompatible versions of PHP
1387 function setPhpInstallCondition($min, $max, $exclude = false)
1389 $r = &$this->_getCurrentRelease();
1393 $this->_isValid = 0;
1394 if (isset($r['installconditions']['php'])) {
1395 unset($r['installconditions']['php']);
1397 $dep = array('min' => $min, 'max' => $max);
1399 if (is_array($exclude) && count($exclude) == 1) {
1400 $exclude = $exclude[0];
1402 $dep['exclude'] = $exclude;
1404 if ($this->getPackageType() == 'extsrc' || $this->getPackageType() == 'zendextsrc') {
1405 $r = $this->_mergeTag($r, $dep,
1407 'installconditions' => array('configureoption', 'binarypackage',
1409 'php' => array('extension', 'os', 'arch')
1412 $r = $this->_mergeTag($r, $dep,
1414 'installconditions' => array('filelist'),
1415 'php' => array('extension', 'os', 'arch')
1421 * @param optional|required optional, required
1422 * @param string extension name
1423 * @param string minimum version
1424 * @param string maximum version
1425 * @param string recommended version
1426 * @param array incompatible versions
1428 function addExtensionInstallCondition($name, $min = false, $max = false, $recommended = false,
1431 $r = &$this->_getCurrentRelease();
1435 $this->_isValid = 0;
1436 $dep = $this->_constructDep($name, false, false, $min, $max, $recommended, $exclude);
1437 if ($this->getPackageType() == 'extsrc' || $this->getPackageType() == 'zendextsrc') {
1438 $r = $this->_mergeTag($r, $dep,
1440 'installconditions' => array('configureoption', 'binarypackage',
1442 'extension' => array('os', 'arch')
1445 $r = $this->_mergeTag($r, $dep,
1447 'installconditions' => array('filelist'),
1448 'extension' => array('os', 'arch')
1454 * Set an installation condition based on operating system for the current release set
1455 * @param string OS name
1456 * @param bool whether this OS is incompatible with the current release
1458 function setOsInstallCondition($name, $conflicts = false)
1460 $r = &$this->_getCurrentRelease();
1464 $this->_isValid = 0;
1465 if (isset($r['installconditions']['os'])) {
1466 unset($r['installconditions']['os']);
1468 $dep = array('name' => $name);
1470 $dep['conflicts'] = '';
1472 if ($this->getPackageType() == 'extsrc' || $this->getPackageType() == 'zendextsrc') {
1473 $r = $this->_mergeTag($r, $dep,
1475 'installconditions' => array('configureoption', 'binarypackage',
1477 'os' => array('arch')
1480 $r = $this->_mergeTag($r, $dep,
1482 'installconditions' => array('filelist'),
1483 'os' => array('arch')
1489 * Set an installation condition based on architecture for the current release set
1490 * @param string architecture pattern
1491 * @param bool whether this arch is incompatible with the current release
1493 function setArchInstallCondition($pattern, $conflicts = false)
1495 $r = &$this->_getCurrentRelease();
1499 $this->_isValid = 0;
1500 if (isset($r['installconditions']['arch'])) {
1501 unset($r['installconditions']['arch']);
1503 $dep = array('pattern' => $pattern);
1505 $dep['conflicts'] = '';
1507 if ($this->getPackageType() == 'extsrc' || $this->getPackageType() == 'zendextsrc') {
1508 $r = $this->_mergeTag($r, $dep,
1510 'installconditions' => array('configureoption', 'binarypackage',
1515 $r = $this->_mergeTag($r, $dep,
1517 'installconditions' => array('filelist'),
1524 * For extension binary releases, this is used to specify either the
1525 * static URI to a source package, or the package name and channel of the extsrc/zendextsrc
1526 * package it is based on.
1527 * @param string Package name, or full URI to source package (extsrc/zendextsrc type)
1529 function setSourcePackage($packageOrUri)
1531 $this->_isValid = 0;
1532 if (isset($this->_packageInfo['channel'])) {
1533 $this->_packageInfo = $this->_insertBefore($this->_packageInfo, array('phprelease',
1534 'extsrcrelease', 'extbinrelease', 'zendextsrcrelease', 'zendextbinrelease',
1535 'bundle', 'changelog'),
1536 $packageOrUri, 'srcpackage');
1538 $this->_packageInfo = $this->_insertBefore($this->_packageInfo, array('phprelease',
1539 'extsrcrelease', 'extbinrelease', 'zendextsrcrelease', 'zendextbinrelease',
1540 'bundle', 'changelog'), $packageOrUri, 'srcuri');
1545 * Generate a valid change log entry from the current package.xml
1546 * @param string|false
1548 function generateChangeLogEntry($notes = false)
1553 'release' => $this->getVersion('release'),
1554 'api' => $this->getVersion('api'),
1557 $this->getStability(),
1558 'date' => $this->getDate(),
1559 'license' => $this->getLicense(true),
1560 'notes' => $notes ? $notes : $this->getNotes()
1565 * @param string release version to set change log notes for
1566 * @param array output of {@link generateChangeLogEntry()}
1568 function setChangelogEntry($releaseversion, $contents)
1570 if (!isset($this->_packageInfo['changelog'])) {
1571 $this->_packageInfo['changelog']['release'] = $contents;
1574 if (!isset($this->_packageInfo['changelog']['release'][0])) {
1575 if ($this->_packageInfo['changelog']['release']['version']['release'] == $releaseversion) {
1576 $this->_packageInfo['changelog']['release'] = array(
1577 $this->_packageInfo['changelog']['release']);
1579 $this->_packageInfo['changelog']['release'] = array(
1580 $this->_packageInfo['changelog']['release']);
1581 return $this->_packageInfo['changelog']['release'][] = $contents;
1584 foreach($this->_packageInfo['changelog']['release'] as $index => $changelog) {
1585 if (isset($changelog['version']) &&
1586 strnatcasecmp($changelog['version']['release'], $releaseversion) == 0) {
1590 if (isset($curlog)) {
1591 $this->_packageInfo['changelog']['release'][$curlog] = $contents;
1593 $this->_packageInfo['changelog']['release'][] = $contents;
1598 * Remove the changelog entirely
1600 function clearChangeLog()
1602 unset($this->_packageInfo['changelog']);