MailZu 0.8RC3
[bMailZu.git] / lib / pear / PEAR / Task / Postinstallscript / rw.php
blob02b5aa665a7e99a97443c8f50e23933b02cf9951
1 <?php
2 /**
3 * <tasks:postinstallscript> - read/write version
5 * PHP versions 4 and 5
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.
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.11 2006/01/06 04:47:37 cellog Exp $
19 * @link http://pear.php.net/package/PEAR
20 * @since File available since Release 1.4.0a10
22 /**
23 * Base class
25 require_once 'PEAR/Task/Postinstallscript.php';
26 /**
27 * Abstracts the postinstallscript file task xml.
28 * @category pear
29 * @package PEAR
30 * @author Greg Beaver <cellog@php.net>
31 * @copyright 1997-2006 The PHP Group
32 * @license http://www.php.net/license/3_0.txt PHP License 3.0
33 * @version Release: 1.4.11
34 * @link http://pear.php.net/package/PEAR
35 * @since Class available since Release 1.4.0a10
37 class PEAR_Task_Postinstallscript_rw extends PEAR_Task_Postinstallscript
39 /**
40 * parent package file object
42 * @var PEAR_PackageFile_v2_rw
44 var $_pkg;
45 /**
46 * Enter description here...
48 * @param PEAR_PackageFile_v2_rw $pkg
49 * @param PEAR_Config $config
50 * @param PEAR_Frontend $logger
51 * @param array $fileXml
52 * @return PEAR_Task_Postinstallscript_rw
54 function PEAR_Task_Postinstallscript_rw(&$pkg, &$config, &$logger, $fileXml)
56 parent::PEAR_Task_Common($config, $logger, PEAR_TASK_PACKAGE);
57 $this->_contents = $fileXml;
58 $this->_pkg = &$pkg;
59 $this->_params = array();
62 function validate()
64 return $this->validateXml($this->_pkg, $this->_params, $this->config, $this->_contents);
67 function getName()
69 return 'postinstallscript';
72 /**
73 * add a simple <paramgroup> to the post-install script
75 * Order is significant, so call this method in the same
76 * sequence the users should see the paramgroups. The $params
77 * parameter should either be the result of a call to {@link getParam()}
78 * or an array of calls to getParam().
80 * Use {@link addConditionTypeGroup()} to add a <paramgroup> containing
81 * a <conditiontype> tag
82 * @param string $id <paramgroup> id as seen by the script
83 * @param array|false $params array of getParam() calls, or false for no params
84 * @param string|false $instructions
86 function addParamGroup($id, $params = false, $instructions = false)
88 if ($params && isset($params[0]) && !isset($params[1])) {
89 $params = $params[0];
91 $stuff =
92 array(
93 $this->_pkg->getTasksNs() . ':id' => $id,
95 if ($instructions) {
96 $stuff[$this->_pkg->getTasksNs() . ':instructions'] = $instructions;
98 if ($params) {
99 $stuff[$this->_pkg->getTasksNs() . ':param'] = $params;
101 $this->_params[$this->_pkg->getTasksNs() . ':paramgroup'][] = $stuff;
105 * add a complex <paramgroup> to the post-install script with conditions
107 * This inserts a <paramgroup> with
109 * Order is significant, so call this method in the same
110 * sequence the users should see the paramgroups. The $params
111 * parameter should either be the result of a call to {@link getParam()}
112 * or an array of calls to getParam().
114 * Use {@link addParamGroup()} to add a simple <paramgroup>
116 * @param string $id <paramgroup> id as seen by the script
117 * @param string $oldgroup <paramgroup> id of the section referenced by
118 * <conditiontype>
119 * @param string $param name of the <param> from the older section referenced
120 * by <contitiontype>
121 * @param string $value value to match of the parameter
122 * @param string $conditiontype one of '=', '!=', 'preg_match'
123 * @param array|false $params array of getParam() calls, or false for no params
124 * @param string|false $instructions
126 function addConditionTypeGroup($id, $oldgroup, $param, $value, $conditiontype = '=',
127 $params = false, $instructions = false)
129 if ($params && isset($params[0]) && !isset($params[1])) {
130 $params = $params[0];
132 $stuff =
133 array(
134 $this->_pkg->getTasksNs() . ':id' => $id,
136 if ($instructions) {
137 $stuff[$this->_pkg->getTasksNs() . ':instructions'] = $instructions;
139 $stuff[$this->_pkg->getTasksNs() . ':name'] = $oldgroup . '::' . $param;
140 $stuff[$this->_pkg->getTasksNs() . ':conditiontype'] = $conditiontype;
141 $stuff[$this->_pkg->getTasksNs() . ':value'] = $value;
142 if ($params) {
143 $stuff[$this->_pkg->getTasksNs() . ':param'] = $params;
145 $this->_params[$this->_pkg->getTasksNs() . ':paramgroup'][] = $stuff;
148 function getXml()
150 return $this->_params;
154 * Use to set up a param tag for use in creating a paramgroup
155 * @static
157 function getParam($name, $prompt, $type = 'string', $default = null)
159 if ($default !== null) {
160 return
161 array(
162 $this->_pkg->getTasksNs() . ':name' => $name,
163 $this->_pkg->getTasksNs() . ':prompt' => $prompt,
164 $this->_pkg->getTasksNs() . ':type' => $type,
165 $this->_pkg->getTasksNs() . ':default' => $default
168 return
169 array(
170 $this->_pkg->getTasksNs() . ':name' => $name,
171 $this->_pkg->getTasksNs() . ':prompt' => $prompt,
172 $this->_pkg->getTasksNs() . ':type' => $type,