Last active
December 24, 2015 17:33
-
-
Save zonuexe/e35355d686d501322cd3 to your computer and use it in GitHub Desktop.
php.netのバージョン表記をパースするやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
/** | |
* phpnet_version_parse.php | |
* | |
* @author USAMI Kenta <tadsan@zonu.me> | |
* @copyright 2015 USAMI Kenta | |
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 | |
*/ | |
const URL = 'http://doc.php.net/downloads/json/php_manual_en.json'; | |
const FILE = './php_manual_en.json'; | |
if (!file_exists(FILE)) { | |
file_put_contents(FILE, fopen(URL, 'r')); | |
} | |
$list_all = isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] === 'all'; | |
$whitelist = ['PHP 4', 'PHP 5', 'PHP 5.4', 'PHP 5.5', 'PHP 5.6', 'PHP 7', 'intl', 'mysqli', 'imagick']; | |
$dic = []; | |
$count = 0; | |
foreach (json_decode(file_get_contents(FILE), true) as $name => $func) { | |
$cat = category($name, $func['versions']); | |
unset($func['versions']); | |
if ($list_all || in_array($cat, $whitelist, true)) { | |
$count++; | |
$dic[$cat][$name] = $func; | |
} | |
} | |
//echo $count, PHP_EOL;exit; | |
echo json_encode($dic, JSON_PRETTY_PRINT), PHP_EOL; | |
exit; | |
function category ($name, $ver) | |
{ | |
static $php7_removed = [ | |
'mcrypt_generic_end', 'mcrypt_ecb', 'mcrypt_cbc', 'mcrypt_cfb', 'mcrypt_ofb', | |
'datefmt_set_timezone_id', 'IntlDateFormatter::setTimeZoneID', | |
'set_magic_quotes_runtime', 'magic_quotes_runtime', 'set_socket_blocking' | |
]; | |
if (in_array($name, $php7_removed, true)) { | |
return 'obsolete PHP 7'; | |
} | |
if (strpos($name, 'DateTime') === 0 || strpos($name, 'Phar') === 0) { | |
return 'PHP 5'; | |
} | |
if (stripos($name, 'KTagLib_') === 0) { | |
return 'PECL ktaglib'; | |
} | |
if (strpos($name, 'QuickHash') === 0) { | |
return 'PECL quickhash'; | |
} | |
if (strpos($name, 'SDO_') === 0) { | |
return 'PECL SCA_SDO'; | |
} | |
if (strpos($name, 'filepro') === 0) { | |
return 'filepro'; | |
} | |
if (strpos($name, 'Imagick') === 0) { | |
return 'imagick'; | |
} | |
if (stripos($name, 'Intl') === 0 || strpos($name, 'UConverter') === 0) { | |
return 'intl'; | |
} | |
if (stripos($name, 'soap') === 0 || $name === 'is_soap_fault' || $name === 'use_soap_error_handler') { | |
return 'SOAP'; | |
} | |
if (stripos($name, 'sqlite') === 0) { | |
return 'PECL sqlite'; | |
} | |
if (strpos($name, 'mysqli') === 0) { | |
return 'mysqli'; | |
} | |
if (strpos($name, 'ifx_') === 0 || strpos($name, 'ifxus_') === 0) { | |
return 'informix'; | |
} | |
if (strpos($name, 'ibase_') === 0) { | |
return 'Firebird'; | |
} | |
if (strpos($name, 'cubrid') === 0) { | |
return 'CUBRID'; | |
} | |
if (strpos($name, 'dbase_') === 0) { | |
return 'dBase'; | |
} | |
if (strpos($name, 'dbplus_') === 0) { | |
return 'DB++'; | |
} | |
if (strpos($name, 'fbsql_') === 0) { | |
return 'FrontBase'; | |
} | |
if (strpos($name, 'ingres_') === 0) { | |
return 'Ingres'; | |
} | |
if (strpos($name, 'maxdb') === 0) { | |
return 'MaxDB'; | |
} | |
if (strpos($name, 'msql_') === 0) { | |
return 'mSQL'; | |
} | |
if (strpos($name, 'mssql_') === 0) { | |
return 'Mssql'; | |
} | |
if (strpos($name, 'px_') === 0) { | |
return 'Paradox'; | |
} | |
if (strpos($name, 'pg_') === 0) { | |
return 'PostgreSQL'; | |
} | |
if (strpos($name, 'SQLite3') === 0) { | |
return 'SQLite3'; | |
} | |
if (strpos($name, 'sqlsrv_') === 0) { | |
return 'SQLSRV'; | |
} | |
if (strpos($name, 'sybase_') === 0) { | |
return 'Sybase'; | |
} | |
if (strpos($name, 'TokyoTyrant') === 0) { | |
return 'TokyoTyrant'; | |
} | |
if (strpos($name, 'tidy') === 0 || $name === 'ob_tidyhandler') { | |
return 'tidy'; | |
} | |
if (strpos($name, 'yp_') === 0 || strpos($name, 'fam_') === 0) { | |
return 'obsolete PHP 5'; | |
} | |
if (strpos($ver, 'Yaf >=') === 0) { | |
return 'PECL Yaf'; | |
} | |
if (strpos($ver, 'mongodb') === 0) { | |
return 'PECL mongodb'; | |
} | |
if ($ver === '' || $ver === 'Unknown' || $ver === 'None') { | |
return 'other'; | |
} | |
if (strpos($ver, 'phar') !== false || strpos($ver, 'PECL pdo') !== false || | |
strpos($ver, 'PECL json') !== false || strpos($ver, 'PECL zip') !== false | |
) { | |
return 'PHP 5'; | |
} | |
if (preg_match('/(PECL [-_a-zA-Z0-9]+)(?: >=)?/', $ver, $matches)) { | |
return $matches[1]; | |
} | |
if ($name === 'ldap_modify_batch') { | |
return 'PHP 5.4'; | |
} | |
if ($name === 'PDF_set_text_matrix') { | |
return 'obsolete PHP 4'; | |
} | |
static $obsolete_5 = [ | |
'session_register', 'session_unregister', 'session_is_registered', 'php_check_syntax', | |
'php_logo_guid', 'zend_logo_guid', 'define_syslog_variables' | |
]; | |
if (in_array($name, $obsolete_5, true)) { | |
return 'obsolete PHP 5'; | |
} | |
if ($ver === 'PHP 7') { | |
return 'PHP 7'; | |
} | |
if ($ver === 'PHP 4, PHP 5, PHP 7' || $ver === 'PHP 4, PHP 5') { | |
return 'PHP 4'; | |
} | |
if ($ver === 'PHP 5, PHP 7') { | |
return 'PHP 5'; | |
} | |
//$is_support_7 = strpos($ver, 'PHP 7') !== false; | |
if (preg_match('/^PHP 4 >= 4\..+, PHP 5/', $ver)) { | |
return 'PHP 4'; | |
} | |
if (strpos($ver, 'PHP 5 >') === 0) { | |
return 'PHP 5'; | |
} | |
if (preg_match('/^PHP 5, PHP 7 >= (5\.[0-9])\.[0-9]/', $ver, $matches)) { | |
return (version_compare(5.3, $matches[1]) <= 0) ? "PHP {$matches[1]}" : 'PHP 5'; | |
} | |
if (preg_match('/^PHP ?>= ?(5.[0-9])(?:\.[0-9]+)?$/', $ver, $matches)) { | |
return (version_compare(5.3, $matches[1]) <= 0) ? "PHP {$matches[1]}" : 'PHP 5'; | |
} | |
if (strpos('PHP 5 <', $ver) === 0) { | |
return 'obsolete PHP 5'; | |
} | |
if (strpos('PHP 4 <', $ver) === 0) { | |
return 'obsolete PHP 4'; | |
} | |
return $ver; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CUBRID | |
DB++ | |
Firebird | |
FrontBase | |
Ingres | |
MaxDB | |
Mssql | |
PECL OAuth | |
PECL OCI8 | |
PECL SCA_SDO | |
PECL SDO | |
PECL Yaf | |
PECL ZendOpcache | |
PECL apc | |
PECL apcu | |
PECL apd | |
PECL bbcode | |
PECL bcompiler | |
PECL blenc | |
PECL cairo | |
PECL chdb | |
PECL classkit | |
PECL crack | |
PECL cyrus | |
PECL dbx | |
PECL eio | |
PECL enchant | |
PECL ev | |
PECL event | |
PECL expect | |
PECL fann | |
PECL fileinfo | |
PECL fribidi | |
PECL gearman | |
PECL gender | |
PECL geoip | |
PECL gmagick | |
PECL gnupg | |
PECL gupnp | |
PECL haru | |
PECL hash | |
PECL hrtime | |
PECL hwapi | |
PECL ibm_db2 | |
PECL id3 | |
PECL iisfunc | |
PECL imagick | |
PECL inclued | |
PECL inotify | |
PECL intl | |
PECL json | |
PECL judy | |
PECL kadm5 | |
PECL ktaglib | |
PECL lapack | |
PECL libevent | |
PECL lua | |
PECL lzf | |
PECL mailparse | |
PECL mcve | |
PECL memcache | |
PECL memcached | |
PECL ming | |
PECL mnogosearch | |
PECL mongo | |
PECL mongodb | |
PECL mqseries | |
PECL mysqlnd-uh | |
PECL mysqlnd_memcache | |
PECL mysqlnd_ms | |
PECL mysqlnd_qc | |
PECL ncurses | |
PECL net_gopher | |
PECL newt | |
PECL openal | |
PECL parsekit | |
PECL pdflib | |
PECL pdo | |
PECL pdo_pgsql | |
PECL pdo_sqlite | |
PECL pecl_http | |
PECL phar | |
PECL proctitle | |
PECL ps | |
PECL pthreads | |
PECL quickhash | |
PECL radius | |
PECL rar | |
PECL rpmreader | |
PECL rrd | |
PECL runkit | |
PECL sam | |
PECL session_pgsql | |
PECL solr | |
PECL sphinx | |
PECL spl_types | |
PECL spplus | |
PECL sqlite | |
PECL ssdeep | |
PECL ssh2 | |
PECL stats | |
PECL stomp | |
PECL svm | |
PECL svn | |
PECL swish | |
PECL sync | |
PECL taint | |
PECL tcpwrap | |
PECL tidy | |
PECL trader | |
PECL uopz | |
PECL v8js | |
PECL varnish | |
PECL vpopmail | |
PECL weakref | |
PECL win32ps | |
PECL win32service | |
PECL wincache | |
PECL xattr | |
PECL xdiff | |
PECL xhprof | |
PECL xmldiff | |
PECL xmlwriter | |
PECL yaml | |
PECL yar | |
PECL yaz | |
PECL zip | |
PECL zmq | |
PHP 4 | |
PHP 5 | |
PHP 5.3 | |
PHP 5.4 | |
PHP 5.5 | |
PHP 5.6 | |
PHP 7 | |
Paradox | |
PostgreSQL | |
SQLSRV | |
Sybase | |
TokyoTyrant | |
dBase | |
filepro | |
informix | |
mSQL | |
mysqli | |
obsolete PHP 4 | |
obsolete PHP 5 | |
obsolete PHP 7 | |
other |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment