Редакция 69 | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 69 | Редакция 87 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | /**
|
2 | /**
|
3 | * PEAR_Task_Common, base class for installer tasks
|
3 | * PEAR_Task_Common, base class for installer tasks
|
4 | *
|
4 | *
|
5 | * PHP versions 4 and 5
|
5 | * PHP versions 4 and 5
|
6 | *
|
6 | *
|
7 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
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:
|
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
|
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
|
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.
|
11 | * send a note to license@php.net so we can mail you a copy immediately.
|
12 | *
|
12 | *
|
13 | * @category pear
|
13 | * @category pear
|
14 | * @package PEAR
|
14 | * @package PEAR
|
15 | * @author Greg Beaver <cellog@php.net>
|
15 | * @author Greg Beaver <cellog@php.net>
|
16 | * @copyright 1997-2008 The PHP Group
|
16 | * @copyright 1997-2008 The PHP Group
|
17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
18 | * @version CVS: $Id: Common.php,v 1.18 2008/05/13 21:28:20 cellog Exp $
|
18 | * @version CVS: $Id: Common.php,v 1.18 2008/05/13 21:28:20 cellog Exp $
|
19 | * @link http://pear.php.net/package/PEAR
|
19 | * @link http://pear.php.net/package/PEAR
|
20 | * @since File available since Release 1.4.0a1
|
20 | * @since File available since Release 1.4.0a1
|
21 | */
|
21 | */
|
22 | /**#@+
|
22 | /**#@+
|
23 | * Error codes for task validation routines
|
23 | * Error codes for task validation routines
|
24 | */
|
24 | */
|
25 | define('PEAR_TASK_ERROR_NOATTRIBS', 1); |
25 | define('PEAR_TASK_ERROR_NOATTRIBS', 1); |
26 | define('PEAR_TASK_ERROR_MISSING_ATTRIB', 2); |
26 | define('PEAR_TASK_ERROR_MISSING_ATTRIB', 2); |
27 | define('PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE', 3); |
27 | define('PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE', 3); |
28 | define('PEAR_TASK_ERROR_INVALID', 4); |
28 | define('PEAR_TASK_ERROR_INVALID', 4); |
29 | /**#@-*/
|
29 | /**#@-*/
|
30 | define('PEAR_TASK_PACKAGE', 1); |
30 | define('PEAR_TASK_PACKAGE', 1); |
31 | define('PEAR_TASK_INSTALL', 2); |
31 | define('PEAR_TASK_INSTALL', 2); |
32 | define('PEAR_TASK_PACKAGEANDINSTALL', 3); |
32 | define('PEAR_TASK_PACKAGEANDINSTALL', 3); |
33 | /**
|
33 | /**
|
34 | * A task is an operation that manipulates the contents of a file.
|
34 | * A task is an operation that manipulates the contents of a file.
|
35 | *
|
35 | *
|
36 | * Simple tasks operate on 1 file. Multiple tasks are executed after all files have been
|
36 | * Simple tasks operate on 1 file. Multiple tasks are executed after all files have been
|
37 | * processed and installed, and are designed to operate on all files containing the task.
|
37 | * processed and installed, and are designed to operate on all files containing the task.
|
38 | * The Post-install script task simply takes advantage of the fact that it will be run
|
38 | * The Post-install script task simply takes advantage of the fact that it will be run
|
39 | * after installation, replace is a simple task.
|
39 | * after installation, replace is a simple task.
|
40 | *
|
40 | *
|
41 | * Combining tasks is possible, but ordering is significant.
|
41 | * Combining tasks is possible, but ordering is significant.
|
42 | *
|
42 | *
|
43 | * <file name="test.php" role="php">
|
43 | * <file name="test.php" role="php">
|
44 | * <tasks:replace from="@data-dir@" to="data_dir" type="pear-config"/>
|
44 | * <tasks:replace from="@data-dir@" to="data_dir" type="pear-config"/>
|
45 | * <tasks:postinstallscript/>
|
45 | * <tasks:postinstallscript/>
|
46 | * </file>
|
46 | * </file>
|
47 | *
|
47 | *
|
48 | * This will first replace any instance of @data-dir@ in the test.php file
|
48 | * This will first replace any instance of @data-dir@ in the test.php file
|
49 | * with the path to the current data directory. Then, it will include the
|
49 | * with the path to the current data directory. Then, it will include the
|
50 | * test.php file and run the script it contains to configure the package post-installation.
|
50 | * test.php file and run the script it contains to configure the package post-installation.
|
51 | * @category pear
|
51 | * @category pear
|
52 | * @package PEAR
|
52 | * @package PEAR
|
53 | * @author Greg Beaver <cellog@php.net>
|
53 | * @author Greg Beaver <cellog@php.net>
|
54 | * @copyright 1997-2008 The PHP Group
|
54 | * @copyright 1997-2008 The PHP Group
|
55 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
55 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
56 | * @version Release: 1.7.2
|
56 | * @version Release: 1.7.2
|
57 | * @link http://pear.php.net/package/PEAR
|
57 | * @link http://pear.php.net/package/PEAR
|
58 | * @since Class available since Release 1.4.0a1
|
58 | * @since Class available since Release 1.4.0a1
|
59 | * @abstract
|
59 | * @abstract
|
60 | */
|
60 | */
|
61 | class PEAR_Task_Common
|
61 | class PEAR_Task_Common
|
62 | {
|
62 | {
|
63 | /**
|
63 | /**
|
64 | * Valid types for this version are 'simple' and 'multiple'
|
64 | * Valid types for this version are 'simple' and 'multiple'
|
65 | *
|
65 | *
|
66 | * - simple tasks operate on the contents of a file and write out changes to disk
|
66 | * - simple tasks operate on the contents of a file and write out changes to disk
|
67 | * - multiple tasks operate on the contents of many files and write out the
|
67 | * - multiple tasks operate on the contents of many files and write out the
|
68 | * changes directly to disk
|
68 | * changes directly to disk
|
69 | *
|
69 | *
|
70 | * Child task classes must override this property.
|
70 | * Child task classes must override this property.
|
71 | * @access protected
|
71 | * @access protected
|
72 | */
|
72 | */
|
73 | var $type = 'simple'; |
73 | var $type = 'simple'; |
74 | /**
|
74 | /**
|
75 | * Determines which install phase this task is executed under
|
75 | * Determines which install phase this task is executed under
|
76 | */
|
76 | */
|
77 | var $phase = PEAR_TASK_INSTALL; |
77 | var $phase = PEAR_TASK_INSTALL; |
78 | /**
|
78 | /**
|
79 | * @access protected
|
79 | * @access protected
|
80 | */
|
80 | */
|
81 | var $config; |
81 | var $config; |
82 | /**
|
82 | /**
|
83 | * @access protected
|
83 | * @access protected
|
84 | */
|
84 | */
|
85 | var $registry; |
85 | var $registry; |
86 | /**
|
86 | /**
|
87 | * @access protected
|
87 | * @access protected
|
88 | */
|
88 | */
|
89 | var $logger; |
89 | var $logger; |
90 | /**
|
90 | /**
|
91 | * @access protected
|
91 | * @access protected
|
92 | */
|
92 | */
|
93 | var $installphase; |
93 | var $installphase; |
94 | /**
|
94 | /**
|
95 | * @param PEAR_Config
|
95 | * @param PEAR_Config
|
96 | * @param PEAR_Common
|
96 | * @param PEAR_Common
|
97 | */
|
97 | */
|
98 | function PEAR_Task_Common(&$config, &$logger, $phase) |
98 | function PEAR_Task_Common(&$config, &$logger, $phase) |
99 | {
|
99 | {
|
100 | $this->config = &$config; |
100 | $this->config = &$config; |
101 | $this->registry = &$config->getRegistry(); |
101 | $this->registry = &$config->getRegistry(); |
102 | $this->logger = &$logger; |
102 | $this->logger = &$logger; |
103 | $this->installphase = $phase; |
103 | $this->installphase = $phase; |
104 | if ($this->type == 'multiple') { |
104 | if ($this->type == 'multiple') { |
105 | $GLOBALS['_PEAR_TASK_POSTINSTANCES'][get_class($this)][] = &$this; |
105 | $GLOBALS['_PEAR_TASK_POSTINSTANCES'][get_class($this)][] = &$this; |
106 | }
|
106 | }
|
107 | }
|
107 | }
|
108 | 108 | ||
109 | /**
|
109 | /**
|
110 | * Validate the basic contents of a task tag.
|
110 | * Validate the basic contents of a task tag.
|
111 | * @param PEAR_PackageFile_v2
|
111 | * @param PEAR_PackageFile_v2
|
112 | * @param array
|
112 | * @param array
|
113 | * @param PEAR_Config
|
113 | * @param PEAR_Config
|
114 | * @param array the entire parsed <file> tag
|
114 | * @param array the entire parsed <file> tag
|
115 | * @return true|array On error, return an array in format:
|
115 | * @return true|array On error, return an array in format:
|
116 | * array(PEAR_TASK_ERROR_???[, param1][, param2][, ...])
|
116 | * array(PEAR_TASK_ERROR_???[, param1][, param2][, ...])
|
117 | *
|
117 | *
|
118 | * For PEAR_TASK_ERROR_MISSING_ATTRIB, pass the attribute name in
|
118 | * For PEAR_TASK_ERROR_MISSING_ATTRIB, pass the attribute name in
|
119 | * For PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, pass the attribute name and an array
|
119 | * For PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, pass the attribute name and an array
|
120 | * of legal values in
|
120 | * of legal values in
|
121 | * @static
|
121 | * @static
|
122 | * @abstract
|
122 | * @abstract
|
123 | */
|
123 | */
|
124 | function validateXml($pkg, $xml, $config, $fileXml) |
124 | function validateXml($pkg, $xml, $config, $fileXml) |
125 | {
|
125 | {
|
126 | }
|
126 | }
|
127 | 127 | ||
128 | /**
|
128 | /**
|
129 | * Initialize a task instance with the parameters
|
129 | * Initialize a task instance with the parameters
|
130 | * @param array raw, parsed xml
|
130 | * @param array raw, parsed xml
|
131 | * @param array attributes from the <file> tag containing this task
|
131 | * @param array attributes from the <file> tag containing this task
|
132 | * @param string|null last installed version of this package
|
132 | * @param string|null last installed version of this package
|
133 | * @abstract
|
133 | * @abstract
|
134 | */
|
134 | */
|
135 | function init($xml, $fileAttributes, $lastVersion) |
135 | function init($xml, $fileAttributes, $lastVersion) |
136 | {
|
136 | {
|
137 | }
|
137 | }
|
138 | 138 | ||
139 | /**
|
139 | /**
|
140 | * Begin a task processing session. All multiple tasks will be processed after each file
|
140 | * Begin a task processing session. All multiple tasks will be processed after each file
|
141 | * has been successfully installed, all simple tasks should perform their task here and
|
141 | * has been successfully installed, all simple tasks should perform their task here and
|
142 | * return any errors using the custom throwError() method to allow forward compatibility
|
142 | * return any errors using the custom throwError() method to allow forward compatibility
|
143 | *
|
143 | *
|
144 | * This method MUST NOT write out any changes to disk
|
144 | * This method MUST NOT write out any changes to disk
|
145 | * @param PEAR_PackageFile_v2
|
145 | * @param PEAR_PackageFile_v2
|
146 | * @param string file contents
|
146 | * @param string file contents
|
147 | * @param string the eventual final file location (informational only)
|
147 | * @param string the eventual final file location (informational only)
|
148 | * @return string|false|PEAR_Error false to skip this file, PEAR_Error to fail
|
148 | * @return string|false|PEAR_Error false to skip this file, PEAR_Error to fail
|
149 | * (use $this->throwError), otherwise return the new contents
|
149 | * (use $this->throwError), otherwise return the new contents
|
150 | * @abstract
|
150 | * @abstract
|
151 | */
|
151 | */
|
152 | function startSession($pkg, $contents, $dest) |
152 | function startSession($pkg, $contents, $dest) |
153 | {
|
153 | {
|
154 | }
|
154 | }
|
155 | 155 | ||
156 | /**
|
156 | /**
|
157 | * This method is used to process each of the tasks for a particular multiple class
|
157 | * This method is used to process each of the tasks for a particular multiple class
|
158 | * type. Simple tasks need not implement this method.
|
158 | * type. Simple tasks need not implement this method.
|
159 | * @param array an array of tasks
|
159 | * @param array an array of tasks
|
160 | * @access protected
|
160 | * @access protected
|
161 | * @static
|
161 | * @static
|
162 | * @abstract
|
162 | * @abstract
|
163 | */
|
163 | */
|
164 | function run($tasks) |
164 | function run($tasks) |
165 | {
|
165 | {
|
166 | }
|
166 | }
|
167 | 167 | ||
168 | /**
|
168 | /**
|
169 | * @static
|
169 | * @static
|
170 | * @final
|
170 | * @final
|
171 | */
|
171 | */
|
172 | function hasPostinstallTasks() |
172 | function hasPostinstallTasks() |
173 | {
|
173 | {
|
174 | return isset($GLOBALS['_PEAR_TASK_POSTINSTANCES']); |
174 | return isset($GLOBALS['_PEAR_TASK_POSTINSTANCES']); |
175 | }
|
175 | }
|
176 | 176 | ||
177 | /**
|
177 | /**
|
178 | * @static
|
178 | * @static
|
179 | * @final
|
179 | * @final
|
180 | */
|
180 | */
|
181 | function runPostinstallTasks() |
181 | function runPostinstallTasks() |
182 | {
|
182 | {
|
183 | foreach ($GLOBALS['_PEAR_TASK_POSTINSTANCES'] as $class => $tasks) { |
183 | foreach ($GLOBALS['_PEAR_TASK_POSTINSTANCES'] as $class => $tasks) { |
184 | $err = call_user_func(array($class, 'run'), |
184 | $err = call_user_func(array($class, 'run'), |
185 | $GLOBALS['_PEAR_TASK_POSTINSTANCES'][$class]); |
185 | $GLOBALS['_PEAR_TASK_POSTINSTANCES'][$class]); |
186 | if ($err) { |
186 | if ($err) { |
187 | return PEAR_Task_Common::throwError($err); |
187 | return PEAR_Task_Common::throwError($err); |
188 | }
|
188 | }
|
189 | }
|
189 | }
|
190 | unset($GLOBALS['_PEAR_TASK_POSTINSTANCES']); |
190 | unset($GLOBALS['_PEAR_TASK_POSTINSTANCES']); |
191 | }
|
191 | }
|
192 | 192 | ||
193 | /**
|
193 | /**
|
194 | * Determines whether a role is a script
|
194 | * Determines whether a role is a script
|
195 | * @return bool
|
195 | * @return bool
|
196 | */
|
196 | */
|
197 | function isScript() |
197 | function isScript() |
198 | {
|
198 | {
|
199 | return $this->type == 'script'; |
199 | return $this->type == 'script'; |
200 | }
|
200 | }
|
201 | 201 | ||
202 | function throwError($msg, $code = -1) |
202 | function throwError($msg, $code = -1) |
203 | {
|
203 | {
|
204 | include_once 'PEAR.php'; |
204 | include_once 'PEAR.php'; |
205 | return PEAR::raiseError($msg, $code); |
205 | return PEAR::raiseError($msg, $code); |
206 | }
|
206 | }
|
207 | }
|
207 | }
|
208 | ?>
|
208 | ?>
|