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