风险系数判断修复
This commit is contained in:
Executable
+10
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$standaloneAutoloader = __DIR__ . '/../vendor/autoload.php';
|
||||
$packageAutoloader = __DIR__ . '/../../../autoload.php';
|
||||
|
||||
if (file_exists($packageAutoloader)) {
|
||||
require_once $packageAutoloader;
|
||||
} else {
|
||||
require_once $standaloneAutoloader;
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
use WhichBrowser\Parser;
|
||||
|
||||
$command = 'exec';
|
||||
$options = [];
|
||||
$payload = [];
|
||||
|
||||
array_shift($argv);
|
||||
|
||||
if (count($argv)) {
|
||||
foreach ($argv as $argument) {
|
||||
if (in_array($argument, [ 'exec' ])) {
|
||||
$command = $argument;
|
||||
} elseif (substr($argument, 0, 2) == '--') {
|
||||
$options[] = substr($argument, 2);
|
||||
} else {
|
||||
$payload[] = $argument;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$payload = implode(' ', $payload);
|
||||
|
||||
|
||||
if ($command == 'exec') {
|
||||
if ($payload == '') {
|
||||
$payload = file_get_contents('php://stdin');
|
||||
}
|
||||
|
||||
if ($payload != '') {
|
||||
echo "\n\033[0;32mInput:\033[0;0m\n" . trim($payload) . "\n";
|
||||
|
||||
$result = new Parser(trim($payload));
|
||||
echo "\n\033[0;32mHuman readable:\033[0;0m\n" . $result->toString() . "\n";
|
||||
echo "\n\033[0;32mData:\033[0;0m\n";
|
||||
echo json_encode($result, JSON_PRETTY_PRINT);
|
||||
echo "\n\n";
|
||||
}
|
||||
}
|
||||
Executable
+103
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
use WhichBrowser\Testrunner;
|
||||
use WhichBrowser\Tests;
|
||||
use SebastianBergmann\CodeCoverage\CodeCoverage;
|
||||
use SebastianBergmann\CodeCoverage\Report\Clover;
|
||||
|
||||
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
|
||||
// error was suppressed with the @-operator
|
||||
if (0 === error_reporting()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
|
||||
});
|
||||
|
||||
|
||||
|
||||
$all = false;
|
||||
$command = 'compare';
|
||||
$files = [];
|
||||
$options = [];
|
||||
|
||||
array_shift($argv);
|
||||
|
||||
if (count($argv)) {
|
||||
foreach ($argv as $argument) {
|
||||
if (in_array($argument, [ 'compare', 'check', 'rebase', 'list' ])) {
|
||||
$command = $argument;
|
||||
} elseif (substr($argument, 0, 2) == '--') {
|
||||
$options[] = substr($argument, 2);
|
||||
} else {
|
||||
if (fnmatch("*.yaml", $argument)) {
|
||||
$files[] = $argument;
|
||||
} else {
|
||||
$files = array_merge($files, Tests::getFromCategory($argument));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($files) === 0) {
|
||||
$files = Tests::getAll();
|
||||
}
|
||||
|
||||
switch ($command) {
|
||||
case 'list':
|
||||
Testrunner::search($files);
|
||||
break;
|
||||
|
||||
case 'check':
|
||||
if (in_array('coverage', $options)) {
|
||||
$coverage = new CodeCoverage;
|
||||
$coverage->filter()->addDirectoryToWhitelist('src');
|
||||
$coverage->start('Testrunner');
|
||||
}
|
||||
|
||||
$result = Testrunner::compare($files, false);
|
||||
|
||||
if (in_array('coverage', $options)) {
|
||||
$coverage->stop();
|
||||
|
||||
$writer = new Clover;
|
||||
$writer->process($coverage, 'runner.xml');
|
||||
|
||||
echo "\nCoverage saved as runner.xml\n\n";
|
||||
}
|
||||
|
||||
if (!$result) {
|
||||
echo "\033[0;31mTestrunner failed, please fix or rebase before building or deploying!\033[0m\n\n";
|
||||
|
||||
if (in_array('show', $options)) {
|
||||
echo file_get_contents('runner.log') . "\n\n";
|
||||
echo "Done!\n\n";
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'compare':
|
||||
$result = Testrunner::compare($files, false);
|
||||
|
||||
if (!$result) {
|
||||
echo "\033[0;31mTestrunner failed, please look at runner.log for the details!\033[0m\n\n";
|
||||
|
||||
if (in_array('show', $options)) {
|
||||
echo file_get_contents('runner.log') . "\n\n";
|
||||
echo "Done!\n\n";
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'rebase':
|
||||
Testrunner::rebase($files, false);
|
||||
break;
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
echo "Updating browser ids...\n";
|
||||
|
||||
$ids = json_decode(file_get_contents("https://api.whichbrowser.net/resources/browser-ids.json"));
|
||||
|
||||
$result = "";
|
||||
$result .= "<?php\n";
|
||||
$result .= "\n";
|
||||
$result .= "/* This file is automatically generated, do not edit manually! */\n";
|
||||
$result .= "\n";
|
||||
$result .= "namespace WhichBrowser\\Data;\n";
|
||||
$result .= "\n";
|
||||
$result .= "BrowserIds::\$ANDROID_BROWSERS = [\n";
|
||||
|
||||
foreach($ids as $key => $id) {
|
||||
$result .= " '" . addslashes(trim($id->browserId)) . "'" . str_repeat(" ", max(0, 100 - strlen($id->browserId)));
|
||||
$result .= "=> " . deviceString($id->browserName) . ",\n";
|
||||
}
|
||||
|
||||
$result .= "];\n";
|
||||
|
||||
file_put_contents(__DIR__ . '/../data/id-android.php', $result);
|
||||
|
||||
|
||||
function deviceString($s) {
|
||||
if (is_null($s) || $s == '') {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
return "'" . addslashes(trim($s)) . "'";
|
||||
}
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . '/bootstrap.php';
|
||||
include __DIR__ . '/../data/browsers-chrome.php';
|
||||
|
||||
echo "Updating chrome versions...\n";
|
||||
|
||||
$stable = [
|
||||
'desktop' => [],
|
||||
'mobile' => []
|
||||
];
|
||||
|
||||
|
||||
$omaha = explode("\n", file_get_contents("http://omahaproxy.appspot.com/history"));
|
||||
foreach ($omaha as $i => $line) {
|
||||
$items = explode(",", $line);
|
||||
|
||||
if ($items[0] == 'mac' && $items[1] == 'stable') {
|
||||
$stable['desktop'][] = implode('.', array_slice(explode('.', $items[2]), 0, 3));
|
||||
}
|
||||
|
||||
if ($items[0] == 'android' && $items[1] == 'stable') {
|
||||
$stable['mobile'][] = implode('.', array_slice(explode('.', $items[2]), 0, 3));
|
||||
}
|
||||
}
|
||||
|
||||
$stable['desktop'] = array_unique($stable['desktop']);
|
||||
$stable['mobile'] = array_unique($stable['mobile']);
|
||||
|
||||
sort($stable['desktop']);
|
||||
sort($stable['mobile']);
|
||||
|
||||
|
||||
foreach ($stable['desktop'] as $i => $version) {
|
||||
if (!isset(WhichBrowser\Data\Chrome::$DESKTOP[$version])) {
|
||||
WhichBrowser\Data\Chrome::$DESKTOP[$version] = 'stable';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($stable['mobile'] as $i => $version) {
|
||||
if (!isset(WhichBrowser\Data\Chrome::$MOBILE[$version])) {
|
||||
WhichBrowser\Data\Chrome::$MOBILE[$version] = 'stable';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result = "";
|
||||
$result .= "<?php\n\n";
|
||||
$result .= "namespace WhichBrowser\Data;\n\n";
|
||||
$result .= "Chrome::\$DESKTOP = [\n";
|
||||
foreach (WhichBrowser\Data\Chrome::$DESKTOP as $version => $channel) $result .= " '{$version}' => '{$channel}',\n";
|
||||
$result .= "];\n\n";
|
||||
$result .= "Chrome::\$MOBILE = [\n";
|
||||
foreach (WhichBrowser\Data\Chrome::$MOBILE as $version => $channel) $result .= " '{$version}' => '{$channel}',\n";
|
||||
$result .= "];\n";
|
||||
|
||||
|
||||
file_put_contents(__DIR__ . '/../data/browsers-chrome.php', $result);
|
||||
Executable
+199
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
use WhichBrowser\Data\DeviceModels;
|
||||
use ReverseRegex\Lexer;
|
||||
|
||||
$command = 'list';
|
||||
$types = [];
|
||||
$options = [];
|
||||
|
||||
array_shift($argv);
|
||||
|
||||
if (count($argv)) {
|
||||
foreach ($argv as $argument) {
|
||||
if (in_array($argument, [ 'list' ])) {
|
||||
$command = $argument;
|
||||
} elseif (substr($argument, 0, 2) == '--') {
|
||||
$options[] = substr($argument, 2);
|
||||
} else {
|
||||
$types[] = $argument;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array('all', $options)) {
|
||||
$types = [
|
||||
'android', 'asha', 'bada', 'brew', 'feature', 'firefoxos',
|
||||
'kddi', 'palmos', 's30plus', 's40', 'symbian', 'tizen',
|
||||
'touchwiz', 'wm', 'wp'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
foreach ($types as $i => $type) {
|
||||
command($command, $type);
|
||||
}
|
||||
|
||||
|
||||
function command($command, $type) {
|
||||
switch($command) {
|
||||
case 'list':
|
||||
command_list($type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function command_list($type) {
|
||||
echo "Creating index for 'data/models-{$type}.php'...\n";
|
||||
|
||||
require_once __DIR__ . '/../data/models-' . $type . '.php';
|
||||
|
||||
$name = strtoupper($type) . '_MODELS';
|
||||
$list = DeviceModels::$$name;
|
||||
|
||||
$index = [];
|
||||
|
||||
foreach ($list as $key => $value) {
|
||||
|
||||
if (substr($key, -2) == '!!') {
|
||||
$keys = getKeysFromRegexp(substr($key, 0, -2));
|
||||
}
|
||||
elseif (substr($key, -1) == '!') {
|
||||
$keys = getKeysFromRegexp(substr($key, 0, -1));
|
||||
}
|
||||
else {
|
||||
$keys = [ substr(strtoupper($key), 0, 2) ];
|
||||
}
|
||||
|
||||
foreach ($keys as $k => $v) {
|
||||
if ($v == '**') {
|
||||
$v = '';
|
||||
}
|
||||
|
||||
if (!isset($index['@'.$v])) {
|
||||
$index['@'.$v] = [];
|
||||
}
|
||||
|
||||
$index['@'.$v][] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
ksort($index);
|
||||
|
||||
$file = "<" . "?php\n";
|
||||
$file .= "\n";
|
||||
$file .= "namespace WhichBrowser\\Data;\n";
|
||||
$file .= "\n";
|
||||
$file .= "DeviceModels::\$" . strtoupper($type) . "_INDEX = " . var_export($index, true) . ";\n";
|
||||
|
||||
file_put_contents(__DIR__ . '/../data/indices/models-' . $type . '.php', $file);
|
||||
}
|
||||
|
||||
function getKeysFromRegexp($regexp) {
|
||||
$lexer = new Lexer($regexp);
|
||||
$lexer->moveNext();
|
||||
|
||||
$keys = readKeysFromLexer($lexer);
|
||||
|
||||
return array_unique($keys);
|
||||
}
|
||||
|
||||
|
||||
function readKeysFromLexer($lexer) {
|
||||
$keys = [];
|
||||
|
||||
if ($lexer->isNextTokenAny([ Lexer::T_LITERAL_CHAR,Lexer::T_LITERAL_NUMERIC ])) {
|
||||
$current = strtoupper($lexer->lookahead['value']);
|
||||
|
||||
$lexer->moveNext();
|
||||
if ($lexer->isNextTokenAny([ Lexer::T_LITERAL_CHAR,Lexer::T_LITERAL_NUMERIC ])) {
|
||||
$keys[] = $current . strtoupper($lexer->lookahead['value']);
|
||||
}
|
||||
else {
|
||||
$keys[] = '**';
|
||||
}
|
||||
}
|
||||
|
||||
else if ($lexer->isNextToken(Lexer::T_GROUP_OPEN)) {
|
||||
$current = '';
|
||||
$active = true;
|
||||
|
||||
while ($lexer->moveNext()) {
|
||||
if ($lexer->isNextTokenAny([ Lexer::T_LITERAL_CHAR,Lexer::T_LITERAL_NUMERIC ])) {
|
||||
if ($active && strlen($current) < 2) {
|
||||
$current .= strtoupper($lexer->lookahead['value']);
|
||||
}
|
||||
}
|
||||
|
||||
else if ($lexer->isNextToken(Lexer::T_CHOICE_BAR)) {
|
||||
$keys[] = $current;
|
||||
$current = '';
|
||||
$active = true;
|
||||
}
|
||||
|
||||
else if ($lexer->isNextToken(Lexer::T_GROUP_OPEN)) {
|
||||
if ($lexer->moveNext()) {
|
||||
$more = readKeysFromLexer($lexer);
|
||||
|
||||
if (count($more)) {
|
||||
$keys = array_merge($keys, $more);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if ($lexer->isNextToken(Lexer::T_GROUP_CLOSE)) {
|
||||
if (strlen($current) == 2) {
|
||||
$keys[] = $current;
|
||||
} else {
|
||||
$keys[] = '**';
|
||||
}
|
||||
|
||||
$current = '';
|
||||
$active = true;
|
||||
break;
|
||||
}
|
||||
|
||||
else if ($lexer->isNextToken(Lexer::T_DOT)) {
|
||||
$keys[] = '**';
|
||||
$current = '';
|
||||
$active = false;
|
||||
break;
|
||||
}
|
||||
|
||||
else {
|
||||
$active = false;
|
||||
}
|
||||
}
|
||||
|
||||
while ($lexer->moveNext()) {
|
||||
if ($lexer->isNextToken(Lexer::T_QUANTIFIER_QUESTION)) {
|
||||
if ($lexer->moveNext()) {
|
||||
$more = readKeysFromLexer($lexer);
|
||||
|
||||
if (count($more)) {
|
||||
$keys = array_merge($keys, $more);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if ($lexer->isNextToken(Lexer::T_SET_OPEN)) {
|
||||
$keys[] = '**';
|
||||
}
|
||||
|
||||
else if ($lexer->isNextToken(Lexer::T_DOT)) {
|
||||
$keys[] = '**';
|
||||
}
|
||||
|
||||
return array_unique($keys);
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
echo "Downloading...";
|
||||
|
||||
$profiles = json_decode(file_get_contents("https://api.whichbrowser.net/resources/profiles.json"));
|
||||
|
||||
$total = count($profiles);
|
||||
|
||||
$result = "";
|
||||
$result .= "<?php\n";
|
||||
$result .= "\n";
|
||||
$result .= "/* This file is automatically generated, do not edit manually! */\n";
|
||||
$result .= "\n";
|
||||
$result .= "namespace WhichBrowser\\Data;\n";
|
||||
$result .= "\n";
|
||||
$result .= "use WhichBrowser\\Constants\\DeviceType;\n";
|
||||
$result .= "\n";
|
||||
$result .= "DeviceProfiles::\$PROFILES = [\n";
|
||||
|
||||
foreach($profiles as $key => $profile) {
|
||||
$result .= " '" . addslashes(trim($profile->url)) . "'" . str_repeat(" ", max(0, 100 - strlen($profile->url)));
|
||||
$result .= "=> [ " . deviceString($profile->deviceManufacturer) . ", " . deviceString($profile->deviceModel);
|
||||
$result .= ", " . deviceString($profile->osName) . ", " . deviceType($profile->deviceType) . " ],\n";
|
||||
}
|
||||
|
||||
$result .= "];\n";
|
||||
|
||||
echo " and writing {$total} profiles...\n";
|
||||
file_put_contents(__DIR__ . '/../data/profiles.php', $result);
|
||||
|
||||
|
||||
function deviceString($s) {
|
||||
if (is_null($s) || $s == '') {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
return "'" . addslashes(trim($s)) . "'";
|
||||
}
|
||||
|
||||
function deviceType($type) {
|
||||
switch ($type) {
|
||||
case 'mobile': return 'DeviceType::MOBILE';
|
||||
case 'tablet': return 'DeviceType::TABLET';
|
||||
}
|
||||
}
|
||||
Executable
+118
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
include_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
use WhichBrowser\Data\Applications;
|
||||
|
||||
$command = 'list';
|
||||
$types = [];
|
||||
$options = [];
|
||||
|
||||
array_shift($argv);
|
||||
|
||||
if (count($argv)) {
|
||||
foreach ($argv as $argument) {
|
||||
if (in_array($argument, [ 'list' ])) {
|
||||
$command = $argument;
|
||||
} elseif (substr($argument, 0, 2) == '--') {
|
||||
$options[] = substr($argument, 2);
|
||||
} else {
|
||||
$types[] = $argument;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array('all', $options)) {
|
||||
$types = [
|
||||
'applications-bots',
|
||||
'applications-browsers',
|
||||
'applications-others'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
foreach ($types as $i => $type) {
|
||||
command($command, $type);
|
||||
}
|
||||
|
||||
|
||||
function command($command, $type) {
|
||||
switch($command) {
|
||||
case 'list':
|
||||
command_list($type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function command_list($type) {
|
||||
echo "Creating regex for 'data/{$type}.php'...\n";
|
||||
|
||||
require_once __DIR__ . '/../data/' . $type . '.php';
|
||||
|
||||
if ($type == 'applications-bots') {
|
||||
$list = Applications::$BOTS;
|
||||
|
||||
$ids = [];
|
||||
|
||||
foreach ($list as $i => $bot) {
|
||||
$ids[] = $bot['id'];
|
||||
}
|
||||
|
||||
$ids = array_unique($ids);
|
||||
$regex = '/(' . implode('|', $ids) . ')/i';
|
||||
|
||||
$file = "<" . "?php\n";
|
||||
$file .= "\n";
|
||||
$file .= "namespace WhichBrowser\\Data;\n";
|
||||
$file .= "\n";
|
||||
$file .= "Applications::\$BOTS_REGEX = '" . $regex . "';\n";
|
||||
|
||||
file_put_contents(__DIR__ . '/../data/regexes/' . $type . '.php', $file);
|
||||
}
|
||||
|
||||
if ($type == 'applications-browsers') {
|
||||
$list = Applications::$BROWSERS;
|
||||
|
||||
$ids = [];
|
||||
|
||||
foreach ($list as $t => $l) {
|
||||
foreach ($l as $i => $item) {
|
||||
$ids[] = $item['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$ids = array_unique($ids);
|
||||
$regex = '/(' . implode('|', $ids) . ')/i';
|
||||
|
||||
$file = "<" . "?php\n";
|
||||
$file .= "\n";
|
||||
$file .= "namespace WhichBrowser\\Data;\n";
|
||||
$file .= "\n";
|
||||
$file .= "Applications::\$BROWSERS_REGEX = '" . $regex . "';\n";
|
||||
|
||||
file_put_contents(__DIR__ . '/../data/regexes/' . $type . '.php', $file);
|
||||
}
|
||||
|
||||
if ($type == 'applications-others') {
|
||||
$list = Applications::$OTHERS;
|
||||
|
||||
$ids = [];
|
||||
|
||||
foreach ($list as $t => $l) {
|
||||
foreach ($l as $i => $item) {
|
||||
$ids[] = $item['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$ids = array_unique($ids);
|
||||
$regex = '/(' . implode('|', $ids) . ')/i';
|
||||
|
||||
$file = "<" . "?php\n";
|
||||
$file .= "\n";
|
||||
$file .= "namespace WhichBrowser\\Data;\n";
|
||||
$file .= "\n";
|
||||
$file .= "Applications::\$OTHERS_REGEX = '" . $regex . "';\n";
|
||||
|
||||
file_put_contents(__DIR__ . '/../data/regexes/' . $type . '.php', $file);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user