📄 common.php
字号:
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);
}
// }}}
// {{{ 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) {
$tmp = $this->analyzeSourceCode($file);
$used_c = @array_merge($used_c, $tmp['used_classes']);
$decl_c = @array_merge($decl_c, $tmp['declared_classes']);
$decl_f = @array_merge($decl_f, $tmp['declared_functions']);
$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,
'declared_functions' => $decl_f,
'undeclared_classes' => $undecl_c,
'inheritance' => $inheri,
);
}
// }}}
// {{{ 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
* parameters: the callback type, and parameters. The implemented
* callback types are:
*
* 'setup' called at the very beginning, parameter is a UI object
* that should be used for all output
* 'message' the parameter is a string with an informational message
* 'saveas' may be used to save with a different file name, the
* parameter is the filename that is about to be used.
* If a 'saveas' callback returns a non-empty string,
* that file name will be used as the filename instead.
* Note that $save_dir will not be affected by this, only
* the basename of the file.
* 'start' download is starting, parameter is number of bytes
* that are expected, or -1 if unknown
* 'bytesread' parameter is the number of bytes read so far
* 'done' download is complete, parameter is the total number
* of bytes read
* 'connfailed' if the TCP connection fails, this callback is called
* with array(host,port,errno,errmsg)
* 'writefailed' if writing to disk fails, this callback is called
* with array(destfile,errmsg)
*
* If an HTTP proxy has been configured (http_proxy PEAR_Config
* setting), the proxy will be used.
*
* @param string $url the URL to download
* @param object $ui PEAR_Frontend_* instance
* @param object $config PEAR_Config instance
* @param string $save_dir (optional) directory to save file in
* @param mixed $callback (optional) function/method to call for status
* updates
*
* @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().
*
* @access public
* @deprecated in favor of PEAR_Downloader::downloadHttp()
*/
function downloadHttp($url, &$ui, $save_dir = '.', $callback = null)
{
if (!class_exists('PEAR_Downloader')) {
require_once 'PEAR/Downloader.php';
}
return PEAR_Downloader::downloadHttp($url, $ui, $save_dir, $callback);
}
// }}}
/**
* @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';
if (!function_exists('file_get_contents')) {
function file_get_contents($filename)
{
$fp = fopen($filename, 'rb');
$ret = '';
while (!feof($fp)) {
$ret .= fread($fp, 8092);;
}
return $ret;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -