first commit
This commit is contained in:
24
vendor/donatj/phpuseragentparser/bin/benchmark.php
vendored
Normal file
24
vendor/donatj/phpuseragentparser/bin/benchmark.php
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../src/UserAgentParser.php';
|
||||
|
||||
$time = microtime(true);
|
||||
|
||||
$uas = json_decode(file_get_contents(__DIR__ . '/../tests/user_agents.json'), true);
|
||||
|
||||
|
||||
foreach( $uas as $ua => $junk ) {
|
||||
$uatime = microtime(true);
|
||||
for( $i = 0; $i <= 1000; $i++ ) {
|
||||
\parse_user_agent($ua);
|
||||
}
|
||||
|
||||
|
||||
echo microtime(true) - $uatime;
|
||||
echo " : $ua\n";
|
||||
}
|
||||
|
||||
|
||||
echo microtime(true) - $time;
|
||||
echo " : TOTAL\n";
|
||||
|
13
vendor/donatj/phpuseragentparser/bin/init_user_agent.php
vendored
Normal file
13
vendor/donatj/phpuseragentparser/bin/init_user_agent.php
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
require(__DIR__ . '/../vendor/autoload.php');
|
||||
|
||||
$jsonfile = __DIR__ . '/../Tests/user_agents.json';
|
||||
|
||||
$uas = json_decode(file_get_contents($jsonfile), true);
|
||||
|
||||
foreach( $uas as $key => &$val ) {
|
||||
$val = parse_user_agent($key);
|
||||
}
|
||||
|
||||
echo json_encode($uas);
|
91
vendor/donatj/phpuseragentparser/bin/user_agent_sorter.php
vendored
Normal file
91
vendor/donatj/phpuseragentparser/bin/user_agent_sorter.php
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
require(__DIR__ . '/../vendor/autoload.php');
|
||||
|
||||
$jsonfile = __DIR__ . '/../Tests/user_agents.json';
|
||||
|
||||
$uas = json_decode(file_get_contents($jsonfile), true);
|
||||
|
||||
foreach( $uas as $key => &$val ) {
|
||||
$val['key'] = $key;
|
||||
}
|
||||
|
||||
uasort($uas, function ( $a, $b ) {
|
||||
|
||||
if($a['platform'] === null && $b['platform'] !== null) return 1;
|
||||
if($b['platform'] === null && $a['platform'] !== null) return -1;
|
||||
|
||||
$desktop = array( 'Windows', 'Linux', 'Macintosh', 'Chrome OS' );
|
||||
|
||||
$ad = in_array($a['platform'], $desktop);
|
||||
$bd = in_array($b['platform'], $desktop);
|
||||
|
||||
if( !$ad && $bd ) return 1;
|
||||
if( $ad && !$bd ) return -1;
|
||||
|
||||
if( $ad ) {
|
||||
$result = strnatcasecmp($a['browser'], $b['browser']);
|
||||
if( $result == 0 ) {
|
||||
|
||||
$result = strnatcasecmp($a['platform'], $b['platform']);
|
||||
|
||||
if( $result == 0 ) {
|
||||
$result = compare_version($a['version'], $b['version']);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
$result = strnatcasecmp($a['platform'], $b['platform']);
|
||||
if( $result == 0 ) {
|
||||
|
||||
$result = strnatcasecmp($a['browser'], $b['browser']);
|
||||
|
||||
if( $result == 0 ) {
|
||||
$result = compare_version($a['version'], $b['version']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if( $result == 0 ) {
|
||||
$result = strnatcasecmp($a['key'], $b['key']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
});
|
||||
|
||||
foreach( $uas as &$val ) {
|
||||
unset($val['key']);
|
||||
}
|
||||
|
||||
$jsonPretty = new Camspiers\JsonPretty\JsonPretty;
|
||||
$json = $jsonPretty->prettify($uas) . "\n";
|
||||
echo $json;
|
||||
file_put_contents($jsonfile, $json);
|
||||
|
||||
|
||||
function compare_version( $a, $b ) {
|
||||
$cmp_a = explode('.', $a);
|
||||
$cmp_b = explode('.', $b);
|
||||
|
||||
$max = max(count($cmp_a), count($cmp_b));
|
||||
|
||||
$value = 0;
|
||||
|
||||
for( $i = 0; $i < $max; $i++ ) {
|
||||
$aa = strtolower(isset($cmp_a[$i]) ? $cmp_a[$i] : '0');
|
||||
$bb = strtolower(isset($cmp_b[$i]) ? $cmp_b[$i] : '0');
|
||||
|
||||
if( is_numeric($aa) && is_numeric($bb) ) {
|
||||
if( $aa != $bb ) {
|
||||
$value = ($aa > $bb ? 1 : -1);
|
||||
break;
|
||||
}
|
||||
} else if( $cmp = strcmp($aa, $bb) ) {
|
||||
$value = $cmp / abs($cmp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
Reference in New Issue
Block a user