3 * <tasks:postinstallscript> - 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 * @link http://pear.php.net/package/PEAR
13 * @since File available since Release 1.4.0a10
18 require_once 'PEAR/Task/Postinstallscript.php';
20 * Abstracts the postinstallscript file task xml.
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.10.1
27 * @link http://pear.php.net/package/PEAR
28 * @since Class available since Release 1.4.0a10
30 class PEAR_Task_Postinstallscript_rw extends PEAR_Task_Postinstallscript
33 * parent package file object
35 * @var PEAR_PackageFile_v2_rw
39 * Enter description here...
41 * @param PEAR_PackageFile_v2_rw $pkg Package
42 * @param PEAR_Config $config Config
43 * @param PEAR_Frontend $logger Logger
44 * @param array $fileXml XML
46 * @return PEAR_Task_Postinstallscript_rw
48 function __construct(&$pkg, &$config, &$logger, $fileXml)
50 parent::__construct($config, $logger, PEAR_TASK_PACKAGE);
51 $this->_contents = $fileXml;
53 $this->_params = array();
56 public function validate()
58 return $this->validateXml($this->_pkg, $this->_params, $this->config, $this->_contents);
61 public function getName()
63 return 'postinstallscript';
67 * add a simple <paramgroup> to the post-install script
69 * Order is significant, so call this method in the same
70 * sequence the users should see the paramgroups. The $params
71 * parameter should either be the result of a call to {@link getParam()}
72 * or an array of calls to getParam().
74 * Use {@link addConditionTypeGroup()} to add a <paramgroup> containing
75 * a <conditiontype> tag
77 * @param string $id <paramgroup> id as seen by the script
78 * @param array|false $params array of getParam() calls, or false for no params
79 * @param string|false $instructions
81 public function addParamGroup($id, $params = false, $instructions = false)
83 if ($params && isset($params[0]) && !isset($params[1])) {
88 $this->_pkg->getTasksNs().':id' => $id,
91 $stuff[$this->_pkg->getTasksNs().':instructions'] = $instructions;
94 $stuff[$this->_pkg->getTasksNs().':param'] = $params;
96 $this->_params[$this->_pkg->getTasksNs().':paramgroup'][] = $stuff;
100 * Add a complex <paramgroup> to the post-install script with conditions
102 * This inserts a <paramgroup> with
104 * Order is significant, so call this method in the same
105 * sequence the users should see the paramgroups. The $params
106 * parameter should either be the result of a call to {@link getParam()}
107 * or an array of calls to getParam().
109 * Use {@link addParamGroup()} to add a simple <paramgroup>
111 * @param string $id <paramgroup> id as seen by the script
112 * @param string $oldgroup <paramgroup> id of the section referenced by
114 * @param string $param name of the <param> from the older section referenced
116 * @param string $value value to match of the parameter
117 * @param string $conditiontype one of '=', '!=', 'preg_match'
118 * @param array|false $params array of getParam() calls, or false for no params
119 * @param string|false $instructions
121 public function addConditionTypeGroup($id,
125 $conditiontype = '=',
127 $instructions = false
129 if ($params && isset($params[0]) && !isset($params[1])) {
130 $params = $params[0];
133 $this->_pkg->getTasksNs().':id' => $id,
136 $stuff[$this->_pkg->getTasksNs().':instructions'] = $instructions;
138 $stuff[$this->_pkg->getTasksNs().':name'] = $oldgroup.'::'.$param;
139 $stuff[$this->_pkg->getTasksNs().':conditiontype'] = $conditiontype;
140 $stuff[$this->_pkg->getTasksNs().':value'] = $value;
142 $stuff[$this->_pkg->getTasksNs().':param'] = $params;
144 $this->_params[$this->_pkg->getTasksNs().':paramgroup'][] = $stuff;
147 public function getXml()
149 return $this->_params;
153 * Use to set up a param tag for use in creating a paramgroup
155 * @param mixed $name Name of parameter
156 * @param mixed $prompt Prompt
157 * @param string $type Type, defaults to 'string'
158 * @param mixed $default Default value
162 public static function getParam(
163 $name, $prompt, $type = 'string', $default = null
165 if ($default !== null) {
168 $this->_pkg->getTasksNs().':name' => $name,
169 $this->_pkg->getTasksNs().':prompt' => $prompt,
170 $this->_pkg->getTasksNs().':type' => $type,
171 $this->_pkg->getTasksNs().':default' => $default,
177 $this->_pkg->getTasksNs().':name' => $name,
178 $this->_pkg->getTasksNs().':prompt' => $prompt,
179 $this->_pkg->getTasksNs().':type' => $type,