initial commit; version 22.5.12042
This commit is contained in:
57
libs/UserAgent/Browsers.php
Normal file
57
libs/UserAgent/Browsers.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
// DO NOT EDIT THIS FILE - IT IS GENERATED BY constant_generator.php
|
||||
|
||||
namespace donatj\UserAgent;
|
||||
|
||||
interface Browsers {
|
||||
|
||||
const ADSBOT_GOOGLE = 'AdsBot-Google';
|
||||
const ANDROID_BROWSER = 'Android Browser';
|
||||
const APPLEBOT = 'Applebot';
|
||||
const BAIDUSPIDER = 'Baiduspider';
|
||||
const BINGBOT = 'bingbot';
|
||||
const BLACKBERRY_BROWSER = 'BlackBerry Browser';
|
||||
const BROWSER = 'Browser';
|
||||
const BUNJALLOO = 'Bunjalloo';
|
||||
const CAMINO = 'Camino';
|
||||
const CHROME = 'Chrome';
|
||||
const CURL = 'curl';
|
||||
const EDGE = 'Edge';
|
||||
const FACEBOOKEXTERNALHIT = 'facebookexternalhit';
|
||||
const FEEDVALIDATOR = 'FeedValidator';
|
||||
const FIREFOX = 'Firefox';
|
||||
const GOOGLEBOT = 'Googlebot';
|
||||
const GOOGLEBOT_IMAGE = 'Googlebot-Image';
|
||||
const GOOGLEBOT_VIDEO = 'Googlebot-Video';
|
||||
const HEADLESSCHROME = 'HeadlessChrome';
|
||||
const IEMOBILE = 'IEMobile';
|
||||
const IMESSAGEBOT = 'iMessageBot';
|
||||
const KINDLE = 'Kindle';
|
||||
const LYNX = 'Lynx';
|
||||
const MIDORI = 'Midori';
|
||||
const MIUIBROWSER = 'MiuiBrowser';
|
||||
const MSIE = 'MSIE';
|
||||
const MSNBOT_MEDIA = 'msnbot-media';
|
||||
const NETFRONT = 'NetFront';
|
||||
const NINTENDOBROWSER = 'NintendoBrowser';
|
||||
const OCULUSBROWSER = 'OculusBrowser';
|
||||
const OPERA = 'Opera';
|
||||
const PUFFIN = 'Puffin';
|
||||
const SAFARI = 'Safari';
|
||||
const SAILFISHBROWSER = 'SailfishBrowser';
|
||||
const SAMSUNGBROWSER = 'SamsungBrowser';
|
||||
const SILK = 'Silk';
|
||||
const TELEGRAMBOT = 'TelegramBot';
|
||||
const TIZENBROWSER = 'TizenBrowser';
|
||||
const TWITTERBOT = 'Twitterbot';
|
||||
const UC_BROWSER = 'UC Browser';
|
||||
const VALVE_STEAM_TENFOOT = 'Valve Steam Tenfoot';
|
||||
const VIVALDI = 'Vivaldi';
|
||||
const WGET = 'Wget';
|
||||
const WORDPRESS = 'WordPress';
|
||||
const YANDEX = 'Yandex';
|
||||
const YANDEXBOT = 'YandexBot';
|
||||
|
||||
}
|
||||
|
42
libs/UserAgent/Platforms.php
Normal file
42
libs/UserAgent/Platforms.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
// DO NOT EDIT THIS FILE - IT IS GENERATED BY constant_generator.php
|
||||
|
||||
namespace donatj\UserAgent;
|
||||
|
||||
interface Platforms {
|
||||
|
||||
const MACINTOSH = 'Macintosh';
|
||||
const CHROME_OS = 'Chrome OS';
|
||||
const LINUX = 'Linux';
|
||||
const WINDOWS = 'Windows';
|
||||
const ANDROID = 'Android';
|
||||
const BLACKBERRY = 'BlackBerry';
|
||||
const FREEBSD = 'FreeBSD';
|
||||
const IPAD = 'iPad';
|
||||
const IPHONE = 'iPhone';
|
||||
const IPOD = 'iPod';
|
||||
const KINDLE = 'Kindle';
|
||||
const KINDLE_FIRE = 'Kindle Fire';
|
||||
const NETBSD = 'NetBSD';
|
||||
const NEW_NINTENDO_3DS = 'New Nintendo 3DS';
|
||||
const NINTENDO_3DS = 'Nintendo 3DS';
|
||||
const NINTENDO_DS = 'Nintendo DS';
|
||||
const NINTENDO_SWITCH = 'Nintendo Switch';
|
||||
const NINTENDO_WII = 'Nintendo Wii';
|
||||
const NINTENDO_WIIU = 'Nintendo WiiU';
|
||||
const OPENBSD = 'OpenBSD';
|
||||
const PLAYBOOK = 'PlayBook';
|
||||
const PLAYSTATION_3 = 'PlayStation 3';
|
||||
const PLAYSTATION_4 = 'PlayStation 4';
|
||||
const PLAYSTATION_5 = 'PlayStation 5';
|
||||
const PLAYSTATION_VITA = 'PlayStation Vita';
|
||||
const SAILFISH = 'Sailfish';
|
||||
const SYMBIAN = 'Symbian';
|
||||
const TIZEN = 'Tizen';
|
||||
const WINDOWS_PHONE = 'Windows Phone';
|
||||
const XBOX = 'Xbox';
|
||||
const XBOX_ONE = 'Xbox One';
|
||||
|
||||
}
|
||||
|
57
libs/UserAgent/UserAgent.php
Normal file
57
libs/UserAgent/UserAgent.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace donatj\UserAgent;
|
||||
|
||||
class UserAgent implements UserAgentInterface {
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $platform;
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $browser;
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $browserVersion;
|
||||
|
||||
/**
|
||||
* UserAgent constructor.
|
||||
*
|
||||
* @param string|null $platform
|
||||
* @param string|null $browser
|
||||
* @param string|null $browserVersion
|
||||
*/
|
||||
public function __construct( $platform, $browser, $browserVersion ) {
|
||||
$this->platform = $platform;
|
||||
$this->browser = $browser;
|
||||
$this->browserVersion = $browserVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
* @see \donatj\UserAgent\Platforms for a list of tested platforms
|
||||
*/
|
||||
public function platform() {
|
||||
return $this->platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
* @see \donatj\UserAgent\Browsers for a list of tested browsers.
|
||||
*/
|
||||
public function browser() {
|
||||
return $this->browser;
|
||||
}
|
||||
|
||||
/**
|
||||
* The version string. Formatting depends on the browser.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function browserVersion() {
|
||||
return $this->browserVersion;
|
||||
}
|
||||
}
|
25
libs/UserAgent/UserAgentInterface.php
Normal file
25
libs/UserAgent/UserAgentInterface.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace donatj\UserAgent;
|
||||
|
||||
interface UserAgentInterface {
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
* @see \donatj\UserAgent\Platforms for a list of tested platforms
|
||||
*/
|
||||
public function platform();
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
* @see \donatj\UserAgent\Browsers for a list of tested browsers.
|
||||
*/
|
||||
public function browser();
|
||||
|
||||
/**
|
||||
* The version string. Formatting depends on the browser.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function browserVersion();
|
||||
}
|
39
libs/UserAgent/UserAgentParser.php
Normal file
39
libs/UserAgent/UserAgentParser.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace donatj\UserAgent;
|
||||
|
||||
class UserAgentParser {
|
||||
|
||||
/**
|
||||
* Parses a user agent string into its important parts, provide an object
|
||||
*
|
||||
* @param string|null $u_agent User agent string to parse or null. Uses $_SERVER['HTTP_USER_AGENT'] on NULL
|
||||
* @return UserAgent an object with 'browser', 'browserVersion' and 'platform' methods
|
||||
* @throws \InvalidArgumentException on not having a proper user agent to parse.
|
||||
* @see \donatj\UserAgent\parse_user_agent()
|
||||
*
|
||||
*/
|
||||
public function parse( $u_agent = null ) {
|
||||
$parsed = parse_user_agent($u_agent);
|
||||
|
||||
return new UserAgent(
|
||||
$parsed[PLATFORM],
|
||||
$parsed[BROWSER],
|
||||
$parsed[BROWSER_VERSION]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a user agent string into its important parts
|
||||
*
|
||||
* @param string|null $u_agent User agent string to parse or null. Uses $_SERVER['HTTP_USER_AGENT'] on NULL
|
||||
* @return UserAgent an object with 'browser', 'browserVersion' and 'platform' methods
|
||||
* @throws \InvalidArgumentException on not having a proper user agent to parse.
|
||||
* @see \donatj\UserAgent\parse_user_agent()
|
||||
*
|
||||
*/
|
||||
public function __invoke( $u_agent = null ) {
|
||||
return $this->parse($u_agent);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user