Common.php 25 KB

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