✨ Hello world!
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";
|
||||
|
77
vendor/donatj/phpuseragentparser/bin/constant_generator.php
vendored
Normal file
77
vendor/donatj/phpuseragentparser/bin/constant_generator.php
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$jsonfile = __DIR__ . '/../tests/user_agents.json';
|
||||
|
||||
$uas = json_decode(
|
||||
file_get_contents($jsonfile),
|
||||
true
|
||||
);
|
||||
|
||||
$platforms = array();
|
||||
$browsers = array();
|
||||
foreach( $uas as $key => $val ) {
|
||||
$kex = strtoupper($val['browser']);
|
||||
if( $kex !== '' ) {
|
||||
$kex = preg_replace('/\W+/', '_', $kex);
|
||||
if( !isset($browsers[$kex][$val['browser']]) ) {
|
||||
$browsers[$kex][$val['browser']] = 0;
|
||||
}
|
||||
|
||||
$browsers[$kex][$val['browser']]++;
|
||||
}
|
||||
|
||||
$kex = strtoupper($val['platform']);
|
||||
if( $kex !== '' ) {
|
||||
$kex = preg_replace('/\W+/', '_', $kex);
|
||||
|
||||
if( !isset($platforms[$kex][$val['platform']]) ) {
|
||||
$platforms[$kex][$val['platform']] = 0;
|
||||
}
|
||||
|
||||
$platforms[$kex][$val['platform']]++;
|
||||
}
|
||||
}
|
||||
|
||||
ksort($browsers);
|
||||
$file = basename(__FILE__);
|
||||
$header = <<<EOT
|
||||
<?php
|
||||
|
||||
// DO NOT EDIT THIS FILE - IT IS GENERATED BY {$file}
|
||||
|
||||
|
||||
EOT;
|
||||
|
||||
|
||||
foreach( $browsers as $browser ) {
|
||||
if( count($browser) !== 1 ) {
|
||||
echo "bad browser count\n";
|
||||
die(2);
|
||||
}
|
||||
}
|
||||
|
||||
$browserBody = "{$header}namespace donatj\UserAgent;\n\ninterface Browsers {\n\n";
|
||||
$maxKey = max(array_map('strlen', array_keys($browsers)));
|
||||
foreach( $browsers as $const => $val ) {
|
||||
$browserBody .= sprintf("\tconst %-{$maxKey}s = %s;\n", $const, var_export(key($val), true));
|
||||
}
|
||||
$browserBody .= "\n}\n\n";
|
||||
|
||||
foreach( $platforms as $platform ) {
|
||||
if( count($platform) !== 1 ) {
|
||||
echo "bad platform count\n";
|
||||
die(2);
|
||||
}
|
||||
}
|
||||
|
||||
$platformBody = "{$header}namespace donatj\UserAgent;\n\ninterface Platforms {\n\n";
|
||||
$maxKey = max(array_map('strlen', array_keys($platforms)));
|
||||
foreach( $platforms as $const => $val ) {
|
||||
$platformBody .= sprintf("\tconst %-{$maxKey}s = %s;\n", $const, var_export(key($val), true));
|
||||
}
|
||||
$platformBody .= "\n}\n\n";
|
||||
|
||||
file_put_contents(__DIR__ . '/../src/UserAgent/Browsers.php', $browserBody);
|
||||
file_put_contents(__DIR__ . '/../src/UserAgent/Platforms.php', $platformBody);
|
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);
|
100
vendor/donatj/phpuseragentparser/bin/user_agent_sorter.php
vendored
Normal file
100
vendor/donatj/phpuseragentparser/bin/user_agent_sorter.php
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
<?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;
|
||||
}
|
||||
unset($val);
|
||||
|
||||
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, true);
|
||||
$bd = in_array($b['platform'], $desktop, true);
|
||||
|
||||
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']);
|
||||
}
|
||||
unset($val);
|
||||
|
||||
$jsonPretty = new Camspiers\JsonPretty\JsonPretty;
|
||||
|
||||
$json = $jsonPretty->prettify($uas) . "\n";
|
||||
echo $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) && $aa !== $bb ) {
|
||||
$value = ($aa > $bb ? 1 : -1);
|
||||
break;
|
||||
}
|
||||
|
||||
if( $cmp = strcmp($aa, $bb) ) {
|
||||
$value = $cmp / abs($cmp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
Reference in New Issue
Block a user