4,20 → 4,13 |
* |
* PHP versions 4 and 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
* http://www.php.net/license/3_0.txt. If you did not receive a copy of |
* the PHP License and are unable to obtain it through the web, please |
* send a note to license@php.net so we can mail you a copy immediately. |
* |
* @category pear |
* @package PEAR |
* @author Stig Bakken <ssb@php.net> |
* @author Tomas V. V. Cox <cox@idecnet.com> |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: Common.php,v 1.157 2006/05/12 02:38:58 cellog Exp $ |
* @copyright 1997-2009 The Authors |
* @license http://opensource.org/licenses/bsd-license.php New BSD License |
* @link http://pear.php.net/package/PEAR |
* @since File available since Release 0.1.0 |
* @deprecated File deprecated since Release 1.4.0a1 |
28,39 → 21,37 |
*/ |
require_once 'PEAR.php'; |
|
// {{{ constants and globals |
|
/** |
* PEAR_Common error when an invalid PHP file is passed to PEAR_Common::analyzeSourceCode() |
*/ |
define('PEAR_COMMON_ERROR_INVALIDPHP', 1); |
define('_PEAR_COMMON_PACKAGE_NAME_PREG', '[A-Za-z][a-zA-Z0-9_]+'); |
define('PEAR_COMMON_PACKAGE_NAME_PREG', '/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '$/'); |
define('PEAR_COMMON_PACKAGE_NAME_PREG', '/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '\\z/'); |
|
// this should allow: 1, 1.0, 1.0RC1, 1.0dev, 1.0dev123234234234, 1.0a1, 1.0b1, 1.0pl1 |
define('_PEAR_COMMON_PACKAGE_VERSION_PREG', '\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?'); |
define('PEAR_COMMON_PACKAGE_VERSION_PREG', '/^' . _PEAR_COMMON_PACKAGE_VERSION_PREG . '$/i'); |
define('PEAR_COMMON_PACKAGE_VERSION_PREG', '/^' . _PEAR_COMMON_PACKAGE_VERSION_PREG . '\\z/i'); |
|
// XXX far from perfect :-) |
define('_PEAR_COMMON_PACKAGE_DOWNLOAD_PREG', '(' . _PEAR_COMMON_PACKAGE_NAME_PREG . |
')(-([.0-9a-zA-Z]+))?'); |
define('PEAR_COMMON_PACKAGE_DOWNLOAD_PREG', '/^' . _PEAR_COMMON_PACKAGE_DOWNLOAD_PREG . |
'$/'); |
'\\z/'); |
|
define('_PEAR_CHANNELS_NAME_PREG', '[A-Za-z][a-zA-Z0-9\.]+'); |
define('PEAR_CHANNELS_NAME_PREG', '/^' . _PEAR_CHANNELS_NAME_PREG . '$/'); |
define('PEAR_CHANNELS_NAME_PREG', '/^' . _PEAR_CHANNELS_NAME_PREG . '\\z/'); |
|
// this should allow any dns or IP address, plus a path - NO UNDERSCORES ALLOWED |
define('_PEAR_CHANNELS_SERVER_PREG', '[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*(\/[a-zA-Z0-9\-]+)*'); |
define('PEAR_CHANNELS_SERVER_PREG', '/^' . _PEAR_CHANNELS_SERVER_PREG . '$/i'); |
define('PEAR_CHANNELS_SERVER_PREG', '/^' . _PEAR_CHANNELS_SERVER_PREG . '\\z/i'); |
|
define('_PEAR_CHANNELS_PACKAGE_PREG', '(' ._PEAR_CHANNELS_SERVER_PREG . ')\/(' |
. _PEAR_COMMON_PACKAGE_NAME_PREG . ')'); |
define('PEAR_CHANNELS_PACKAGE_PREG', '/^' . _PEAR_CHANNELS_PACKAGE_PREG . '$/i'); |
define('PEAR_CHANNELS_PACKAGE_PREG', '/^' . _PEAR_CHANNELS_PACKAGE_PREG . '\\z/i'); |
|
define('_PEAR_COMMON_CHANNEL_DOWNLOAD_PREG', '(' . _PEAR_CHANNELS_NAME_PREG . ')::(' |
. _PEAR_COMMON_PACKAGE_NAME_PREG . ')(-([.0-9a-zA-Z]+))?'); |
define('PEAR_COMMON_CHANNEL_DOWNLOAD_PREG', '/^' . _PEAR_COMMON_CHANNEL_DOWNLOAD_PREG . '$/'); |
define('PEAR_COMMON_CHANNEL_DOWNLOAD_PREG', '/^' . _PEAR_COMMON_CHANNEL_DOWNLOAD_PREG . '\\z/'); |
|
/** |
* List of temporary files and directories registered by |
117,8 → 108,6 |
*/ |
$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'); |
|
// }}} |
|
/** |
* Class providing common functionality for PEAR administration classes. |
* @category pear |
126,9 → 115,9 |
* @author Stig Bakken <ssb@php.net> |
* @author Tomas V. V. Cox <cox@idecnet.com> |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version Release: 1.5.1 |
* @copyright 1997-2009 The Authors |
* @license http://opensource.org/licenses/bsd-license.php New BSD License |
* @version Release: 1.10.1 |
* @link http://pear.php.net/package/PEAR |
* @since Class available since Release 1.4.0a1 |
* @deprecated This class will disappear, and its components will be spread |
136,8 → 125,19 |
*/ |
class PEAR_Common extends PEAR |
{ |
// {{{ properties |
/** |
* User Interface object (PEAR_Frontend_* class). If null, |
* the log() method uses print. |
* @var object |
*/ |
var $ui = null; |
|
/** |
* Configuration object (PEAR_Config). |
* @var PEAR_Config |
*/ |
var $config = null; |
|
/** stack of elements, gives some sort of XML context */ |
var $element_stack = array(); |
|
150,27 → 150,9 |
/** assoc with information about a package */ |
var $pkginfo = array(); |
|
/** |
* User Interface object (PEAR_Frontend_* class). If null, |
* the log() method uses print. |
* @var object |
*/ |
var $ui = null; |
|
/** |
* Configuration object (PEAR_Config). |
* @var object |
*/ |
var $config = null; |
|
var $current_path = null; |
|
/** |
* PEAR_SourceAnalyzer instance |
* @var object |
*/ |
var $source_analyzer = null; |
/** |
* Flag variable used to mark a valid package file |
* @var boolean |
* @access private |
177,25 → 159,18 |
*/ |
var $_validPackageFile; |
|
// }}} |
|
// {{{ constructor |
|
/** |
* PEAR_Common constructor |
* |
* @access public |
*/ |
function PEAR_Common() |
function __construct() |
{ |
parent::PEAR(); |
parent::__construct(); |
$this->config = &PEAR_Config::singleton(); |
$this->debug = $this->config->get('verbose'); |
} |
|
// }}} |
// {{{ destructor |
|
/** |
* PEAR_Common destructor |
* |
211,6 → 186,7 |
if (!class_exists('System')) { |
require_once 'System.php'; |
} |
|
System::rm(array('-rf', $file)); |
} elseif (file_exists($file)) { |
unlink($file); |
218,9 → 194,6 |
} |
} |
|
// }}} |
// {{{ addTempFile() |
|
/** |
* Register a temporary file or directory. When the destructor is |
* executed, all registered temporary files and directories are |
240,9 → 213,6 |
PEAR_Frontend::addTempFile($file); |
} |
|
// }}} |
// {{{ mkDirHier() |
|
/** |
* Wrapper to System::mkDir(), creates a directory as well as |
* any necessary parent directories. |
255,6 → 225,7 |
*/ |
function mkDirHier($dir) |
{ |
// Only used in Installer - move it there ? |
$this->log(2, "+ create dir $dir"); |
if (!class_exists('System')) { |
require_once 'System.php'; |
262,9 → 233,6 |
return System::mkDir(array('-p', $dir)); |
} |
|
// }}} |
// {{{ log() |
|
/** |
* Logging method. |
* |
272,16 → 240,14 |
* @param string $msg message to write to the log |
* |
* @return void |
* |
* @access public |
* @static |
*/ |
function log($level, $msg, $append_crlf = true) |
public function log($level, $msg, $append_crlf = true) |
{ |
if ($this->debug >= $level) { |
if (!class_exists('PEAR_Frontend')) { |
require_once 'PEAR/Frontend.php'; |
} |
|
$ui = &PEAR_Frontend::singleton(); |
if (is_a($ui, 'PEAR_Frontend')) { |
$ui->log($msg, $append_crlf); |
291,9 → 257,6 |
} |
} |
|
// }}} |
// {{{ mkTempDir() |
|
/** |
* Create and register a temporary directory. |
* |
307,25 → 270,20 |
*/ |
function mkTempDir($tmpdir = '') |
{ |
if ($tmpdir) { |
$topt = array('-t', $tmpdir); |
} else { |
$topt = array(); |
} |
$topt = $tmpdir ? array('-t', $tmpdir) : array(); |
$topt = array_merge($topt, array('-d', 'pear')); |
if (!class_exists('System')) { |
require_once 'System.php'; |
} |
|
if (!$tmpdir = System::mktemp($topt)) { |
return false; |
} |
|
$this->addTempFile($tmpdir); |
return $tmpdir; |
} |
|
// }}} |
// {{{ setFrontendObject() |
|
/** |
* Set object that represents the frontend to be used. |
* |
338,11 → 296,173 |
$this->ui = &$ui; |
} |
|
// }}} |
/** |
* Return an array containing all of the states that are more stable than |
* or equal to the passed in state |
* |
* @param string Release state |
* @param boolean Determines whether to include $state in the list |
* @return false|array False if $state is not a valid release state |
*/ |
function betterStates($state, $include = false) |
{ |
static $states = array('snapshot', 'devel', 'alpha', 'beta', 'stable'); |
$i = array_search($state, $states); |
if ($i === false) { |
return false; |
} |
if ($include) { |
$i--; |
} |
return array_slice($states, $i + 1); |
} |
|
// {{{ infoFromTgzFile() |
/** |
* Get the valid roles for a PEAR package maintainer |
* |
* @return array |
*/ |
public static function getUserRoles() |
{ |
return $GLOBALS['_PEAR_Common_maintainer_roles']; |
} |
|
/** |
* Get the valid package release states of packages |
* |
* @return array |
*/ |
public static function getReleaseStates() |
{ |
return $GLOBALS['_PEAR_Common_release_states']; |
} |
|
/** |
* Get the implemented dependency types (php, ext, pkg etc.) |
* |
* @return array |
*/ |
public static function getDependencyTypes() |
{ |
return $GLOBALS['_PEAR_Common_dependency_types']; |
} |
|
/** |
* Get the implemented dependency relations (has, lt, ge etc.) |
* |
* @return array |
*/ |
public static function getDependencyRelations() |
{ |
return $GLOBALS['_PEAR_Common_dependency_relations']; |
} |
|
/** |
* Get the implemented file roles |
* |
* @return array |
*/ |
public static function getFileRoles() |
{ |
return $GLOBALS['_PEAR_Common_file_roles']; |
} |
|
/** |
* Get the implemented file replacement types in |
* |
* @return array |
*/ |
public static function getReplacementTypes() |
{ |
return $GLOBALS['_PEAR_Common_replacement_types']; |
} |
|
/** |
* Get the implemented file replacement types in |
* |
* @return array |
*/ |
public static function getProvideTypes() |
{ |
return $GLOBALS['_PEAR_Common_provide_types']; |
} |
|
/** |
* Get the implemented file replacement types in |
* |
* @return array |
*/ |
public static function getScriptPhases() |
{ |
return $GLOBALS['_PEAR_Common_script_phases']; |
} |
|
/** |
* Test whether a string contains a valid package name. |
* |
* @param string $name the package name to test |
* |
* @return bool |
* |
* @access public |
*/ |
function validPackageName($name) |
{ |
return (bool)preg_match(PEAR_COMMON_PACKAGE_NAME_PREG, $name); |
} |
|
/** |
* Test whether a string contains a valid package version. |
* |
* @param string $ver the package version to test |
* |
* @return bool |
* |
* @access public |
*/ |
function validPackageVersion($ver) |
{ |
return (bool)preg_match(PEAR_COMMON_PACKAGE_VERSION_PREG, $ver); |
} |
|
/** |
* @param string $path relative or absolute include path |
* @return boolean |
*/ |
public static function isIncludeable($path) |
{ |
if (file_exists($path) && is_readable($path)) { |
return true; |
} |
|
$ipath = explode(PATH_SEPARATOR, ini_get('include_path')); |
foreach ($ipath as $include) { |
$test = realpath($include . DIRECTORY_SEPARATOR . $path); |
if (file_exists($test) && is_readable($test)) { |
return true; |
} |
} |
|
return false; |
} |
|
function _postProcessChecks($pf) |
{ |
if (!PEAR::isError($pf)) { |
return $this->_postProcessValidPackagexml($pf); |
} |
|
$errs = $pf->getUserinfo(); |
if (is_array($errs)) { |
foreach ($errs as $error) { |
$e = $this->raiseError($error['message'], $error['code'], null, null, $error); |
} |
} |
|
return $pf; |
} |
|
/** |
* Returns information about a package file. Expects the name of |
* a gzipped tar file as input. |
* |
356,23 → 476,11 |
*/ |
function infoFromTgzFile($file) |
{ |
$packagefile = &new PEAR_PackageFile($this->config); |
$packagefile = new PEAR_PackageFile($this->config); |
$pf = &$packagefile->fromTgzFile($file, PEAR_VALIDATE_NORMAL); |
if (PEAR::isError($pf)) { |
$errs = $pf->getUserinfo(); |
if (is_array($errs)) { |
foreach ($errs as $error) { |
$e = $this->raiseError($error['message'], $error['code'], null, null, $error); |
} |
} |
return $pf; |
} |
return $this->_postProcessValidPackagexml($pf); |
return $this->_postProcessChecks($pf); |
} |
|
// }}} |
// {{{ infoFromDescriptionFile() |
|
/** |
* Returns information about a package file. Expects the name of |
* a package xml file as input. |
387,23 → 495,11 |
*/ |
function infoFromDescriptionFile($descfile) |
{ |
$packagefile = &new PEAR_PackageFile($this->config); |
$packagefile = new PEAR_PackageFile($this->config); |
$pf = &$packagefile->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); |
if (PEAR::isError($pf)) { |
$errs = $pf->getUserinfo(); |
if (is_array($errs)) { |
foreach ($errs as $error) { |
$e = $this->raiseError($error['message'], $error['code'], null, null, $error); |
} |
} |
return $pf; |
} |
return $this->_postProcessValidPackagexml($pf); |
return $this->_postProcessChecks($pf); |
} |
|
// }}} |
// {{{ infoFromString() |
|
/** |
* Returns information about a package file. Expects the contents |
* of a package xml file as input. |
418,20 → 514,10 |
*/ |
function infoFromString($data) |
{ |
$packagefile = &new PEAR_PackageFile($this->config); |
$packagefile = new PEAR_PackageFile($this->config); |
$pf = &$packagefile->fromXmlString($data, PEAR_VALIDATE_NORMAL, false); |
if (PEAR::isError($pf)) { |
$errs = $pf->getUserinfo(); |
if (is_array($errs)) { |
foreach ($errs as $error) { |
$e = $this->raiseError($error['message'], $error['code'], null, null, $error); |
} |
} |
return $pf; |
} |
return $this->_postProcessValidPackagexml($pf); |
return $this->_postProcessChecks($pf); |
} |
// }}} |
|
/** |
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2 |
439,37 → 525,24 |
*/ |
function _postProcessValidPackagexml(&$pf) |
{ |
if (is_a($pf, 'PEAR_PackageFile_v2')) { |
// sort of make this into a package.xml 1.0-style array |
// changelog is not converted to old format. |
$arr = $pf->toArray(true); |
$arr = array_merge($arr, $arr['old']); |
unset($arr['old']); |
unset($arr['xsdversion']); |
unset($arr['contents']); |
unset($arr['compatible']); |
unset($arr['channel']); |
unset($arr['uri']); |
unset($arr['dependencies']); |
unset($arr['phprelease']); |
unset($arr['extsrcrelease']); |
unset($arr['zendextsrcrelease']); |
unset($arr['extbinrelease']); |
unset($arr['zendextbinrelease']); |
unset($arr['bundle']); |
unset($arr['lead']); |
unset($arr['developer']); |
unset($arr['helper']); |
unset($arr['contributor']); |
$arr['filelist'] = $pf->getFilelist(); |
$this->pkginfo = $arr; |
return $arr; |
} else { |
if (!is_a($pf, 'PEAR_PackageFile_v2')) { |
$this->pkginfo = $pf->toArray(); |
return $this->pkginfo; |
} |
|
// sort of make this into a package.xml 1.0-style array |
// changelog is not converted to old format. |
$arr = $pf->toArray(true); |
$arr = array_merge($arr, $arr['old']); |
unset($arr['old'], $arr['xsdversion'], $arr['contents'], $arr['compatible'], |
$arr['channel'], $arr['uri'], $arr['dependencies'], $arr['phprelease'], |
$arr['extsrcrelease'], $arr['zendextsrcrelease'], $arr['extbinrelease'], |
$arr['zendextbinrelease'], $arr['bundle'], $arr['lead'], $arr['developer'], |
$arr['helper'], $arr['contributor']); |
$arr['filelist'] = $pf->getFilelist(); |
$this->pkginfo = $arr; |
return $arr; |
} |
// {{{ infoFromAny() |
|
/** |
* Returns package information from different sources |
485,7 → 558,7 |
function infoFromAny($info) |
{ |
if (is_string($info) && file_exists($info)) { |
$packagefile = &new PEAR_PackageFile($this->config); |
$packagefile = new PEAR_PackageFile($this->config); |
$pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL); |
if (PEAR::isError($pf)) { |
$errs = $pf->getUserinfo(); |
494,16 → 567,16 |
$e = $this->raiseError($error['message'], $error['code'], null, null, $error); |
} |
} |
|
return $pf; |
} |
|
return $this->_postProcessValidPackagexml($pf); |
} |
|
return $info; |
} |
|
// }}} |
// {{{ xmlFromInfo() |
|
/** |
* Return an XML document based on the package info (as returned |
* by the PEAR_Common::infoFrom* methods). |
517,16 → 590,13 |
*/ |
function xmlFromInfo($pkginfo) |
{ |
$config = &PEAR_Config::singleton(); |
$packagefile = &new PEAR_PackageFile($config); |
$config = &PEAR_Config::singleton(); |
$packagefile = new PEAR_PackageFile($config); |
$pf = &$packagefile->fromArray($pkginfo); |
$gen = &$pf->getDefaultGenerator(); |
return $gen->toXml(PEAR_VALIDATE_PACKAGING); |
} |
|
// }}} |
// {{{ validatePackageInfo() |
|
/** |
* Validate XML package definition file. |
* |
542,8 → 612,8 |
*/ |
function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '') |
{ |
$config = &PEAR_Config::singleton(); |
$packagefile = &new PEAR_PackageFile($config); |
$config = &PEAR_Config::singleton(); |
$packagefile = new PEAR_PackageFile($config); |
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); |
if (strpos($info, '<?xml') !== false) { |
$pf = &$packagefile->fromXmlString($info, PEAR_VALIDATE_NORMAL, ''); |
550,6 → 620,7 |
} else { |
$pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL); |
} |
|
PEAR::staticPopErrorHandling(); |
if (PEAR::isError($pf)) { |
$errs = $pf->getUserinfo(); |
562,14 → 633,13 |
} |
} |
} |
|
return false; |
} |
|
return true; |
} |
|
// }}} |
// {{{ buildProvidesArray() |
|
/** |
* Build a "provides" array from data returned by |
* analyzeSourceCode(). The format of the built array is like |
596,6 → 666,7 |
if (isset($this->_packageName)) { |
$pn = $this->_packageName; |
} |
|
$pnl = strlen($pn); |
foreach ($srcinfo['declared_classes'] as $class) { |
$key = "class;$class"; |
602,6 → 673,7 |
if (isset($this->pkginfo['provides'][$key])) { |
continue; |
} |
|
$this->pkginfo['provides'][$key] = |
array('file'=> $file, 'type' => 'class', 'name' => $class); |
if (isset($srcinfo['inheritance'][$class])) { |
609,6 → 681,7 |
$srcinfo['inheritance'][$class]; |
} |
} |
|
foreach ($srcinfo['declared_methods'] as $class => $methods) { |
foreach ($methods as $method) { |
$function = "$class::$method"; |
617,6 → 690,7 |
isset($this->pkginfo['provides'][$key])) { |
continue; |
} |
|
$this->pkginfo['provides'][$key] = |
array('file'=> $file, 'type' => 'function', 'name' => $function); |
} |
627,17 → 701,16 |
if ($function{0} == '_' || isset($this->pkginfo['provides'][$key])) { |
continue; |
} |
|
if (!strstr($function, '::') && strncasecmp($function, $pn, $pnl)) { |
$warnings[] = "in1 " . $file . ": function \"$function\" not prefixed with package name \"$pn\""; |
} |
|
$this->pkginfo['provides'][$key] = |
array('file'=> $file, 'type' => 'function', 'name' => $function); |
} |
} |
|
// }}} |
// {{{ analyzeSourceCode() |
|
/** |
* Analyze the source code of the given PHP file |
* |
647,231 → 720,28 |
*/ |
function analyzeSourceCode($file) |
{ |
if (!function_exists("token_get_all")) { |
return false; |
if (!class_exists('PEAR_PackageFile_v2_Validator')) { |
require_once 'PEAR/PackageFile/v2/Validator.php'; |
} |
if (!defined('T_DOC_COMMENT')) { |
define('T_DOC_COMMENT', T_COMMENT); |
} |
if (!defined('T_INTERFACE')) { |
define('T_INTERFACE', -1); |
} |
if (!defined('T_IMPLEMENTS')) { |
define('T_IMPLEMENTS', -1); |
} |
if (!$fp = @fopen($file, "r")) { |
return false; |
} |
fclose($fp); |
$contents = file_get_contents($file); |
$tokens = token_get_all($contents); |
/* |
for ($i = 0; $i < sizeof($tokens); $i++) { |
@list($token, $data) = $tokens[$i]; |
if (is_string($token)) { |
var_dump($token); |
} else { |
print token_name($token) . ' '; |
var_dump(rtrim($data)); |
} |
} |
*/ |
$look_for = 0; |
$paren_level = 0; |
$bracket_level = 0; |
$brace_level = 0; |
$lastphpdoc = ''; |
$current_class = ''; |
$current_interface = ''; |
$current_class_level = -1; |
$current_function = ''; |
$current_function_level = -1; |
$declared_classes = array(); |
$declared_interfaces = array(); |
$declared_functions = array(); |
$declared_methods = array(); |
$used_classes = array(); |
$used_functions = array(); |
$extends = array(); |
$implements = array(); |
$nodeps = array(); |
$inquote = false; |
$interface = false; |
for ($i = 0; $i < sizeof($tokens); $i++) { |
if (is_array($tokens[$i])) { |
list($token, $data) = $tokens[$i]; |
} else { |
$token = $tokens[$i]; |
$data = ''; |
} |
if ($inquote) { |
if ($token != '"') { |
continue; |
} else { |
$inquote = false; |
continue; |
} |
} |
switch ($token) { |
case T_WHITESPACE: |
continue; |
case ';': |
if ($interface) { |
$current_function = ''; |
$current_function_level = -1; |
} |
break; |
case '"': |
$inquote = true; |
break; |
case T_CURLY_OPEN: |
case T_DOLLAR_OPEN_CURLY_BRACES: |
case '{': $brace_level++; continue 2; |
case '}': |
$brace_level--; |
if ($current_class_level == $brace_level) { |
$current_class = ''; |
$current_class_level = -1; |
} |
if ($current_function_level == $brace_level) { |
$current_function = ''; |
$current_function_level = -1; |
} |
continue 2; |
case '[': $bracket_level++; continue 2; |
case ']': $bracket_level--; continue 2; |
case '(': $paren_level++; continue 2; |
case ')': $paren_level--; continue 2; |
case T_INTERFACE: |
$interface = true; |
case T_CLASS: |
if (($current_class_level != -1) || ($current_function_level != -1)) { |
PEAR::raiseError("Parser error: invalid PHP found in file \"$file\"", |
PEAR_COMMON_ERROR_INVALIDPHP); |
return false; |
} |
case T_FUNCTION: |
case T_NEW: |
case T_EXTENDS: |
case T_IMPLEMENTS: |
$look_for = $token; |
continue 2; |
case T_STRING: |
if (version_compare(zend_version(), '2.0', '<')) { |
if (in_array(strtolower($data), |
array('public', 'private', 'protected', 'abstract', |
'interface', 'implements', 'throw') |
)) { |
PEAR::raiseError('Error: PHP5 token encountered in ' . $file . |
'packaging should be done in PHP 5'); |
return false; |
} |
} |
if ($look_for == T_CLASS) { |
$current_class = $data; |
$current_class_level = $brace_level; |
$declared_classes[] = $current_class; |
} elseif ($look_for == T_INTERFACE) { |
$current_interface = $data; |
$current_class_level = $brace_level; |
$declared_interfaces[] = $current_interface; |
} elseif ($look_for == T_IMPLEMENTS) { |
$implements[$current_class] = $data; |
} elseif ($look_for == T_EXTENDS) { |
$extends[$current_class] = $data; |
} elseif ($look_for == T_FUNCTION) { |
if ($current_class) { |
$current_function = "$current_class::$data"; |
$declared_methods[$current_class][] = $data; |
} elseif ($current_interface) { |
$current_function = "$current_interface::$data"; |
$declared_methods[$current_interface][] = $data; |
} else { |
$current_function = $data; |
$declared_functions[] = $current_function; |
} |
$current_function_level = $brace_level; |
$m = array(); |
} elseif ($look_for == T_NEW) { |
$used_classes[$data] = true; |
} |
$look_for = 0; |
continue 2; |
case T_VARIABLE: |
$look_for = 0; |
continue 2; |
case T_DOC_COMMENT: |
case T_COMMENT: |
if (preg_match('!^/\*\*\s!', $data)) { |
$lastphpdoc = $data; |
if (preg_match_all('/@nodep\s+(\S+)/', $lastphpdoc, $m)) { |
$nodeps = array_merge($nodeps, $m[1]); |
} |
} |
continue 2; |
case T_DOUBLE_COLON: |
if (!($tokens[$i - 1][0] == T_WHITESPACE || $tokens[$i - 1][0] == T_STRING)) { |
PEAR::raiseError("Parser error: invalid PHP found in file \"$file\"", |
PEAR_COMMON_ERROR_INVALIDPHP); |
return false; |
} |
$class = $tokens[$i - 1][1]; |
if (strtolower($class) != 'parent') { |
$used_classes[$class] = true; |
} |
continue 2; |
} |
} |
return array( |
"source_file" => $file, |
"declared_classes" => $declared_classes, |
"declared_interfaces" => $declared_interfaces, |
"declared_methods" => $declared_methods, |
"declared_functions" => $declared_functions, |
"used_classes" => array_diff(array_keys($used_classes), $nodeps), |
"inheritance" => $extends, |
"implements" => $implements, |
); |
} |
|
// }}} |
// {{{ betterStates() |
|
/** |
* Return an array containing all of the states that are more stable than |
* or equal to the passed in state |
* |
* @param string Release state |
* @param boolean Determines whether to include $state in the list |
* @return false|array False if $state is not a valid release state |
*/ |
function betterStates($state, $include = false) |
{ |
static $states = array('snapshot', 'devel', 'alpha', 'beta', 'stable'); |
$i = array_search($state, $states); |
if ($i === false) { |
return false; |
} |
if ($include) { |
$i--; |
} |
return array_slice($states, $i + 1); |
$a = new PEAR_PackageFile_v2_Validator; |
return $a->analyzeSourceCode($file); |
} |
|
// }}} |
// {{{ detectDependencies() |
|
function detectDependencies($any, $status_callback = null) |
{ |
if (!function_exists("token_get_all")) { |
return false; |
} |
|
if (PEAR::isError($info = $this->infoFromAny($any))) { |
return $this->raiseError($info); |
} |
|
if (!is_array($info)) { |
return false; |
} |
|
$deps = array(); |
$used_c = $decl_c = $decl_f = $decl_m = array(); |
foreach ($info['filelist'] as $file => $fa) { |
882,9 → 752,11 |
$decl_m = @array_merge($decl_m, $tmp['declared_methods']); |
$inheri = @array_merge($inheri, $tmp['inheritance']); |
} |
|
$used_c = array_unique($used_c); |
$decl_c = array_unique($decl_c); |
$undecl_c = array_diff($used_c, $decl_c); |
|
return array('used_classes' => $used_c, |
'declared_classes' => $decl_c, |
'declared_methods' => $decl_m, |
894,159 → 766,7 |
); |
} |
|
// }}} |
// {{{ getUserRoles() |
|
/** |
* Get the valid roles for a PEAR package maintainer |
* |
* @return array |
* @static |
*/ |
function getUserRoles() |
{ |
return $GLOBALS['_PEAR_Common_maintainer_roles']; |
} |
|
// }}} |
// {{{ getReleaseStates() |
|
/** |
* Get the valid package release states of packages |
* |
* @return array |
* @static |
*/ |
function getReleaseStates() |
{ |
return $GLOBALS['_PEAR_Common_release_states']; |
} |
|
// }}} |
// {{{ getDependencyTypes() |
|
/** |
* Get the implemented dependency types (php, ext, pkg etc.) |
* |
* @return array |
* @static |
*/ |
function getDependencyTypes() |
{ |
return $GLOBALS['_PEAR_Common_dependency_types']; |
} |
|
// }}} |
// {{{ getDependencyRelations() |
|
/** |
* Get the implemented dependency relations (has, lt, ge etc.) |
* |
* @return array |
* @static |
*/ |
function getDependencyRelations() |
{ |
return $GLOBALS['_PEAR_Common_dependency_relations']; |
} |
|
// }}} |
// {{{ getFileRoles() |
|
/** |
* Get the implemented file roles |
* |
* @return array |
* @static |
*/ |
function getFileRoles() |
{ |
return $GLOBALS['_PEAR_Common_file_roles']; |
} |
|
// }}} |
// {{{ getReplacementTypes() |
|
/** |
* Get the implemented file replacement types in |
* |
* @return array |
* @static |
*/ |
function getReplacementTypes() |
{ |
return $GLOBALS['_PEAR_Common_replacement_types']; |
} |
|
// }}} |
// {{{ getProvideTypes() |
|
/** |
* Get the implemented file replacement types in |
* |
* @return array |
* @static |
*/ |
function getProvideTypes() |
{ |
return $GLOBALS['_PEAR_Common_provide_types']; |
} |
|
// }}} |
// {{{ getScriptPhases() |
|
/** |
* Get the implemented file replacement types in |
* |
* @return array |
* @static |
*/ |
function getScriptPhases() |
{ |
return $GLOBALS['_PEAR_Common_script_phases']; |
} |
|
// }}} |
// {{{ validPackageName() |
|
/** |
* Test whether a string contains a valid package name. |
* |
* @param string $name the package name to test |
* |
* @return bool |
* |
* @access public |
*/ |
function validPackageName($name) |
{ |
return (bool)preg_match(PEAR_COMMON_PACKAGE_NAME_PREG, $name); |
} |
|
|
// }}} |
// {{{ validPackageVersion() |
|
/** |
* Test whether a string contains a valid package version. |
* |
* @param string $ver the package version to test |
* |
* @return bool |
* |
* @access public |
*/ |
function validPackageVersion($ver) |
{ |
return (bool)preg_match(PEAR_COMMON_PACKAGE_VERSION_PREG, $ver); |
} |
|
|
// }}} |
|
// {{{ downloadHttp() |
|
/** |
* Download a file through HTTP. Considers suggested file name in |
* Content-disposition: header and can run a callback function for |
* different events. The callback will be called with two |
1081,46 → 801,38 |
* @param string $save_dir (optional) directory to save file in |
* @param mixed $callback (optional) function/method to call for status |
* updates |
* @param false|string|array $lastmodified header values to check against |
* for caching |
* use false to return the header |
* values from this download |
* @param false|array $accept Accept headers to send |
* @param false|string $channel Channel to use for retrieving |
* authentication |
* |
* @return string Returns the full path of the downloaded file or a PEAR |
* error on failure. If the error is caused by |
* socket-related errors, the error object will |
* have the fsockopen error code available through |
* getCode(). |
* @return mixed Returns the full path of the downloaded file or a PEAR |
* error on failure. If the error is caused by |
* socket-related errors, the error object will |
* have the fsockopen error code available through |
* getCode(). If caching is requested, then return the header |
* values. |
* If $lastmodified was given and the there are no changes, |
* boolean false is returned. |
* |
* @access public |
* @deprecated in favor of PEAR_Downloader::downloadHttp() |
*/ |
function downloadHttp($url, &$ui, $save_dir = '.', $callback = null) |
{ |
function downloadHttp( |
$url, &$ui, $save_dir = '.', $callback = null, $lastmodified = null, |
$accept = false, $channel = false |
) { |
if (!class_exists('PEAR_Downloader')) { |
require_once 'PEAR/Downloader.php'; |
} |
return PEAR_Downloader::downloadHttp($url, $ui, $save_dir, $callback); |
return PEAR_Downloader::_downloadHttp( |
$this, $url, $ui, $save_dir, $callback, $lastmodified, |
$accept, $channel |
); |
} |
} |
|
// }}} |
|
/** |
* @param string $path relative or absolute include path |
* @return boolean |
* @static |
*/ |
function isIncludeable($path) |
{ |
if (file_exists($path) && is_readable($path)) { |
return true; |
} |
$ipath = explode(PATH_SEPARATOR, ini_get('include_path')); |
foreach ($ipath as $include) { |
$test = realpath($include . DIRECTORY_SEPARATOR . $path); |
if (file_exists($test) && is_readable($test)) { |
return true; |
} |
} |
return false; |
} |
} |
require_once 'PEAR/Config.php'; |
require_once 'PEAR/PackageFile.php'; |
?> |