Applications.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace WhichBrowser\Data;
  3. use WhichBrowser\Model\Browser;
  4. use WhichBrowser\Model\Version;
  5. class Applications
  6. {
  7. public static $BOTS = [];
  8. public static $BOTS_REGEX = '';
  9. public static $BROWSERS = [];
  10. public static $BROWSERS_REGEX = '';
  11. public static $OTHERS = [];
  12. public static $OTHERS_REGEX = '';
  13. public static function identifyBrowser($ua)
  14. {
  15. require_once __DIR__ . '/../../data/regexes/applications-browsers.php';
  16. if (preg_match(self::$BROWSERS_REGEX, $ua)) {
  17. require_once __DIR__ . '/../../data/applications-browsers.php';
  18. foreach (self::$BROWSERS as $type => $list) {
  19. foreach ($list as $i => $item) {
  20. if (preg_match($item['regexp'], $ua, $match)) {
  21. return [
  22. 'browser' => [
  23. 'name' => $item['name'],
  24. 'hidden' => isset($item['hidden']) ? $item['hidden'] : false,
  25. 'stock' => false,
  26. 'channel' => '',
  27. 'type' => $type,
  28. 'version' => isset($match[1]) && $match[1] ? new Version([ 'value' => $match[1], 'details' => isset($item['details']) ? $item['details'] : null ]) : null
  29. ],
  30. 'device' => isset($item['type']) ? [
  31. 'type' => $item['type']
  32. ] : null
  33. ];
  34. }
  35. }
  36. }
  37. }
  38. }
  39. public static function identifyOther($ua)
  40. {
  41. require_once __DIR__ . '/../../data/regexes/applications-others.php';
  42. if (preg_match(self::$OTHERS_REGEX, $ua)) {
  43. require_once __DIR__ . '/../../data/applications-others.php';
  44. foreach (self::$OTHERS as $type => $list) {
  45. foreach ($list as $i => $item) {
  46. if (preg_match($item['regexp'], $ua, $match)) {
  47. return [
  48. 'browser' => [
  49. 'name' => $item['name'],
  50. 'hidden' => isset($item['hidden']) ? $item['hidden'] : false,
  51. 'stock' => false,
  52. 'channel' => '',
  53. 'type' => $type,
  54. 'version' => isset($match[1]) && $match[1] ? new Version([ 'value' => $match[1], 'details' => isset($item['details']) ? $item['details'] : null ]) : null
  55. ],
  56. 'device' => isset($item['type']) ? [
  57. 'type' => $item['type']
  58. ] : null
  59. ];
  60. }
  61. }
  62. }
  63. }
  64. }
  65. public static function identifyBot($ua)
  66. {
  67. require_once __DIR__ . '/../../data/regexes/applications-bots.php';
  68. if (preg_match(self::$BOTS_REGEX, $ua)) {
  69. require_once __DIR__ . '/../../data/applications-bots.php';
  70. foreach (self::$BOTS as $i => $item) {
  71. if (preg_match($item['regexp'], $ua, $match)) {
  72. return new Browser([
  73. 'name' => $item['name'],
  74. 'stock' => false,
  75. 'version' => isset($match[1]) && $match[1] ? new Version([ 'value' => $match[1], 'details' => isset($item['details']) ? $item['details'] : null ]) : null
  76. ]);
  77. }
  78. }
  79. }
  80. }
  81. }