Bearsampp 2026.9.23
Loading...
Searching...
No Matches
PEAR_Task_Postinstallscript Class Reference
Inheritance diagram for PEAR_Task_Postinstallscript:
Collaboration diagram for PEAR_Task_Postinstallscript:

Public Member Functions

 _stripNamespace ($params=null)
 init ($xml, $fileattribs, $lastversion)
 startSession ($pkg, $contents, $dest)
Public Member Functions inherited from PEAR_Task_Common
 __construct (&$config, &$logger, $phase)
 isScript ()
 throwError ($msg, $code=-1)

Static Public Member Functions

static run ($tasks)
static validateXml ($pkg, $xml, $config, $fileXml)
Static Public Member Functions inherited from PEAR_Task_Common
static hasPostinstallTasks ()
static runPostinstallTasks ()

Data Fields

 $_class
 $_contents
 $_obj
 $_params
 $_pkg
 $phase = PEAR_TASK_INSTALL
 $type = 'script'
Data Fields inherited from PEAR_Task_Common
 $logger
 $phase = PEAR_TASK_INSTALL

Additional Inherited Members

Protected Attributes inherited from PEAR_Task_Common
 $config
 $installphase
 $registry
 $type = 'simple'

Detailed Description

Definition at line 34 of file Postinstallscript.php.

Member Function Documentation

◆ _stripNamespace()

_stripNamespace ( $params = null)

Strip the tasks: namespace from internal params

@access private

Definition at line 262 of file Postinstallscript.php.

263 {
264 if ($params === null) {
265 $params = array();
266 if (!is_array($this->_params)) {
267 return;
268 }
269 foreach ($this->_params as $i => $param) {
270 if (is_array($param)) {
271 $param = $this->_stripNamespace($param);
272 }
273 $params[str_replace($this->_pkg->getTasksNs().':', '', $i)] = $param;
274 }
275 $this->_params = $params;
276 } else {
277 $newparams = array();
278 foreach ($params as $i => $param) {
279 if (is_array($param)) {
280 $param = $this->_stripNamespace($param);
281 }
282 $newparams[str_replace($this->_pkg->getTasksNs().':', '', $i)] = $param;
283 }
284
285 return $newparams;
286 }
287 }

References _stripNamespace().

Referenced by _stripNamespace(), and startSession().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

init ( $xml,
$fileattribs,
$lastversion )

Initialize a task instance with the parameters

Parameters
array$xmlraw, parsed xml
array$fileattribsattributes from the <file> tag containing this task
string | null$lastversionlast installed version of this package, if any (useful for upgrades)

Reimplemented from PEAR_Task_Common.

Definition at line 248 of file Postinstallscript.php.

249 {
250 $this->_class = str_replace('/', '_', $fileattribs['name']);
251 $this->_filename = $fileattribs['name'];
252 $this->_class = str_replace('.php', '', $this->_class).'_postinstall';
253 $this->_params = $xml;
254 $this->_lastversion = $lastversion;
255 }

◆ run()

run ( $tasks)
static

No longer used

See also
PEAR_PackageFile_v2\runPostinstallScripts()
Parameters
arrayan array of tasks
stringinstall or upgrade @access protected

Reimplemented from PEAR_Task_Common.

Definition at line 347 of file Postinstallscript.php.

348 {
349 }

◆ startSession()

startSession ( $pkg,
$contents,
$dest )

Unlike other tasks, the installed file name is passed in instead of the file contents, because this task is handled post-installation

Parameters
mixed$pkgPEAR_PackageFile_v1|PEAR_PackageFile_v2
string$contentsfile name
string$destthe eventual final file location (informational only)
Returns
bool|PEAR_Error false to skip this file, PEAR_Error to fail (use $this->throwError)

Reimplemented from PEAR_Task_Common.

Definition at line 300 of file Postinstallscript.php.

301 {
302 if ($this->installphase != PEAR_TASK_INSTALL) {
303 return false;
304 }
305 // remove the tasks: namespace if present
306 $this->_pkg = $pkg;
307 $this->_stripNamespace();
308 $this->logger->log(
309 0, 'Including external post-installation script "'.
310 $contents.'" - any errors are in this script'
311 );
312 include_once $contents;
313 if (class_exists($this->_class)) {
314 $this->logger->log(0, 'Inclusion succeeded');
315 } else {
316 return $this->throwError(
317 'init of post-install script class "'.$this->_class
318 .'" failed'
319 );
320 }
321 $this->_obj = new $this->_class();
322 $this->logger->log(1, 'running post-install script "'.$this->_class.'->init()"');
323 PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
324 $res = $this->_obj->init($this->config, $pkg, $this->_lastversion);
325 PEAR::popErrorHandling();
326 if ($res) {
327 $this->logger->log(0, 'init succeeded');
328 } else {
329 return $this->throwError(
330 'init of post-install script "'.$this->_class.
331 '->init()" failed'
332 );
333 }
334 $this->_contents = $contents;
335
336 return true;
337 }
const PEAR_ERROR_RETURN
Definition PEAR.php:24
const PEAR_TASK_INSTALL
Definition Common.php:24
throwError($msg, $code=-1)
Definition Common.php:201

References _stripNamespace(), PEAR_ERROR_RETURN, PEAR_TASK_INSTALL, and PEAR_Task_Common\throwError().

Here is the call graph for this function:

◆ validateXml()

validateXml ( $pkg,
$xml,
$config,
$fileXml )
static

Validate the raw xml at parsing-time.

This also attempts to validate the script to make sure it meets the criteria for a post-install script

Parameters
PEAR_PackageFile_v2
arrayThe XML contents of the <postinstallscript> tag
PEAR_Config
arraythe entire parsed <file> tag

Reimplemented from PEAR_Task_Common.

Definition at line 59 of file Postinstallscript.php.

60 {
61 if ($fileXml['role'] != 'php') {
62 return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
63 $fileXml['name'].'" must be role="php"', );
64 }
65 PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
66 $file = $pkg->getFileContents($fileXml['name']);
67 if (PEAR::isError($file)) {
68 PEAR::popErrorHandling();
69
70 return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
71 $fileXml['name'].'" is not valid: '.
72 $file->getMessage(), );
73 } elseif ($file === null) {
74 return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
75 $fileXml['name'].'" could not be retrieved for processing!', );
76 } else {
77 $analysis = $pkg->analyzeSourceCode($file, true);
78 if (!$analysis) {
79 PEAR::popErrorHandling();
80 $warnings = '';
81 foreach ($pkg->getValidationWarnings() as $warn) {
82 $warnings .= $warn['message']."\n";
83 }
84
85 return array(PEAR_TASK_ERROR_INVALID, 'Analysis of post-install script "'.
86 $fileXml['name'].'" failed: '.$warnings, );
87 }
88 if (count($analysis['declared_classes']) != 1) {
89 PEAR::popErrorHandling();
90
91 return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
92 $fileXml['name'].'" must declare exactly 1 class', );
93 }
94 $class = $analysis['declared_classes'][0];
95 if ($class != str_replace(
96 array('/', '.php'), array('_', ''),
97 $fileXml['name']
98 ).'_postinstall') {
99 PEAR::popErrorHandling();
100
101 return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
102 $fileXml['name'].'" class "'.$class.'" must be named "'.
103 str_replace(
104 array('/', '.php'), array('_', ''),
105 $fileXml['name']
106 ).'_postinstall"', );
107 }
108 if (!isset($analysis['declared_methods'][$class])) {
109 PEAR::popErrorHandling();
110
111 return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
112 $fileXml['name'].'" must declare methods init() and run()', );
113 }
114 $methods = array('init' => 0, 'run' => 1);
115 foreach ($analysis['declared_methods'][$class] as $method) {
116 if (isset($methods[$method])) {
117 unset($methods[$method]);
118 }
119 }
120 if (count($methods)) {
121 PEAR::popErrorHandling();
122
123 return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
124 $fileXml['name'].'" must declare methods init() and run()', );
125 }
126 }
127 PEAR::popErrorHandling();
128 $definedparams = array();
129 $tasksNamespace = $pkg->getTasksNs().':';
130 if (!isset($xml[$tasksNamespace.'paramgroup']) && isset($xml['paramgroup'])) {
131 // in order to support the older betas, which did not expect internal tags
132 // to also use the namespace
133 $tasksNamespace = '';
134 }
135 if (isset($xml[$tasksNamespace.'paramgroup'])) {
136 $params = $xml[$tasksNamespace.'paramgroup'];
137 if (!is_array($params) || !isset($params[0])) {
138 $params = array($params);
139 }
140 foreach ($params as $param) {
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', );
145 }
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', );
153 }
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"', );
161 }
162 if (!in_array(
163 $param[$tasksNamespace.'conditiontype'],
164 array('=', '!=', 'preg_match')
165 )) {
166 return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
167 $fileXml['name'].'" '.$tasksNamespace.
168 'paramgroup> id "'.$param[$tasksNamespace.'id'].
169 '" must have a '.$tasksNamespace.
170 'conditiontype> tag containing either "=", '.
171 '"!=", or "preg_match"', );
172 }
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', );
179 }
180 }
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', );
187 }
188 }
189 if (!isset($param[$tasksNamespace.'param'])) {
190 continue; // <param> is no longer required
191 }
192 $subparams = $param[$tasksNamespace.'param'];
193 if (!is_array($subparams) || !isset($subparams[0])) {
194 $subparams = array($subparams);
195 }
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', );
203 }
204 if (!preg_match(
205 '/[a-zA-Z0-9]+/',
206 $subparam[$tasksNamespace.'name']
207 )) {
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', );
214 }
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', );
222 }
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', );
230 }
231 $definedparams[] = $param[$tasksNamespace.'id'].'::'.
232 $subparam[$tasksNamespace.'name'];
233 }
234 }
235 }
236
237 return true;
238 }
const PEAR_TASK_ERROR_INVALID
Definition Common.php:21
foreach( $bearsamppBins->getApache() ->getModulesFromConf() as $moduleName=> $moduleStatus) foreach($bearsamppBins->getApache() ->getAlias() as $alias) foreach( $bearsamppBins->getApache() ->getWwwDirectories() as $wwwDirectory) foreach( $bearsamppBins->getApache() ->getVhostsUrl() as $vhost=> $enabled)
if('@'. 'php_dir'.'@'=='@'. 'php_dir'.'@')
Definition helper.inc:2

References PEAR_Task_Common\$config, foreach, if, PEAR_ERROR_RETURN, and PEAR_TASK_ERROR_INVALID.

Referenced by PEAR_Task_Postinstallscript_rw\validate().

Here is the caller graph for this function:

Field Documentation

◆ $_class

$_class

Definition at line 37 of file Postinstallscript.php.

◆ $_contents

$_contents

Definition at line 45 of file Postinstallscript.php.

◆ $_obj

$_obj

Definition at line 39 of file Postinstallscript.php.

◆ $_params

$_params

Definition at line 38 of file Postinstallscript.php.

Referenced by PEAR_Task_Postinstallscript_rw\getXml().

◆ $_pkg

$_pkg

Definition at line 44 of file Postinstallscript.php.

◆ $phase

Definition at line 46 of file Postinstallscript.php.

◆ $type

$type = 'script'

Definition at line 36 of file Postinstallscript.php.

Referenced by PEAR_Task_Postinstallscript_rw\getParam().


The documentation for this class was generated from the following file: