| 94 |
jpm |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* PEAR_Common, the base class for the PEAR Installer
|
|
|
4 |
*
|
|
|
5 |
* PHP versions 4 and 5
|
|
|
6 |
*
|
|
|
7 |
* @category pear
|
|
|
8 |
* @package PEAR
|
|
|
9 |
* @author Stig Bakken <ssb@php.net>
|
|
|
10 |
* @author Tomas V. V. Cox <cox@idecnet.com>
|
|
|
11 |
* @author Greg Beaver <cellog@php.net>
|
| 187 |
mathias |
12 |
* @copyright 1997-2009 The Authors
|
|
|
13 |
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
| 94 |
jpm |
14 |
* @link http://pear.php.net/package/PEAR
|
|
|
15 |
* @since File available since Release 0.1.0
|
|
|
16 |
* @deprecated File deprecated since Release 1.4.0a1
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Include error handling
|
|
|
21 |
*/
|
|
|
22 |
require_once 'PEAR.php';
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* PEAR_Common error when an invalid PHP file is passed to PEAR_Common::analyzeSourceCode()
|
|
|
26 |
*/
|
|
|
27 |
define('PEAR_COMMON_ERROR_INVALIDPHP', 1);
|
|
|
28 |
define('_PEAR_COMMON_PACKAGE_NAME_PREG', '[A-Za-z][a-zA-Z0-9_]+');
|
| 187 |
mathias |
29 |
define('PEAR_COMMON_PACKAGE_NAME_PREG', '/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '\\z/');
|
| 94 |
jpm |
30 |
|
|
|
31 |
// this should allow: 1, 1.0, 1.0RC1, 1.0dev, 1.0dev123234234234, 1.0a1, 1.0b1, 1.0pl1
|
|
|
32 |
define('_PEAR_COMMON_PACKAGE_VERSION_PREG', '\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?');
|
| 187 |
mathias |
33 |
define('PEAR_COMMON_PACKAGE_VERSION_PREG', '/^' . _PEAR_COMMON_PACKAGE_VERSION_PREG . '\\z/i');
|
| 94 |
jpm |
34 |
|
|
|
35 |
// XXX far from perfect :-)
|
|
|
36 |
define('_PEAR_COMMON_PACKAGE_DOWNLOAD_PREG', '(' . _PEAR_COMMON_PACKAGE_NAME_PREG .
|
|
|
37 |
')(-([.0-9a-zA-Z]+))?');
|
|
|
38 |
define('PEAR_COMMON_PACKAGE_DOWNLOAD_PREG', '/^' . _PEAR_COMMON_PACKAGE_DOWNLOAD_PREG .
|
| 187 |
mathias |
39 |
'\\z/');
|
| 94 |
jpm |
40 |
|
|
|
41 |
define('_PEAR_CHANNELS_NAME_PREG', '[A-Za-z][a-zA-Z0-9\.]+');
|
| 187 |
mathias |
42 |
define('PEAR_CHANNELS_NAME_PREG', '/^' . _PEAR_CHANNELS_NAME_PREG . '\\z/');
|
| 94 |
jpm |
43 |
|
|
|
44 |
// this should allow any dns or IP address, plus a path - NO UNDERSCORES ALLOWED
|
|
|
45 |
define('_PEAR_CHANNELS_SERVER_PREG', '[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*(\/[a-zA-Z0-9\-]+)*');
|
| 187 |
mathias |
46 |
define('PEAR_CHANNELS_SERVER_PREG', '/^' . _PEAR_CHANNELS_SERVER_PREG . '\\z/i');
|
| 94 |
jpm |
47 |
|
|
|
48 |
define('_PEAR_CHANNELS_PACKAGE_PREG', '(' ._PEAR_CHANNELS_SERVER_PREG . ')\/('
|
|
|
49 |
. _PEAR_COMMON_PACKAGE_NAME_PREG . ')');
|
| 187 |
mathias |
50 |
define('PEAR_CHANNELS_PACKAGE_PREG', '/^' . _PEAR_CHANNELS_PACKAGE_PREG . '\\z/i');
|
| 94 |
jpm |
51 |
|
|
|
52 |
define('_PEAR_COMMON_CHANNEL_DOWNLOAD_PREG', '(' . _PEAR_CHANNELS_NAME_PREG . ')::('
|
|
|
53 |
. _PEAR_COMMON_PACKAGE_NAME_PREG . ')(-([.0-9a-zA-Z]+))?');
|
| 187 |
mathias |
54 |
define('PEAR_COMMON_CHANNEL_DOWNLOAD_PREG', '/^' . _PEAR_COMMON_CHANNEL_DOWNLOAD_PREG . '\\z/');
|
| 94 |
jpm |
55 |
|
|
|
56 |
/**
|
|
|
57 |
* List of temporary files and directories registered by
|
|
|
58 |
* PEAR_Common::addTempFile().
|
|
|
59 |
* @var array
|
|
|
60 |
*/
|
|
|
61 |
$GLOBALS['_PEAR_Common_tempfiles'] = array();
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
* Valid maintainer roles
|
|
|
65 |
* @var array
|
|
|
66 |
*/
|
|
|
67 |
$GLOBALS['_PEAR_Common_maintainer_roles'] = array('lead','developer','contributor','helper');
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Valid release states
|
|
|
71 |
* @var array
|
|
|
72 |
*/
|
|
|
73 |
$GLOBALS['_PEAR_Common_release_states'] = array('alpha','beta','stable','snapshot','devel');
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* Valid dependency types
|
|
|
77 |
* @var array
|
|
|
78 |
*/
|
|
|
79 |
$GLOBALS['_PEAR_Common_dependency_types'] = array('pkg','ext','php','prog','ldlib','rtlib','os','websrv','sapi');
|
|
|
80 |
|
|
|
81 |
/**
|
|
|
82 |
* Valid dependency relations
|
|
|
83 |
* @var array
|
|
|
84 |
*/
|
|
|
85 |
$GLOBALS['_PEAR_Common_dependency_relations'] = array('has','eq','lt','le','gt','ge','not', 'ne');
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* Valid file roles
|
|
|
89 |
* @var array
|
|
|
90 |
*/
|
|
|
91 |
$GLOBALS['_PEAR_Common_file_roles'] = array('php','ext','test','doc','data','src','script');
|
|
|
92 |
|
|
|
93 |
/**
|
|
|
94 |
* Valid replacement types
|
|
|
95 |
* @var array
|
|
|
96 |
*/
|
|
|
97 |
$GLOBALS['_PEAR_Common_replacement_types'] = array('php-const', 'pear-config', 'package-info');
|
|
|
98 |
|
|
|
99 |
/**
|
|
|
100 |
* Valid "provide" types
|
|
|
101 |
* @var array
|
|
|
102 |
*/
|
|
|
103 |
$GLOBALS['_PEAR_Common_provide_types'] = array('ext', 'prog', 'class', 'function', 'feature', 'api');
|
|
|
104 |
|
|
|
105 |
/**
|
|
|
106 |
* Valid "provide" types
|
|
|
107 |
* @var array
|
|
|
108 |
*/
|
|
|
109 |
$GLOBALS['_PEAR_Common_script_phases'] = array('pre-install', 'post-install', 'pre-uninstall', 'post-uninstall', 'pre-build', 'post-build', 'pre-configure', 'post-configure', 'pre-setup', 'post-setup');
|
|
|
110 |
|
|
|
111 |
/**
|
|
|
112 |
* Class providing common functionality for PEAR administration classes.
|
|
|
113 |
* @category pear
|
|
|
114 |
* @package PEAR
|
|
|
115 |
* @author Stig Bakken <ssb@php.net>
|
|
|
116 |
* @author Tomas V. V. Cox <cox@idecnet.com>
|
|
|
117 |
* @author Greg Beaver <cellog@php.net>
|
| 187 |
mathias |
118 |
* @copyright 1997-2009 The Authors
|
|
|
119 |
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
|
|
120 |
* @version Release: 1.10.1
|
| 94 |
jpm |
121 |
* @link http://pear.php.net/package/PEAR
|
|
|
122 |
* @since Class available since Release 1.4.0a1
|
|
|
123 |
* @deprecated This class will disappear, and its components will be spread
|
|
|
124 |
* into smaller classes, like the AT&T breakup, as of Release 1.4.0a1
|
|
|
125 |
*/
|
|
|
126 |
class PEAR_Common extends PEAR
|
|
|
127 |
{
|
| 187 |
mathias |
128 |
/**
|
|
|
129 |
* User Interface object (PEAR_Frontend_* class). If null,
|
|
|
130 |
* the log() method uses print.
|
|
|
131 |
* @var object
|
|
|
132 |
*/
|
|
|
133 |
var $ui = null;
|
| 94 |
jpm |
134 |
|
| 187 |
mathias |
135 |
/**
|
|
|
136 |
* Configuration object (PEAR_Config).
|
|
|
137 |
* @var PEAR_Config
|
|
|
138 |
*/
|
|
|
139 |
var $config = null;
|
|
|
140 |
|
| 94 |
jpm |
141 |
/** stack of elements, gives some sort of XML context */
|
|
|
142 |
var $element_stack = array();
|
|
|
143 |
|
|
|
144 |
/** name of currently parsed XML element */
|
|
|
145 |
var $current_element;
|
|
|
146 |
|
|
|
147 |
/** array of attributes of the currently parsed XML element */
|
|
|
148 |
var $current_attributes = array();
|
|
|
149 |
|
|
|
150 |
/** assoc with information about a package */
|
|
|
151 |
var $pkginfo = array();
|
|
|
152 |
|
|
|
153 |
var $current_path = null;
|
|
|
154 |
|
|
|
155 |
/**
|
|
|
156 |
* Flag variable used to mark a valid package file
|
|
|
157 |
* @var boolean
|
|
|
158 |
* @access private
|
|
|
159 |
*/
|
|
|
160 |
var $_validPackageFile;
|
|
|
161 |
|
|
|
162 |
/**
|
|
|
163 |
* PEAR_Common constructor
|
|
|
164 |
*
|
|
|
165 |
* @access public
|
|
|
166 |
*/
|
| 187 |
mathias |
167 |
function __construct()
|
| 94 |
jpm |
168 |
{
|
| 187 |
mathias |
169 |
parent::__construct();
|
| 94 |
jpm |
170 |
$this->config = &PEAR_Config::singleton();
|
|
|
171 |
$this->debug = $this->config->get('verbose');
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
/**
|
|
|
175 |
* PEAR_Common destructor
|
|
|
176 |
*
|
|
|
177 |
* @access private
|
|
|
178 |
*/
|
|
|
179 |
function _PEAR_Common()
|
|
|
180 |
{
|
|
|
181 |
// doesn't work due to bug #14744
|
|
|
182 |
//$tempfiles = $this->_tempfiles;
|
|
|
183 |
$tempfiles =& $GLOBALS['_PEAR_Common_tempfiles'];
|
|
|
184 |
while ($file = array_shift($tempfiles)) {
|
|
|
185 |
if (@is_dir($file)) {
|
|
|
186 |
if (!class_exists('System')) {
|
|
|
187 |
require_once 'System.php';
|
|
|
188 |
}
|
| 187 |
mathias |
189 |
|
| 94 |
jpm |
190 |
System::rm(array('-rf', $file));
|
|
|
191 |
} elseif (file_exists($file)) {
|
|
|
192 |
unlink($file);
|
|
|
193 |
}
|
|
|
194 |
}
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
/**
|
|
|
198 |
* Register a temporary file or directory. When the destructor is
|
|
|
199 |
* executed, all registered temporary files and directories are
|
|
|
200 |
* removed.
|
|
|
201 |
*
|
|
|
202 |
* @param string $file name of file or directory
|
|
|
203 |
*
|
|
|
204 |
* @return void
|
|
|
205 |
*
|
|
|
206 |
* @access public
|
|
|
207 |
*/
|
|
|
208 |
function addTempFile($file)
|
|
|
209 |
{
|
|
|
210 |
if (!class_exists('PEAR_Frontend')) {
|
|
|
211 |
require_once 'PEAR/Frontend.php';
|
|
|
212 |
}
|
|
|
213 |
PEAR_Frontend::addTempFile($file);
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
/**
|
|
|
217 |
* Wrapper to System::mkDir(), creates a directory as well as
|
|
|
218 |
* any necessary parent directories.
|
|
|
219 |
*
|
|
|
220 |
* @param string $dir directory name
|
|
|
221 |
*
|
|
|
222 |
* @return bool TRUE on success, or a PEAR error
|
|
|
223 |
*
|
|
|
224 |
* @access public
|
|
|
225 |
*/
|
|
|
226 |
function mkDirHier($dir)
|
|
|
227 |
{
|
| 187 |
mathias |
228 |
// Only used in Installer - move it there ?
|
| 94 |
jpm |
229 |
$this->log(2, "+ create dir $dir");
|
|
|
230 |
if (!class_exists('System')) {
|
|
|
231 |
require_once 'System.php';
|
|
|
232 |
}
|
|
|
233 |
return System::mkDir(array('-p', $dir));
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
/**
|
|
|
237 |
* Logging method.
|
|
|
238 |
*
|
|
|
239 |
* @param int $level log level (0 is quiet, higher is noisier)
|
|
|
240 |
* @param string $msg message to write to the log
|
|
|
241 |
*
|
|
|
242 |
* @return void
|
|
|
243 |
*/
|
| 187 |
mathias |
244 |
public function log($level, $msg, $append_crlf = true)
|
| 94 |
jpm |
245 |
{
|
|
|
246 |
if ($this->debug >= $level) {
|
|
|
247 |
if (!class_exists('PEAR_Frontend')) {
|
|
|
248 |
require_once 'PEAR/Frontend.php';
|
|
|
249 |
}
|
| 187 |
mathias |
250 |
|
| 94 |
jpm |
251 |
$ui = &PEAR_Frontend::singleton();
|
|
|
252 |
if (is_a($ui, 'PEAR_Frontend')) {
|
|
|
253 |
$ui->log($msg, $append_crlf);
|
|
|
254 |
} else {
|
|
|
255 |
print "$msg\n";
|
|
|
256 |
}
|
|
|
257 |
}
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
/**
|
|
|
261 |
* Create and register a temporary directory.
|
|
|
262 |
*
|
|
|
263 |
* @param string $tmpdir (optional) Directory to use as tmpdir.
|
|
|
264 |
* Will use system defaults (for example
|
|
|
265 |
* /tmp or c:\windows\temp) if not specified
|
|
|
266 |
*
|
|
|
267 |
* @return string name of created directory
|
|
|
268 |
*
|
|
|
269 |
* @access public
|
|
|
270 |
*/
|
|
|
271 |
function mkTempDir($tmpdir = '')
|
|
|
272 |
{
|
| 187 |
mathias |
273 |
$topt = $tmpdir ? array('-t', $tmpdir) : array();
|
| 94 |
jpm |
274 |
$topt = array_merge($topt, array('-d', 'pear'));
|
|
|
275 |
if (!class_exists('System')) {
|
|
|
276 |
require_once 'System.php';
|
|
|
277 |
}
|
| 187 |
mathias |
278 |
|
| 94 |
jpm |
279 |
if (!$tmpdir = System::mktemp($topt)) {
|
|
|
280 |
return false;
|
|
|
281 |
}
|
| 187 |
mathias |
282 |
|
| 94 |
jpm |
283 |
$this->addTempFile($tmpdir);
|
|
|
284 |
return $tmpdir;
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
/**
|
|
|
288 |
* Set object that represents the frontend to be used.
|
|
|
289 |
*
|
|
|
290 |
* @param object Reference of the frontend object
|
|
|
291 |
* @return void
|
|
|
292 |
* @access public
|
|
|
293 |
*/
|
|
|
294 |
function setFrontendObject(&$ui)
|
|
|
295 |
{
|
|
|
296 |
$this->ui = &$ui;
|
|
|
297 |
}
|
|
|
298 |
|
| 187 |
mathias |
299 |
/**
|
|
|
300 |
* Return an array containing all of the states that are more stable than
|
|
|
301 |
* or equal to the passed in state
|
|
|
302 |
*
|
|
|
303 |
* @param string Release state
|
|
|
304 |
* @param boolean Determines whether to include $state in the list
|
|
|
305 |
* @return false|array False if $state is not a valid release state
|
|
|
306 |
*/
|
|
|
307 |
function betterStates($state, $include = false)
|
|
|
308 |
{
|
|
|
309 |
static $states = array('snapshot', 'devel', 'alpha', 'beta', 'stable');
|
|
|
310 |
$i = array_search($state, $states);
|
|
|
311 |
if ($i === false) {
|
|
|
312 |
return false;
|
|
|
313 |
}
|
|
|
314 |
if ($include) {
|
|
|
315 |
$i--;
|
|
|
316 |
}
|
|
|
317 |
return array_slice($states, $i + 1);
|
|
|
318 |
}
|
| 94 |
jpm |
319 |
|
| 187 |
mathias |
320 |
/**
|
|
|
321 |
* Get the valid roles for a PEAR package maintainer
|
|
|
322 |
*
|
|
|
323 |
* @return array
|
|
|
324 |
*/
|
|
|
325 |
public static function getUserRoles()
|
|
|
326 |
{
|
|
|
327 |
return $GLOBALS['_PEAR_Common_maintainer_roles'];
|
|
|
328 |
}
|
| 94 |
jpm |
329 |
|
|
|
330 |
/**
|
| 187 |
mathias |
331 |
* Get the valid package release states of packages
|
|
|
332 |
*
|
|
|
333 |
* @return array
|
|
|
334 |
*/
|
|
|
335 |
public static function getReleaseStates()
|
|
|
336 |
{
|
|
|
337 |
return $GLOBALS['_PEAR_Common_release_states'];
|
|
|
338 |
}
|
|
|
339 |
|
|
|
340 |
/**
|
|
|
341 |
* Get the implemented dependency types (php, ext, pkg etc.)
|
|
|
342 |
*
|
|
|
343 |
* @return array
|
|
|
344 |
*/
|
|
|
345 |
public static function getDependencyTypes()
|
|
|
346 |
{
|
|
|
347 |
return $GLOBALS['_PEAR_Common_dependency_types'];
|
|
|
348 |
}
|
|
|
349 |
|
|
|
350 |
/**
|
|
|
351 |
* Get the implemented dependency relations (has, lt, ge etc.)
|
|
|
352 |
*
|
|
|
353 |
* @return array
|
|
|
354 |
*/
|
|
|
355 |
public static function getDependencyRelations()
|
|
|
356 |
{
|
|
|
357 |
return $GLOBALS['_PEAR_Common_dependency_relations'];
|
|
|
358 |
}
|
|
|
359 |
|
|
|
360 |
/**
|
|
|
361 |
* Get the implemented file roles
|
|
|
362 |
*
|
|
|
363 |
* @return array
|
|
|
364 |
*/
|
|
|
365 |
public static function getFileRoles()
|
|
|
366 |
{
|
|
|
367 |
return $GLOBALS['_PEAR_Common_file_roles'];
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
/**
|
|
|
371 |
* Get the implemented file replacement types in
|
|
|
372 |
*
|
|
|
373 |
* @return array
|
|
|
374 |
*/
|
|
|
375 |
public static function getReplacementTypes()
|
|
|
376 |
{
|
|
|
377 |
return $GLOBALS['_PEAR_Common_replacement_types'];
|
|
|
378 |
}
|
|
|
379 |
|
|
|
380 |
/**
|
|
|
381 |
* Get the implemented file replacement types in
|
|
|
382 |
*
|
|
|
383 |
* @return array
|
|
|
384 |
*/
|
|
|
385 |
public static function getProvideTypes()
|
|
|
386 |
{
|
|
|
387 |
return $GLOBALS['_PEAR_Common_provide_types'];
|
|
|
388 |
}
|
|
|
389 |
|
|
|
390 |
/**
|
|
|
391 |
* Get the implemented file replacement types in
|
|
|
392 |
*
|
|
|
393 |
* @return array
|
|
|
394 |
*/
|
|
|
395 |
public static function getScriptPhases()
|
|
|
396 |
{
|
|
|
397 |
return $GLOBALS['_PEAR_Common_script_phases'];
|
|
|
398 |
}
|
|
|
399 |
|
|
|
400 |
/**
|
|
|
401 |
* Test whether a string contains a valid package name.
|
|
|
402 |
*
|
|
|
403 |
* @param string $name the package name to test
|
|
|
404 |
*
|
|
|
405 |
* @return bool
|
|
|
406 |
*
|
|
|
407 |
* @access public
|
|
|
408 |
*/
|
|
|
409 |
function validPackageName($name)
|
|
|
410 |
{
|
|
|
411 |
return (bool)preg_match(PEAR_COMMON_PACKAGE_NAME_PREG, $name);
|
|
|
412 |
}
|
|
|
413 |
|
|
|
414 |
/**
|
|
|
415 |
* Test whether a string contains a valid package version.
|
|
|
416 |
*
|
|
|
417 |
* @param string $ver the package version to test
|
|
|
418 |
*
|
|
|
419 |
* @return bool
|
|
|
420 |
*
|
|
|
421 |
* @access public
|
|
|
422 |
*/
|
|
|
423 |
function validPackageVersion($ver)
|
|
|
424 |
{
|
|
|
425 |
return (bool)preg_match(PEAR_COMMON_PACKAGE_VERSION_PREG, $ver);
|
|
|
426 |
}
|
|
|
427 |
|
|
|
428 |
/**
|
|
|
429 |
* @param string $path relative or absolute include path
|
|
|
430 |
* @return boolean
|
|
|
431 |
*/
|
|
|
432 |
public static function isIncludeable($path)
|
|
|
433 |
{
|
|
|
434 |
if (file_exists($path) && is_readable($path)) {
|
|
|
435 |
return true;
|
|
|
436 |
}
|
|
|
437 |
|
|
|
438 |
$ipath = explode(PATH_SEPARATOR, ini_get('include_path'));
|
|
|
439 |
foreach ($ipath as $include) {
|
|
|
440 |
$test = realpath($include . DIRECTORY_SEPARATOR . $path);
|
|
|
441 |
if (file_exists($test) && is_readable($test)) {
|
|
|
442 |
return true;
|
|
|
443 |
}
|
|
|
444 |
}
|
|
|
445 |
|
|
|
446 |
return false;
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
function _postProcessChecks($pf)
|
|
|
450 |
{
|
|
|
451 |
if (!PEAR::isError($pf)) {
|
|
|
452 |
return $this->_postProcessValidPackagexml($pf);
|
|
|
453 |
}
|
|
|
454 |
|
|
|
455 |
$errs = $pf->getUserinfo();
|
|
|
456 |
if (is_array($errs)) {
|
|
|
457 |
foreach ($errs as $error) {
|
|
|
458 |
$e = $this->raiseError($error['message'], $error['code'], null, null, $error);
|
|
|
459 |
}
|
|
|
460 |
}
|
|
|
461 |
|
|
|
462 |
return $pf;
|
|
|
463 |
}
|
|
|
464 |
|
|
|
465 |
/**
|
| 94 |
jpm |
466 |
* Returns information about a package file. Expects the name of
|
|
|
467 |
* a gzipped tar file as input.
|
|
|
468 |
*
|
|
|
469 |
* @param string $file name of .tgz file
|
|
|
470 |
*
|
|
|
471 |
* @return array array with package information
|
|
|
472 |
*
|
|
|
473 |
* @access public
|
|
|
474 |
* @deprecated use PEAR_PackageFile->fromTgzFile() instead
|
|
|
475 |
*
|
|
|
476 |
*/
|
|
|
477 |
function infoFromTgzFile($file)
|
|
|
478 |
{
|
| 187 |
mathias |
479 |
$packagefile = new PEAR_PackageFile($this->config);
|
| 94 |
jpm |
480 |
$pf = &$packagefile->fromTgzFile($file, PEAR_VALIDATE_NORMAL);
|
| 187 |
mathias |
481 |
return $this->_postProcessChecks($pf);
|
| 94 |
jpm |
482 |
}
|
|
|
483 |
|
|
|
484 |
/**
|
|
|
485 |
* Returns information about a package file. Expects the name of
|
|
|
486 |
* a package xml file as input.
|
|
|
487 |
*
|
|
|
488 |
* @param string $descfile name of package xml file
|
|
|
489 |
*
|
|
|
490 |
* @return array array with package information
|
|
|
491 |
*
|
|
|
492 |
* @access public
|
|
|
493 |
* @deprecated use PEAR_PackageFile->fromPackageFile() instead
|
|
|
494 |
*
|
|
|
495 |
*/
|
|
|
496 |
function infoFromDescriptionFile($descfile)
|
|
|
497 |
{
|
| 187 |
mathias |
498 |
$packagefile = new PEAR_PackageFile($this->config);
|
| 94 |
jpm |
499 |
$pf = &$packagefile->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
|
| 187 |
mathias |
500 |
return $this->_postProcessChecks($pf);
|
| 94 |
jpm |
501 |
}
|
|
|
502 |
|
|
|
503 |
/**
|
|
|
504 |
* Returns information about a package file. Expects the contents
|
|
|
505 |
* of a package xml file as input.
|
|
|
506 |
*
|
|
|
507 |
* @param string $data contents of package.xml file
|
|
|
508 |
*
|
|
|
509 |
* @return array array with package information
|
|
|
510 |
*
|
|
|
511 |
* @access public
|
|
|
512 |
* @deprecated use PEAR_PackageFile->fromXmlstring() instead
|
|
|
513 |
*
|
|
|
514 |
*/
|
|
|
515 |
function infoFromString($data)
|
|
|
516 |
{
|
| 187 |
mathias |
517 |
$packagefile = new PEAR_PackageFile($this->config);
|
| 94 |
jpm |
518 |
$pf = &$packagefile->fromXmlString($data, PEAR_VALIDATE_NORMAL, false);
|
| 187 |
mathias |
519 |
return $this->_postProcessChecks($pf);
|
| 94 |
jpm |
520 |
}
|
|
|
521 |
|
|
|
522 |
/**
|
|
|
523 |
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
|
|
|
524 |
* @return array
|
|
|
525 |
*/
|
|
|
526 |
function _postProcessValidPackagexml(&$pf)
|
|
|
527 |
{
|
| 187 |
mathias |
528 |
if (!is_a($pf, 'PEAR_PackageFile_v2')) {
|
| 94 |
jpm |
529 |
$this->pkginfo = $pf->toArray();
|
|
|
530 |
return $this->pkginfo;
|
|
|
531 |
}
|
| 187 |
mathias |
532 |
|
|
|
533 |
// sort of make this into a package.xml 1.0-style array
|
|
|
534 |
// changelog is not converted to old format.
|
|
|
535 |
$arr = $pf->toArray(true);
|
|
|
536 |
$arr = array_merge($arr, $arr['old']);
|
|
|
537 |
unset($arr['old'], $arr['xsdversion'], $arr['contents'], $arr['compatible'],
|
|
|
538 |
$arr['channel'], $arr['uri'], $arr['dependencies'], $arr['phprelease'],
|
|
|
539 |
$arr['extsrcrelease'], $arr['zendextsrcrelease'], $arr['extbinrelease'],
|
|
|
540 |
$arr['zendextbinrelease'], $arr['bundle'], $arr['lead'], $arr['developer'],
|
|
|
541 |
$arr['helper'], $arr['contributor']);
|
|
|
542 |
$arr['filelist'] = $pf->getFilelist();
|
|
|
543 |
$this->pkginfo = $arr;
|
|
|
544 |
return $arr;
|
| 94 |
jpm |
545 |
}
|
|
|
546 |
|
|
|
547 |
/**
|
|
|
548 |
* Returns package information from different sources
|
|
|
549 |
*
|
|
|
550 |
* This method is able to extract information about a package
|
|
|
551 |
* from a .tgz archive or from a XML package definition file.
|
|
|
552 |
*
|
|
|
553 |
* @access public
|
|
|
554 |
* @param string Filename of the source ('package.xml', '<package>.tgz')
|
|
|
555 |
* @return string
|
|
|
556 |
* @deprecated use PEAR_PackageFile->fromAnyFile() instead
|
|
|
557 |
*/
|
|
|
558 |
function infoFromAny($info)
|
|
|
559 |
{
|
|
|
560 |
if (is_string($info) && file_exists($info)) {
|
| 187 |
mathias |
561 |
$packagefile = new PEAR_PackageFile($this->config);
|
| 94 |
jpm |
562 |
$pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL);
|
|
|
563 |
if (PEAR::isError($pf)) {
|
|
|
564 |
$errs = $pf->getUserinfo();
|
|
|
565 |
if (is_array($errs)) {
|
|
|
566 |
foreach ($errs as $error) {
|
|
|
567 |
$e = $this->raiseError($error['message'], $error['code'], null, null, $error);
|
|
|
568 |
}
|
|
|
569 |
}
|
| 187 |
mathias |
570 |
|
| 94 |
jpm |
571 |
return $pf;
|
|
|
572 |
}
|
| 187 |
mathias |
573 |
|
| 94 |
jpm |
574 |
return $this->_postProcessValidPackagexml($pf);
|
|
|
575 |
}
|
| 187 |
mathias |
576 |
|
| 94 |
jpm |
577 |
return $info;
|
|
|
578 |
}
|
|
|
579 |
|
|
|
580 |
/**
|
|
|
581 |
* Return an XML document based on the package info (as returned
|
|
|
582 |
* by the PEAR_Common::infoFrom* methods).
|
|
|
583 |
*
|
|
|
584 |
* @param array $pkginfo package info
|
|
|
585 |
*
|
|
|
586 |
* @return string XML data
|
|
|
587 |
*
|
|
|
588 |
* @access public
|
|
|
589 |
* @deprecated use a PEAR_PackageFile_v* object's generator instead
|
|
|
590 |
*/
|
|
|
591 |
function xmlFromInfo($pkginfo)
|
|
|
592 |
{
|
| 187 |
mathias |
593 |
$config = &PEAR_Config::singleton();
|
|
|
594 |
$packagefile = new PEAR_PackageFile($config);
|
| 94 |
jpm |
595 |
$pf = &$packagefile->fromArray($pkginfo);
|
|
|
596 |
$gen = &$pf->getDefaultGenerator();
|
|
|
597 |
return $gen->toXml(PEAR_VALIDATE_PACKAGING);
|
|
|
598 |
}
|
|
|
599 |
|
|
|
600 |
/**
|
|
|
601 |
* Validate XML package definition file.
|
|
|
602 |
*
|
|
|
603 |
* @param string $info Filename of the package archive or of the
|
|
|
604 |
* package definition file
|
|
|
605 |
* @param array $errors Array that will contain the errors
|
|
|
606 |
* @param array $warnings Array that will contain the warnings
|
|
|
607 |
* @param string $dir_prefix (optional) directory where source files
|
|
|
608 |
* may be found, or empty if they are not available
|
|
|
609 |
* @access public
|
|
|
610 |
* @return boolean
|
|
|
611 |
* @deprecated use the validation of PEAR_PackageFile objects
|
|
|
612 |
*/
|
|
|
613 |
function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '')
|
|
|
614 |
{
|
| 187 |
mathias |
615 |
$config = &PEAR_Config::singleton();
|
|
|
616 |
$packagefile = new PEAR_PackageFile($config);
|
| 94 |
jpm |
617 |
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
|
|
|
618 |
if (strpos($info, '<?xml') !== false) {
|
|
|
619 |
$pf = &$packagefile->fromXmlString($info, PEAR_VALIDATE_NORMAL, '');
|
|
|
620 |
} else {
|
|
|
621 |
$pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL);
|
|
|
622 |
}
|
| 187 |
mathias |
623 |
|
| 94 |
jpm |
624 |
PEAR::staticPopErrorHandling();
|
|
|
625 |
if (PEAR::isError($pf)) {
|
|
|
626 |
$errs = $pf->getUserinfo();
|
|
|
627 |
if (is_array($errs)) {
|
|
|
628 |
foreach ($errs as $error) {
|
|
|
629 |
if ($error['level'] == 'error') {
|
|
|
630 |
$errors[] = $error['message'];
|
|
|
631 |
} else {
|
|
|
632 |
$warnings[] = $error['message'];
|
|
|
633 |
}
|
|
|
634 |
}
|
|
|
635 |
}
|
| 187 |
mathias |
636 |
|
| 94 |
jpm |
637 |
return false;
|
|
|
638 |
}
|
| 187 |
mathias |
639 |
|
| 94 |
jpm |
640 |
return true;
|
|
|
641 |
}
|
|
|
642 |
|
|
|
643 |
/**
|
|
|
644 |
* Build a "provides" array from data returned by
|
|
|
645 |
* analyzeSourceCode(). The format of the built array is like
|
|
|
646 |
* this:
|
|
|
647 |
*
|
|
|
648 |
* array(
|
|
|
649 |
* 'class;MyClass' => 'array('type' => 'class', 'name' => 'MyClass'),
|
|
|
650 |
* ...
|
|
|
651 |
* )
|
|
|
652 |
*
|
|
|
653 |
*
|
|
|
654 |
* @param array $srcinfo array with information about a source file
|
|
|
655 |
* as returned by the analyzeSourceCode() method.
|
|
|
656 |
*
|
|
|
657 |
* @return void
|
|
|
658 |
*
|
|
|
659 |
* @access public
|
|
|
660 |
*
|
|
|
661 |
*/
|
|
|
662 |
function buildProvidesArray($srcinfo)
|
|
|
663 |
{
|
|
|
664 |
$file = basename($srcinfo['source_file']);
|
|
|
665 |
$pn = '';
|
|
|
666 |
if (isset($this->_packageName)) {
|
|
|
667 |
$pn = $this->_packageName;
|
|
|
668 |
}
|
| 187 |
mathias |
669 |
|
| 94 |
jpm |
670 |
$pnl = strlen($pn);
|
|
|
671 |
foreach ($srcinfo['declared_classes'] as $class) {
|
|
|
672 |
$key = "class;$class";
|
|
|
673 |
if (isset($this->pkginfo['provides'][$key])) {
|
|
|
674 |
continue;
|
|
|
675 |
}
|
| 187 |
mathias |
676 |
|
| 94 |
jpm |
677 |
$this->pkginfo['provides'][$key] =
|
|
|
678 |
array('file'=> $file, 'type' => 'class', 'name' => $class);
|
|
|
679 |
if (isset($srcinfo['inheritance'][$class])) {
|
|
|
680 |
$this->pkginfo['provides'][$key]['extends'] =
|
|
|
681 |
$srcinfo['inheritance'][$class];
|
|
|
682 |
}
|
|
|
683 |
}
|
| 187 |
mathias |
684 |
|
| 94 |
jpm |
685 |
foreach ($srcinfo['declared_methods'] as $class => $methods) {
|
|
|
686 |
foreach ($methods as $method) {
|
|
|
687 |
$function = "$class::$method";
|
|
|
688 |
$key = "function;$function";
|
|
|
689 |
if ($method{0} == '_' || !strcasecmp($method, $class) ||
|
|
|
690 |
isset($this->pkginfo['provides'][$key])) {
|
|
|
691 |
continue;
|
|
|
692 |
}
|
| 187 |
mathias |
693 |
|
| 94 |
jpm |
694 |
$this->pkginfo['provides'][$key] =
|
|
|
695 |
array('file'=> $file, 'type' => 'function', 'name' => $function);
|
|
|
696 |
}
|
|
|
697 |
}
|
|
|
698 |
|
|
|
699 |
foreach ($srcinfo['declared_functions'] as $function) {
|
|
|
700 |
$key = "function;$function";
|
|
|
701 |
if ($function{0} == '_' || isset($this->pkginfo['provides'][$key])) {
|
|
|
702 |
continue;
|
|
|
703 |
}
|
| 187 |
mathias |
704 |
|
| 94 |
jpm |
705 |
if (!strstr($function, '::') && strncasecmp($function, $pn, $pnl)) {
|
|
|
706 |
$warnings[] = "in1 " . $file . ": function \"$function\" not prefixed with package name \"$pn\"";
|
|
|
707 |
}
|
| 187 |
mathias |
708 |
|
| 94 |
jpm |
709 |
$this->pkginfo['provides'][$key] =
|
|
|
710 |
array('file'=> $file, 'type' => 'function', 'name' => $function);
|
|
|
711 |
}
|
|
|
712 |
}
|
|
|
713 |
|
|
|
714 |
/**
|
|
|
715 |
* Analyze the source code of the given PHP file
|
|
|
716 |
*
|
|
|
717 |
* @param string Filename of the PHP file
|
|
|
718 |
* @return mixed
|
|
|
719 |
* @access public
|
|
|
720 |
*/
|
|
|
721 |
function analyzeSourceCode($file)
|
|
|
722 |
{
|
| 187 |
mathias |
723 |
if (!class_exists('PEAR_PackageFile_v2_Validator')) {
|
|
|
724 |
require_once 'PEAR/PackageFile/v2/Validator.php';
|
| 94 |
jpm |
725 |
}
|
|
|
726 |
|
| 187 |
mathias |
727 |
$a = new PEAR_PackageFile_v2_Validator;
|
|
|
728 |
return $a->analyzeSourceCode($file);
|
| 94 |
jpm |
729 |
}
|
|
|
730 |
|
|
|
731 |
function detectDependencies($any, $status_callback = null)
|
|
|
732 |
{
|
|
|
733 |
if (!function_exists("token_get_all")) {
|
|
|
734 |
return false;
|
|
|
735 |
}
|
| 187 |
mathias |
736 |
|
| 94 |
jpm |
737 |
if (PEAR::isError($info = $this->infoFromAny($any))) {
|
|
|
738 |
return $this->raiseError($info);
|
|
|
739 |
}
|
| 187 |
mathias |
740 |
|
| 94 |
jpm |
741 |
if (!is_array($info)) {
|
|
|
742 |
return false;
|
|
|
743 |
}
|
| 187 |
mathias |
744 |
|
| 94 |
jpm |
745 |
$deps = array();
|
|
|
746 |
$used_c = $decl_c = $decl_f = $decl_m = array();
|
|
|
747 |
foreach ($info['filelist'] as $file => $fa) {
|
|
|
748 |
$tmp = $this->analyzeSourceCode($file);
|
|
|
749 |
$used_c = @array_merge($used_c, $tmp['used_classes']);
|
|
|
750 |
$decl_c = @array_merge($decl_c, $tmp['declared_classes']);
|
|
|
751 |
$decl_f = @array_merge($decl_f, $tmp['declared_functions']);
|
|
|
752 |
$decl_m = @array_merge($decl_m, $tmp['declared_methods']);
|
|
|
753 |
$inheri = @array_merge($inheri, $tmp['inheritance']);
|
|
|
754 |
}
|
| 187 |
mathias |
755 |
|
| 94 |
jpm |
756 |
$used_c = array_unique($used_c);
|
|
|
757 |
$decl_c = array_unique($decl_c);
|
|
|
758 |
$undecl_c = array_diff($used_c, $decl_c);
|
| 187 |
mathias |
759 |
|
| 94 |
jpm |
760 |
return array('used_classes' => $used_c,
|
|
|
761 |
'declared_classes' => $decl_c,
|
|
|
762 |
'declared_methods' => $decl_m,
|
|
|
763 |
'declared_functions' => $decl_f,
|
|
|
764 |
'undeclared_classes' => $undecl_c,
|
|
|
765 |
'inheritance' => $inheri,
|
|
|
766 |
);
|
|
|
767 |
}
|
|
|
768 |
|
|
|
769 |
/**
|
|
|
770 |
* Download a file through HTTP. Considers suggested file name in
|
|
|
771 |
* Content-disposition: header and can run a callback function for
|
|
|
772 |
* different events. The callback will be called with two
|
|
|
773 |
* parameters: the callback type, and parameters. The implemented
|
|
|
774 |
* callback types are:
|
|
|
775 |
*
|
|
|
776 |
* 'setup' called at the very beginning, parameter is a UI object
|
|
|
777 |
* that should be used for all output
|
|
|
778 |
* 'message' the parameter is a string with an informational message
|
|
|
779 |
* 'saveas' may be used to save with a different file name, the
|
|
|
780 |
* parameter is the filename that is about to be used.
|
|
|
781 |
* If a 'saveas' callback returns a non-empty string,
|
|
|
782 |
* that file name will be used as the filename instead.
|
|
|
783 |
* Note that $save_dir will not be affected by this, only
|
|
|
784 |
* the basename of the file.
|
|
|
785 |
* 'start' download is starting, parameter is number of bytes
|
|
|
786 |
* that are expected, or -1 if unknown
|
|
|
787 |
* 'bytesread' parameter is the number of bytes read so far
|
|
|
788 |
* 'done' download is complete, parameter is the total number
|
|
|
789 |
* of bytes read
|
|
|
790 |
* 'connfailed' if the TCP connection fails, this callback is called
|
|
|
791 |
* with array(host,port,errno,errmsg)
|
|
|
792 |
* 'writefailed' if writing to disk fails, this callback is called
|
|
|
793 |
* with array(destfile,errmsg)
|
|
|
794 |
*
|
|
|
795 |
* If an HTTP proxy has been configured (http_proxy PEAR_Config
|
|
|
796 |
* setting), the proxy will be used.
|
|
|
797 |
*
|
|
|
798 |
* @param string $url the URL to download
|
|
|
799 |
* @param object $ui PEAR_Frontend_* instance
|
|
|
800 |
* @param object $config PEAR_Config instance
|
|
|
801 |
* @param string $save_dir (optional) directory to save file in
|
|
|
802 |
* @param mixed $callback (optional) function/method to call for status
|
|
|
803 |
* updates
|
| 187 |
mathias |
804 |
* @param false|string|array $lastmodified header values to check against
|
|
|
805 |
* for caching
|
|
|
806 |
* use false to return the header
|
|
|
807 |
* values from this download
|
|
|
808 |
* @param false|array $accept Accept headers to send
|
|
|
809 |
* @param false|string $channel Channel to use for retrieving
|
|
|
810 |
* authentication
|
| 94 |
jpm |
811 |
*
|
| 187 |
mathias |
812 |
* @return mixed Returns the full path of the downloaded file or a PEAR
|
|
|
813 |
* error on failure. If the error is caused by
|
|
|
814 |
* socket-related errors, the error object will
|
|
|
815 |
* have the fsockopen error code available through
|
|
|
816 |
* getCode(). If caching is requested, then return the header
|
|
|
817 |
* values.
|
|
|
818 |
* If $lastmodified was given and the there are no changes,
|
|
|
819 |
* boolean false is returned.
|
| 94 |
jpm |
820 |
*
|
|
|
821 |
* @access public
|
|
|
822 |
*/
|
| 187 |
mathias |
823 |
function downloadHttp(
|
|
|
824 |
$url, &$ui, $save_dir = '.', $callback = null, $lastmodified = null,
|
|
|
825 |
$accept = false, $channel = false
|
|
|
826 |
) {
|
| 94 |
jpm |
827 |
if (!class_exists('PEAR_Downloader')) {
|
|
|
828 |
require_once 'PEAR/Downloader.php';
|
|
|
829 |
}
|
| 187 |
mathias |
830 |
return PEAR_Downloader::_downloadHttp(
|
|
|
831 |
$this, $url, $ui, $save_dir, $callback, $lastmodified,
|
|
|
832 |
$accept, $channel
|
|
|
833 |
);
|
| 94 |
jpm |
834 |
}
|
| 187 |
mathias |
835 |
}
|
| 94 |
jpm |
836 |
|
|
|
837 |
require_once 'PEAR/Config.php';
|
|
|
838 |
require_once 'PEAR/PackageFile.php';
|