61 if ($fileXml[
'role'] !=
'php') {
63 $fileXml[
'name'].
'" must be role="php"', );
66 $file = $pkg->getFileContents($fileXml[
'name']);
67 if (PEAR::isError($file)) {
68 PEAR::popErrorHandling();
71 $fileXml[
'name'].
'" is not valid: '.
72 $file->getMessage(), );
73 } elseif ($file ===
null) {
75 $fileXml[
'name'].
'" could not be retrieved for processing!', );
77 $analysis = $pkg->analyzeSourceCode($file,
true);
79 PEAR::popErrorHandling();
81 foreach ($pkg->getValidationWarnings() as $warn) {
82 $warnings .= $warn[
'message'].
"\n";
86 $fileXml[
'name'].
'" failed: '.$warnings, );
88 if (count($analysis[
'declared_classes']) != 1) {
89 PEAR::popErrorHandling();
92 $fileXml[
'name'].
'" must declare exactly 1 class', );
94 $class = $analysis[
'declared_classes'][0];
95 if ($class != str_replace(
96 array(
'/',
'.php'), array(
'_',
''),
99 PEAR::popErrorHandling();
102 $fileXml[
'name'].
'" class "'.$class.
'" must be named "'.
104 array(
'/',
'.php'), array(
'_',
''),
106 ).
'_postinstall"', );
108 if (!isset($analysis[
'declared_methods'][$class])) {
109 PEAR::popErrorHandling();
112 $fileXml[
'name'].
'" must declare methods init() and run()', );
114 $methods = array(
'init' => 0,
'run' => 1);
115 foreach ($analysis[
'declared_methods'][$class] as $method) {
116 if (isset($methods[$method])) {
117 unset($methods[$method]);
120 if (count($methods)) {
121 PEAR::popErrorHandling();
124 $fileXml[
'name'].
'" must declare methods init() and run()', );
127 PEAR::popErrorHandling();
128 $definedparams = array();
129 $tasksNamespace = $pkg->getTasksNs().
':';
130 if (!isset($xml[$tasksNamespace.
'paramgroup']) && isset($xml[
'paramgroup'])) {
133 $tasksNamespace =
'';
135 if (isset($xml[$tasksNamespace.
'paramgroup'])) {
136 $params = $xml[$tasksNamespace.
'paramgroup'];
137 if (!is_array($params) || !isset($params[0])) {
138 $params = array($params);
141 if (!isset($param[$tasksNamespace.
'id'])) {
142 return array(PEAR_TASK_ERROR_INVALID,
'Post-install script "'.
143 $fileXml[
'name'].
'" <paramgroup> must have '.
144 'an '.$tasksNamespace.
'id> tag', );
146 if (isset($param[$tasksNamespace.
'name'])) {
147 if (!in_array($param[$tasksNamespace.
'name'], $definedparams)) {
148 return array(PEAR_TASK_ERROR_INVALID,
'Post-install script "'.
149 $fileXml[
'name'].
'" '.$tasksNamespace.
150 'paramgroup> id "'.$param[$tasksNamespace.
'id'].
151 '" parameter "'.$param[$tasksNamespace.
'name'].
152 '" has not been previously defined', );
154 if (!isset($param[$tasksNamespace.
'conditiontype'])) {
155 return array(PEAR_TASK_ERROR_INVALID,
'Post-install script "'.
156 $fileXml[
'name'].
'" '.$tasksNamespace.
157 'paramgroup> id "'.$param[$tasksNamespace.
'id'].
158 '" must have a '.$tasksNamespace.
159 'conditiontype> tag containing either "=", '.
160 '"!=", or "preg_match"', );
163 $param[$tasksNamespace.
'conditiontype'],
164 array(
'=',
'!=',
'preg_match')
167 $fileXml[
'name'].
'" '.$tasksNamespace.
168 'paramgroup> id "'.$param[$tasksNamespace.
'id'].
169 '" must have a '.$tasksNamespace.
170 'conditiontype> tag containing either "=", '.
171 '"!=", or "preg_match"', );
173 if (!isset($param[$tasksNamespace.
'value'])) {
174 return array(PEAR_TASK_ERROR_INVALID,
'Post-install script "'.
175 $fileXml[
'name'].
'" '.$tasksNamespace.
176 'paramgroup> id "'.$param[$tasksNamespace.
'id'].
177 '" must have a '.$tasksNamespace.
178 'value> tag containing expected parameter value', );
181 if (isset($param[$tasksNamespace.
'instructions'])) {
182 if (!is_string($param[$tasksNamespace.
'instructions'])) {
183 return array(PEAR_TASK_ERROR_INVALID,
'Post-install script "'.
184 $fileXml[
'name'].
'" '.$tasksNamespace.
185 'paramgroup> id "'.$param[$tasksNamespace.
'id'].
186 '" '.$tasksNamespace.
'instructions> must be simple text', );
189 if (!isset($param[$tasksNamespace.
'param'])) {
192 $subparams = $param[$tasksNamespace.
'param'];
193 if (!is_array($subparams) || !isset($subparams[0])) {
194 $subparams = array($subparams);
196 foreach ($subparams as $subparam) {
197 if (!isset($subparam[$tasksNamespace.
'name'])) {
198 return array(PEAR_TASK_ERROR_INVALID,
'Post-install script "'.
199 $fileXml[
'name'].
'" parameter for '.
200 $tasksNamespace.
'paramgroup> id "'.
201 $param[$tasksNamespace.
'id'].
'" must have '.
202 'a '.$tasksNamespace.
'name> tag', );
206 $subparam[$tasksNamespace.
'name']
208 return array(PEAR_TASK_ERROR_INVALID,
'Post-install script "'.
209 $fileXml[
'name'].
'" parameter "'.
210 $subparam[$tasksNamespace.
'name'].
211 '" for '.$tasksNamespace.
'paramgroup> id "'.
212 $param[$tasksNamespace.
'id'].
213 '" is not a valid name. Must contain only alphanumeric characters', );
215 if (!isset($subparam[$tasksNamespace.
'prompt'])) {
216 return array(PEAR_TASK_ERROR_INVALID,
'Post-install script "'.
217 $fileXml[
'name'].
'" parameter "'.
218 $subparam[$tasksNamespace.
'name'].
219 '" for '.$tasksNamespace.
'paramgroup> id "'.
220 $param[$tasksNamespace.
'id'].
221 '" must have a '.$tasksNamespace.
'prompt> tag', );
223 if (!isset($subparam[$tasksNamespace.
'type'])) {
224 return array(PEAR_TASK_ERROR_INVALID,
'Post-install script "'.
225 $fileXml[
'name'].
'" parameter "'.
226 $subparam[$tasksNamespace.
'name'].
227 '" for '.$tasksNamespace.
'paramgroup> id "'.
228 $param[$tasksNamespace.
'id'].
229 '" must have a '.$tasksNamespace.
'type> tag', );
231 $definedparams[] = $param[$tasksNamespace.
'id'].
'::'.
232 $subparam[$tasksNamespace.
'name'];