📄 dependency.php
字号:
if (!extension_loaded($name)) { if ($relation == 'ne') { return false; } if ($opt) { $errmsg = "'$name' PHP extension is recommended to utilize some features"; return PEAR_DEPENDENCY_MISSING_OPTIONAL; } $errmsg = "'$name' PHP extension is not installed"; return PEAR_DEPENDENCY_MISSING; } if ($relation == 'has') { return false; } $code = false; if (is_string($req) && substr($req, 0, 2) == 'v.') { $req = substr($req, 2); } $ext_ver = phpversion($name); $operator = $relation; // Force params to be strings, otherwise the comparation will fail (ex. 0.9==0.90) if (!version_compare("$ext_ver", "$req", $operator)) { $errmsg = "'$name' PHP extension version " . $this->signOperator($operator) . " $req is required"; $code = $this->codeFromRelation($relation, $ext_ver, $req, $opt); if ($opt) { $errmsg = "'$name' PHP extension version " . $this->signOperator($operator) . " $req is recommended to utilize some features"; return $code; } } return $code; } // }}} // {{{ checkOS() /** * Operating system dependencies check method * * @param string $os Name of the operating system * * @return mixed bool false if no error or the error string */ function checkOS(&$errmsg, $os) { // XXX Fixme: Implement a more flexible way, like // comma separated values or something similar to PEAR_OS static $myos; if (empty($myos)) { include_once "OS/Guess.php"; $myos = new OS_Guess(); } // only 'has' relation is currently supported if ($myos->matchSignature($os)) { return false; } $errmsg = "'$os' operating system not supported"; return PEAR_DEPENDENCY_CONFLICT; } // }}} // {{{ checkPHP() /** * PHP version check method * * @param string $req which version to compare * @param string $relation how to compare the version * * @return mixed bool false if no error or the error string */ function checkPHP(&$errmsg, $req, $relation = 'ge') { // this would be a bit stupid, but oh well :) if ($relation == 'has') { return false; } if ($relation == 'not') { $errmsg = "Invalid dependency - 'not' is allowed when specifying PHP, you must run PHP in PHP"; return PEAR_DEPENDENCY_BAD_DEPENDENCY; } if (substr($req, 0, 2) == 'v.') { $req = substr($req,2, strlen($req) - 2); } $php_ver = phpversion(); $operator = $relation; if (!version_compare("$php_ver", "$req", $operator)) { $errmsg = "PHP version " . $this->signOperator($operator) . " $req is required"; return PEAR_DEPENDENCY_CONFLICT; } return false; } // }}} // {{{ checkProgram() /** * External program check method. Looks for executable files in * directories listed in the PATH environment variable. * * @param string $program which program to look for * * @return mixed bool false if no error or the error string */ function checkProgram(&$errmsg, $program) { // XXX FIXME honor safe mode $exe_suffix = OS_WINDOWS ? '.exe' : ''; $path_elements = explode(PATH_SEPARATOR, getenv('PATH')); foreach ($path_elements as $dir) { $file = $dir . DIRECTORY_SEPARATOR . $program . $exe_suffix; if (@file_exists($file) && @is_executable($file)) { return false; } } $errmsg = "'$program' program is not present in the PATH"; return PEAR_DEPENDENCY_MISSING; } // }}} // {{{ checkSAPI() /** * SAPI backend check method. Version comparison is not yet * available here. * * @param string $name name of SAPI backend * @param string $req which version to compare * @param string $relation how to compare versions (currently * hardcoded to 'has') * @return mixed bool false if no error or the error string */ function checkSAPI(&$errmsg, $name, $req = null, $relation = 'has') { // XXX Fixme: There is no way to know if the user has or // not other SAPI backends installed than the installer one $sapi_backend = php_sapi_name(); // Version comparisons not supported, sapi backends don't have // version information yet. if ($sapi_backend == $name) { return false; } $errmsg = "'$sapi_backend' SAPI backend not supported"; return PEAR_DEPENDENCY_CONFLICT; } // }}} // {{{ checkZend() /** * Zend version check method * * @param string $req which version to compare * @param string $relation how to compare the version * * @return mixed bool false if no error or the error string */ function checkZend(&$errmsg, $req, $relation = 'ge') { if (substr($req, 0, 2) == 'v.') { $req = substr($req,2, strlen($req) - 2); } $zend_ver = zend_version(); $operator = substr($relation,0,2); if (!version_compare("$zend_ver", "$req", $operator)) { $errmsg = "Zend version " . $this->signOperator($operator) . " $req is required"; return PEAR_DEPENDENCY_CONFLICT; } return false; } // }}} // {{{ signOperator() /** * Converts text comparing operators to them sign equivalents * * Example: 'ge' to '>=' * * @access public * @param string Operator * @return string Sign equivalent */ function signOperator($operator) { switch($operator) { case 'lt': return '<'; case 'le': return '<='; case 'gt': return '>'; case 'ge': return '>='; case 'eq': return '=='; case 'ne': return '!='; default: return $operator; } } // }}} // {{{ codeFromRelation() /** * Convert relation into corresponding code * * @access public * @param string Relation * @param string Version * @param string Requirement * @param bool Optional dependency indicator * @return integer */ function codeFromRelation($relation, $version, $req, $opt = false) { $code = PEAR_DEPENDENCY_BAD_DEPENDENCY; switch ($relation) { case 'gt': case 'ge': case 'eq': // upgrade $have_major = preg_replace('/\D.*/', '', $version); $need_major = preg_replace('/\D.*/', '', $req); if ($need_major > $have_major) { $code = $opt ? PEAR_DEPENDENCY_UPGRADE_MAJOR_OPTIONAL : PEAR_DEPENDENCY_UPGRADE_MAJOR; } else { $code = $opt ? PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL : PEAR_DEPENDENCY_UPGRADE_MINOR; } break; case 'lt': case 'le': case 'ne': $code = $opt ? PEAR_DEPENDENCY_CONFLICT_OPTIONAL : PEAR_DEPENDENCY_CONFLICT; break; } return $code; } // }}}}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -