1 | <?php |
---|
2 | /** |
---|
3 | * <tasks:postinstallscript> - read/write version |
---|
4 | * |
---|
5 | * PHP versions 4 and 5 |
---|
6 | * |
---|
7 | * @category pear |
---|
8 | * @package PEAR |
---|
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.0a10 |
---|
15 | */ |
---|
16 | /** |
---|
17 | * Base class |
---|
18 | */ |
---|
19 | require_once 'PEAR/Task/Postinstallscript.php'; |
---|
20 | /** |
---|
21 | * Abstracts the postinstallscript file task xml. |
---|
22 | * @category pear |
---|
23 | * @package PEAR |
---|
24 | * @author Greg Beaver <cellog@php.net> |
---|
25 | * @copyright 1997-2009 The Authors |
---|
26 | * @license http://opensource.org/licenses/bsd-license.php New BSD License |
---|
27 | * @version Release: 1.9.4 |
---|
28 | * @link http://pear.php.net/package/PEAR |
---|
29 | * @since Class available since Release 1.4.0a10 |
---|
30 | */ |
---|
31 | class PEAR_Task_Postinstallscript_rw extends PEAR_Task_Postinstallscript |
---|
32 | { |
---|
33 | /** |
---|
34 | * parent package file object |
---|
35 | * |
---|
36 | * @var PEAR_PackageFile_v2_rw |
---|
37 | */ |
---|
38 | var $_pkg; |
---|
39 | /** |
---|
40 | * Enter description here... |
---|
41 | * |
---|
42 | * @param PEAR_PackageFile_v2_rw $pkg |
---|
43 | * @param PEAR_Config $config |
---|
44 | * @param PEAR_Frontend $logger |
---|
45 | * @param array $fileXml |
---|
46 | * @return PEAR_Task_Postinstallscript_rw |
---|
47 | */ |
---|
48 | function PEAR_Task_Postinstallscript_rw(&$pkg, &$config, &$logger, $fileXml) |
---|
49 | { |
---|
50 | parent::PEAR_Task_Common($config, $logger, PEAR_TASK_PACKAGE); |
---|
51 | $this->_contents = $fileXml; |
---|
52 | $this->_pkg = &$pkg; |
---|
53 | $this->_params = array(); |
---|
54 | } |
---|
55 | |
---|
56 | function validate() |
---|
57 | { |
---|
58 | return $this->validateXml($this->_pkg, $this->_params, $this->config, $this->_contents); |
---|
59 | } |
---|
60 | |
---|
61 | function getName() |
---|
62 | { |
---|
63 | return 'postinstallscript'; |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * add a simple <paramgroup> to the post-install script |
---|
68 | * |
---|
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(). |
---|
73 | * |
---|
74 | * Use {@link addConditionTypeGroup()} to add a <paramgroup> containing |
---|
75 | * a <conditiontype> tag |
---|
76 | * @param string $id <paramgroup> id as seen by the script |
---|
77 | * @param array|false $params array of getParam() calls, or false for no params |
---|
78 | * @param string|false $instructions |
---|
79 | */ |
---|
80 | function addParamGroup($id, $params = false, $instructions = false) |
---|
81 | { |
---|
82 | if ($params && isset($params[0]) && !isset($params[1])) { |
---|
83 | $params = $params[0]; |
---|
84 | } |
---|
85 | $stuff = |
---|
86 | array( |
---|
87 | $this->_pkg->getTasksNs() . ':id' => $id, |
---|
88 | ); |
---|
89 | if ($instructions) { |
---|
90 | $stuff[$this->_pkg->getTasksNs() . ':instructions'] = $instructions; |
---|
91 | } |
---|
92 | if ($params) { |
---|
93 | $stuff[$this->_pkg->getTasksNs() . ':param'] = $params; |
---|
94 | } |
---|
95 | $this->_params[$this->_pkg->getTasksNs() . ':paramgroup'][] = $stuff; |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * add a complex <paramgroup> to the post-install script with conditions |
---|
100 | * |
---|
101 | * This inserts a <paramgroup> with |
---|
102 | * |
---|
103 | * Order is significant, so call this method in the same |
---|
104 | * sequence the users should see the paramgroups. The $params |
---|
105 | * parameter should either be the result of a call to {@link getParam()} |
---|
106 | * or an array of calls to getParam(). |
---|
107 | * |
---|
108 | * Use {@link addParamGroup()} to add a simple <paramgroup> |
---|
109 | * |
---|
110 | * @param string $id <paramgroup> id as seen by the script |
---|
111 | * @param string $oldgroup <paramgroup> id of the section referenced by |
---|
112 | * <conditiontype> |
---|
113 | * @param string $param name of the <param> from the older section referenced |
---|
114 | * by <contitiontype> |
---|
115 | * @param string $value value to match of the parameter |
---|
116 | * @param string $conditiontype one of '=', '!=', 'preg_match' |
---|
117 | * @param array|false $params array of getParam() calls, or false for no params |
---|
118 | * @param string|false $instructions |
---|
119 | */ |
---|
120 | function addConditionTypeGroup($id, $oldgroup, $param, $value, $conditiontype = '=', |
---|
121 | $params = false, $instructions = false) |
---|
122 | { |
---|
123 | if ($params && isset($params[0]) && !isset($params[1])) { |
---|
124 | $params = $params[0]; |
---|
125 | } |
---|
126 | $stuff = array( |
---|
127 | $this->_pkg->getTasksNs() . ':id' => $id, |
---|
128 | ); |
---|
129 | if ($instructions) { |
---|
130 | $stuff[$this->_pkg->getTasksNs() . ':instructions'] = $instructions; |
---|
131 | } |
---|
132 | $stuff[$this->_pkg->getTasksNs() . ':name'] = $oldgroup . '::' . $param; |
---|
133 | $stuff[$this->_pkg->getTasksNs() . ':conditiontype'] = $conditiontype; |
---|
134 | $stuff[$this->_pkg->getTasksNs() . ':value'] = $value; |
---|
135 | if ($params) { |
---|
136 | $stuff[$this->_pkg->getTasksNs() . ':param'] = $params; |
---|
137 | } |
---|
138 | $this->_params[$this->_pkg->getTasksNs() . ':paramgroup'][] = $stuff; |
---|
139 | } |
---|
140 | |
---|
141 | function getXml() |
---|
142 | { |
---|
143 | return $this->_params; |
---|
144 | } |
---|
145 | |
---|
146 | /** |
---|
147 | * Use to set up a param tag for use in creating a paramgroup |
---|
148 | * @static |
---|
149 | */ |
---|
150 | function getParam($name, $prompt, $type = 'string', $default = null) |
---|
151 | { |
---|
152 | if ($default !== null) { |
---|
153 | return |
---|
154 | array( |
---|
155 | $this->_pkg->getTasksNs() . ':name' => $name, |
---|
156 | $this->_pkg->getTasksNs() . ':prompt' => $prompt, |
---|
157 | $this->_pkg->getTasksNs() . ':type' => $type, |
---|
158 | $this->_pkg->getTasksNs() . ':default' => $default |
---|
159 | ); |
---|
160 | } |
---|
161 | return |
---|
162 | array( |
---|
163 | $this->_pkg->getTasksNs() . ':name' => $name, |
---|
164 | $this->_pkg->getTasksNs() . ':prompt' => $prompt, |
---|
165 | $this->_pkg->getTasksNs() . ':type' => $type, |
---|
166 | ); |
---|
167 | } |
---|
168 | } |
---|
169 | ?> |
---|