Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like BrowserDetection often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use BrowserDetection, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 76 | class BrowserDetection |
||
| 77 | { |
||
| 78 | const BROWSER_AMAYA = 'Amaya'; |
||
| 79 | const BROWSER_ANDROID = 'Android'; |
||
| 80 | const BROWSER_BINGBOT = 'Bingbot'; |
||
| 81 | const BROWSER_BLACKBERRY = 'BlackBerry'; |
||
| 82 | const BROWSER_CHROME = 'Chrome'; |
||
| 83 | const BROWSER_FIREBIRD = 'Firebird'; |
||
| 84 | const BROWSER_FIREFOX = 'Firefox'; |
||
| 85 | const BROWSER_GALEON = 'Galeon'; |
||
| 86 | const BROWSER_GOOGLEBOT = 'Googlebot'; |
||
| 87 | const BROWSER_ICAB = 'iCab'; |
||
| 88 | const BROWSER_ICECAT = 'GNU IceCat'; |
||
| 89 | const BROWSER_ICEWEASEL = 'GNU IceWeasel'; |
||
| 90 | const BROWSER_IE = 'Internet Explorer'; |
||
| 91 | const BROWSER_IE_MOBILE = 'Internet Explorer Mobile'; |
||
| 92 | const BROWSER_KONQUEROR = 'Konqueror'; |
||
| 93 | const BROWSER_LYNX = 'Lynx'; |
||
| 94 | const BROWSER_MOZILLA = 'Mozilla'; |
||
| 95 | const BROWSER_MSNBOT = 'MSNBot'; |
||
| 96 | const BROWSER_MSNTV = 'MSN TV'; |
||
| 97 | const BROWSER_NETPOSITIVE = 'NetPositive'; |
||
| 98 | const BROWSER_NETSCAPE = 'Netscape'; |
||
| 99 | const BROWSER_NOKIA = 'Nokia Browser'; |
||
| 100 | const BROWSER_OMNIWEB = 'OmniWeb'; |
||
| 101 | const BROWSER_OPERA = 'Opera'; |
||
| 102 | const BROWSER_OPERA_MINI = 'Opera Mini'; |
||
| 103 | const BROWSER_OPERA_MOBILE = 'Opera Mobile'; |
||
| 104 | const BROWSER_PHOENIX = 'Phoenix'; |
||
| 105 | const BROWSER_SAFARI = 'Safari'; |
||
| 106 | const BROWSER_SLURP = 'Yahoo! Slurp'; |
||
| 107 | const BROWSER_TABLET_OS = 'BlackBerry Tablet OS'; |
||
| 108 | const BROWSER_UNKNOWN = 'unknown'; |
||
| 109 | const BROWSER_W3CVALIDATOR = 'W3C Validator'; |
||
| 110 | const BROWSER_YAHOO_MM = 'Yahoo! Multimedia'; |
||
| 111 | const PLATFORM_ANDROID = 'Android'; |
||
| 112 | const PLATFORM_BEOS = 'BeOS'; |
||
| 113 | const PLATFORM_BLACKBERRY = 'BlackBerry'; |
||
| 114 | const PLATFORM_FREEBSD = 'FreeBSD'; |
||
| 115 | const PLATFORM_IPAD = 'iPad'; |
||
| 116 | const PLATFORM_IPHONE = 'iPhone'; |
||
| 117 | const PLATFORM_IPOD = 'iPod'; |
||
| 118 | const PLATFORM_LINUX = 'Linux'; |
||
| 119 | const PLATFORM_MACINTOSH = 'Macintosh'; |
||
| 120 | const PLATFORM_NETBSD = 'NetBSD'; |
||
| 121 | const PLATFORM_NOKIA = 'Nokia'; |
||
| 122 | const PLATFORM_OPENBSD = 'OpenBSD'; |
||
| 123 | const PLATFORM_OPENSOLARIS = 'OpenSolaris'; |
||
| 124 | const PLATFORM_OS2 = 'OS/2'; |
||
| 125 | const PLATFORM_SUNOS = 'SunOS'; |
||
| 126 | const PLATFORM_SYMBIAN = 'Symbian'; |
||
| 127 | const PLATFORM_UNKNOWN = 'unknown'; |
||
| 128 | const PLATFORM_WINDOWS = 'Windows'; |
||
| 129 | const PLATFORM_WINDOWS_CE = 'Windows CE'; |
||
| 130 | const PLATFORM_WINDOWS_PHONE = 'Windows Phone'; |
||
| 131 | const VERSION_UNKNOWN = 'unknown'; |
||
| 132 | private $_agent = ''; |
||
| 133 | private $_aolVersion = ''; |
||
| 134 | private $_browserName = ''; |
||
| 135 | private $_compatibilityViewName = ''; |
||
| 136 | private $_compatibilityViewVer = ''; |
||
| 137 | private $_isAol = false; |
||
| 138 | private $_isMobile = false; |
||
| 139 | private $_isRobot = false; |
||
| 140 | private $_platform = ''; |
||
| 141 | private $_version = ''; |
||
| 142 | //--- MAGIC METHODS ------------------------------------------------------------------------------------------------ |
||
| 143 | /** |
||
| 144 | * BrowserDetection class constructor. |
||
| 145 | * @param string $useragent The user agent to work with. Leave empty for the current user agent (contained in |
||
| 146 | * $_SERVER['HTTP_USER_AGENT']). |
||
| 147 | */ |
||
| 148 | public function __construct($useragent = '') |
||
| 152 | /** |
||
| 153 | * Determine how the class will react when it is treated like a string. |
||
| 154 | * @return string Returns an HTML formatted string with a summary of the browser informations. |
||
| 155 | */ |
||
| 156 | public function __toString() |
||
| 179 | //--- PUBLIC MEMBERS ----------------------------------------------------------------------------------------------- |
||
| 180 | /** |
||
| 181 | * Compare two version number strings. |
||
| 182 | * @param string $sourceVer The source version number. |
||
| 183 | * @param string $compareVer The version number to compare with the source version number. |
||
| 184 | * @return int Returns 1 if $sourceVer < $compareVer, 0 if $sourceVer == $compareVer or -1 if $sourceVer > $compareVer. |
||
| 185 | */ |
||
| 186 | public function compareVersions($sourceVer, $compareVer) |
||
| 218 | /** |
||
| 219 | * Get the version of AOL (if any). AOL releases "optimized" Internet Explorer and Firefox versions. In the making |
||
| 220 | * they add their version number in the user agent string of these browsers. |
||
| 221 | * @return string Returns the version of AOL or an empty string if no AOL version was found. |
||
| 222 | */ |
||
| 223 | public function getAolVersion() |
||
| 227 | /** |
||
| 228 | * Get the name of the browser. All of the return values are class constants. You can compare them like this: |
||
| 229 | * $myBrowserInstance->getBrowser() == BrowserDetection::BROWSER_FIREFOX. |
||
| 230 | * @return string Returns the name of the browser. |
||
| 231 | */ |
||
| 232 | public function getBrowser() |
||
| 236 | /** |
||
| 237 | * Get the name and version of the browser emulated in the compatibility view mode (if any). Since Internet |
||
| 238 | * Explorer 8, IE can be put in compatibility mode to make websites that were created for older browsers, especially |
||
| 239 | * IE 6 and 7, look better in IE 8+ which renders web pages closer to the standards and thus differently from those |
||
| 240 | * older versions of IE. |
||
| 241 | * @param bool $asArray Determines if the return value must be an array (true) or a string (false). |
||
| 242 | * @return mixed If a string was requested, the function returns the name and version of the browser emulated in the |
||
| 243 | * compatibility view mode or an empty string if the browser is not in compatibility view mode. If an array was |
||
| 244 | * requested, an array with the keys 'browser' and 'version' is returned. |
||
| 245 | */ |
||
| 246 | public function getIECompatibilityView($asArray = false) |
||
| 254 | /** |
||
| 255 | * Get the name of the platform on which the browser is run on (such as Windows, Apple, iPhone, etc.). All of the |
||
| 256 | * return values are class constants. You can compare them like this: |
||
| 257 | * $myBrowserInstance->getPlatform() == BrowserDetection::PLATFORM_ANDROID. |
||
| 258 | * @return string Returns the name of the platform or BrowserDetection::PLATFORM_UNKNOWN if unknown. |
||
| 259 | */ |
||
| 260 | public function getPlatform() |
||
| 264 | /** |
||
| 265 | * Get the user agent value used by the class to determine the browser details. |
||
| 266 | * @return string The user agent string. |
||
| 267 | */ |
||
| 268 | public function getUserAgent() |
||
| 272 | /** |
||
| 273 | * Get the version of the browser. |
||
| 274 | * @return string Returns the version of the browser or BrowserDetection::VERSION_UNKNOWN if unknown. |
||
| 275 | */ |
||
| 276 | public function getVersion() |
||
| 280 | /** |
||
| 281 | * Determine if the browser is from AOL. AOL releases "optimized" Internet Explorer and Firefox versions. In the |
||
| 282 | * making they add their details in the user agent string of these browsers. |
||
| 283 | * @return boolean Returns true if the browser is from AOL, false otherwise. |
||
| 284 | */ |
||
| 285 | public function isAol() |
||
| 289 | /** |
||
| 290 | * Determine if the browser runs Google Chrome Frame (it's a plug-in designed for Internet Explorer 6+ based on the |
||
| 291 | * open-source Chromium project - it's like a Chrome browser within IE). |
||
| 292 | * @return boolean Returns true if the browser is using Google Chrome Frame, false otherwise. |
||
| 293 | */ |
||
| 294 | public function isChromeFrame() |
||
| 298 | /** |
||
| 299 | * Determine if the browser is in compatibility view or not. Since Internet Explorer 8, IE can be put in |
||
| 300 | * compatibility mode to make websites that were created for older browsers, especially IE 6 and 7, look better in |
||
| 301 | * IE 8+ which renders web pages closer to the standards and thus differently from those older versions of IE. |
||
| 302 | * @return boolean Returns true if the browser is in compatibility view, false otherwise. |
||
| 303 | */ |
||
| 304 | public function isInIECompatibilityView() |
||
| 308 | /** |
||
| 309 | * Determine if the browser is from a mobile device or not. |
||
| 310 | * @return boolean Returns true if the browser is from a mobile device, false otherwise. |
||
| 311 | */ |
||
| 312 | public function isMobile() |
||
| 316 | /** |
||
| 317 | * Determine if the browser is a robot (Googlebot, Bingbot, Yahoo! Slurp...) or not. |
||
| 318 | * @return boolean Returns true if the browser is a robot, false otherwise. |
||
| 319 | */ |
||
| 320 | public function isRobot() |
||
| 324 | /** |
||
| 325 | * Set the user agent to use with the class. |
||
| 326 | * @param string $agentString The value of the user agent. If an empty string is sent (default), |
||
| 327 | * $_SERVER['HTTP_USER_AGENT'] will be used. |
||
| 328 | */ |
||
| 329 | public function setUserAgent($agentString = '') |
||
| 342 | //--- PROTECTED MEMBERS -------------------------------------------------------------------------------------------- |
||
| 343 | /** |
||
| 344 | * Determine if the browser is the Amaya Web editor or not. |
||
| 345 | * @access protected |
||
| 346 | * @link http://www.w3.org/Amaya/ |
||
| 347 | * @return boolean Returns true if the browser is Amaya, false otherwise. |
||
| 348 | */ |
||
| 349 | protected function checkBrowserAmaya() |
||
| 353 | /** |
||
| 354 | * Determine if the browser is the Android browser (based on the WebKit layout engine and coupled with Chrome's |
||
| 355 | * JavaScript engine) or not. |
||
| 356 | * @access protected |
||
| 357 | * @return boolean Returns true if the browser is the Android browser, false otherwise. |
||
| 358 | */ |
||
| 359 | protected function checkBrowserAndroid() |
||
| 364 | /** |
||
| 365 | * Determine if the browser is the Bingbot crawler or not. |
||
| 366 | * @access protected |
||
| 367 | * @link http://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0 |
||
| 368 | * @return boolean Returns true if the browser is Bingbot, false otherwise. |
||
| 369 | */ |
||
| 370 | protected function checkBrowserBingbot() |
||
| 374 | /** |
||
| 375 | * Determine if the browser is the BlackBerry browser or not. |
||
| 376 | * @access protected |
||
| 377 | * @link http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/How-to-detect-the-BlackBerry-Browser/ta-p/559862 |
||
| 378 | * @return boolean Returns true if the browser is the BlackBerry browser, false otherwise. |
||
| 379 | */ |
||
| 380 | protected function checkBrowserBlackBerry() |
||
| 405 | /** |
||
| 406 | * Determine if the browser is Chrome or not. |
||
| 407 | * @access protected |
||
| 408 | * @link http://www.google.com/chrome/ |
||
| 409 | * @return boolean Returns true if the browser is Chrome, false otherwise. |
||
| 410 | */ |
||
| 411 | protected function checkBrowserChrome() |
||
| 415 | /** |
||
| 416 | * Determine if the browser is Firebird or not. Firebird was the name of Firefox from version 0.6 to 0.7.1. |
||
| 417 | * @access protected |
||
| 418 | * @return boolean Returns true if the browser is Firebird, false otherwise. |
||
| 419 | */ |
||
| 420 | protected function checkBrowserFirebird() |
||
| 424 | /** |
||
| 425 | * Determine if the browser is Firefox or not. |
||
| 426 | * @access protected |
||
| 427 | * @link http://www.mozilla.org/en-US/firefox/new/ |
||
| 428 | * @return boolean Returns true if the browser is Firefox, false otherwise. |
||
| 429 | */ |
||
| 430 | protected function checkBrowserFirefox() |
||
| 443 | /** |
||
| 444 | * Determine if the browser is Galeon or not. The browser was discontinued on September 27, 2008. |
||
| 445 | * @access protected |
||
| 446 | * @link http://en.wikipedia.org/wiki/Galeon |
||
| 447 | * @return boolean Returns true if the browser is Galeon, false otherwise. |
||
| 448 | */ |
||
| 449 | protected function checkBrowserGaleon() |
||
| 453 | /** |
||
| 454 | * Determine if the browser is the Googlebot crawler or not. |
||
| 455 | * @access protected |
||
| 456 | * @return boolean Returns true if the browser is Googlebot, false otherwise. |
||
| 457 | */ |
||
| 458 | protected function checkBrowserGooglebot() |
||
| 462 | /** |
||
| 463 | * Determine if the browser is iCab or not. |
||
| 464 | * @access protected |
||
| 465 | * @link http://www.icab.de/ |
||
| 466 | * @return boolean Returns true if the browser is iCab, false otherwise. |
||
| 467 | */ |
||
| 468 | protected function checkBrowserIcab() |
||
| 473 | /** |
||
| 474 | * Determine if the browser is GNU IceCat (formerly known as GNU IceWeasel) or not. |
||
| 475 | * @access protected |
||
| 476 | * @link http://www.gnu.org/software/gnuzilla/ |
||
| 477 | * @return boolean Returns true if the browser is GNU IceCat, false otherwise. |
||
| 478 | */ |
||
| 479 | protected function checkBrowserIceCat() |
||
| 483 | /** |
||
| 484 | * Determine if the browser is GNU IceWeasel (now know as GNU IceCat) or not. |
||
| 485 | * @access protected |
||
| 486 | * @see checkBrowserIceCat() |
||
| 487 | * @return boolean Returns true if the browser is GNU IceWeasel, false otherwise. |
||
| 488 | */ |
||
| 489 | protected function checkBrowserIceWeasel() |
||
| 493 | /** |
||
| 494 | * Determine if the browser is Internet Explorer or not. |
||
| 495 | * @access protected |
||
| 496 | * @link http://www.microsoft.com/ie/ |
||
| 497 | * @link http://en.wikipedia.org/wiki/Internet_Explorer_Mobile |
||
| 498 | * @return boolean Returns true if the browser is Internet Explorer, false otherwise. |
||
| 499 | */ |
||
| 500 | protected function checkBrowserInternetExplorer() |
||
| 577 | /** |
||
| 578 | * Determine if the browser is Konqueror or not. |
||
| 579 | * @access protected |
||
| 580 | * @link http://www.konqueror.org/ |
||
| 581 | * @return boolean Returns true if the browser is Konqueror, false otherwise. |
||
| 582 | */ |
||
| 583 | protected function checkBrowserKonqueror() |
||
| 587 | /** |
||
| 588 | * Determine if the browser is Lynx or not. It is the oldest web browser currently in general use and development. |
||
| 589 | * It is a text-based only Web browser. |
||
| 590 | * @access protected |
||
| 591 | * @link http://en.wikipedia.org/wiki/Lynx |
||
| 592 | * @return boolean Returns true if the browser is Lynx, false otherwise. |
||
| 593 | */ |
||
| 594 | protected function checkBrowserLynx() |
||
| 598 | /** |
||
| 599 | * Determine if the browser is Mozilla or not. |
||
| 600 | * @access protected |
||
| 601 | * @return boolean Returns true if the browser is Mozilla, false otherwise. |
||
| 602 | */ |
||
| 603 | protected function checkBrowserMozilla() |
||
| 607 | /** |
||
| 608 | * Determine if the browser is the MSNBot crawler or not. In October 2010 it was replaced by the Bingbot robot. |
||
| 609 | * @access protected |
||
| 610 | * @see checkBrowserBingbot() |
||
| 611 | * @return boolean Returns true if the browser is MSNBot, false otherwise. |
||
| 612 | */ |
||
| 613 | protected function checkBrowserMsnBot() |
||
| 617 | /** |
||
| 618 | * Determine if the browser is MSN TV (formerly WebTV) or not. |
||
| 619 | * @access protected |
||
| 620 | * @link http://en.wikipedia.org/wiki/MSN_TV |
||
| 621 | * @return boolean Returns true if the browser is WebTv, false otherwise. |
||
| 622 | */ |
||
| 623 | protected function checkBrowserMsnTv() |
||
| 627 | /** |
||
| 628 | * Determine if the browser is NetPositive or not. The browser is discontinued since November 2001. |
||
| 629 | * @access protected |
||
| 630 | * @link http://en.wikipedia.org/wiki/NetPositive |
||
| 631 | * @return boolean Returns true if the browser is NetPositive, false otherwise. |
||
| 632 | */ |
||
| 633 | protected function checkBrowserNetPositive() |
||
| 637 | /** |
||
| 638 | * Determine if the browser is Netscape or not. Official support for this browser ended on March 1st, 2008. |
||
| 639 | * @access protected |
||
| 640 | * @link http://en.wikipedia.org/wiki/Netscape |
||
| 641 | * @return boolean Returns true if the browser is Netscape, false otherwise. |
||
| 642 | */ |
||
| 643 | protected function checkBrowserNetscape() |
||
| 683 | /** |
||
| 684 | * Determine if the browser is a Nokia browser or not. |
||
| 685 | * @access protected |
||
| 686 | * @link http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices |
||
| 687 | * @return boolean Returns true if the browser is a Nokia browser, false otherwise. |
||
| 688 | */ |
||
| 689 | protected function checkBrowserNokia() |
||
| 703 | /** |
||
| 704 | * Determine if the browser is OmniWeb or not. |
||
| 705 | * @access protected |
||
| 706 | * @link http://www.omnigroup.com/products/omniweb/ |
||
| 707 | * @return boolean Returns true if the browser is OmniWeb, false otherwise. |
||
| 708 | */ |
||
| 709 | protected function checkBrowserOmniWeb() |
||
| 720 | /** |
||
| 721 | * Determine if the browser is Opera or not. |
||
| 722 | * @access protected |
||
| 723 | * @link http://www.opera.com/ |
||
| 724 | * @link http://www.opera.com/mini/ |
||
| 725 | * @link http://www.opera.com/mobile/ |
||
| 726 | * @link http://my.opera.com/community/openweb/idopera/ |
||
| 727 | * @return boolean Returns true if the browser is Opera, false otherwise. |
||
| 728 | */ |
||
| 729 | protected function checkBrowserOpera() |
||
| 754 | /** |
||
| 755 | * Determine if the browser is Phoenix or not. Phoenix was the name of Firefox from version 0.1 to 0.5. |
||
| 756 | * @access protected |
||
| 757 | * @return boolean Returns true if the browser is Phoenix, false otherwise. |
||
| 758 | */ |
||
| 759 | protected function checkBrowserPhoenix() |
||
| 763 | /** |
||
| 764 | * Determine what is the browser used by the user. |
||
| 765 | * @access protected |
||
| 766 | */ |
||
| 767 | protected function checkBrowsers() |
||
| 807 | /** |
||
| 808 | * Determine if the browser is Safari or not. |
||
| 809 | * @access protected |
||
| 810 | * @link http://www.apple.com/safari/ |
||
| 811 | * @link http://web.archive.org/web/20080514173941/http://developer.apple.com/internet/safari/uamatrix.html |
||
| 812 | * @link http://en.wikipedia.org/wiki/Safari_version_history#Release_history |
||
| 813 | * @return boolean Returns true if the browser is Safari, false otherwise. |
||
| 814 | */ |
||
| 815 | protected function checkBrowserSafari() |
||
| 844 | /** |
||
| 845 | * Determine if the browser is the Yahoo! Slurp crawler or not. |
||
| 846 | * @access protected |
||
| 847 | * @return boolean Returns true if the browser is Yahoo! Slurp, false otherwise. |
||
| 848 | */ |
||
| 849 | protected function checkBrowserSlurp() |
||
| 853 | /** |
||
| 854 | * Test the user agent for a specific browser that use a "Version" string (like Safari and Opera). The user agent |
||
| 855 | * should look like: "Version/1.0 Browser name/123.456" or "Browser name/123.456 Version/1.0". |
||
| 856 | * @access protected |
||
| 857 | * @param mixed $uaNameToLookFor The string (or array of strings) representing the browser name to find in the user |
||
| 858 | * agent. |
||
| 859 | * @param string $userAgent The user agent string to work with. |
||
| 860 | * @param string $browserName The literal browser name. Always use a class constant! |
||
| 861 | * @param boolean $isMobile Determines if the browser is from a mobile device. |
||
| 862 | * @param boolean $isRobot Determines if the browser is a robot or not. |
||
| 863 | * @return boolean Returns true if we found the browser we were looking for, false otherwise. |
||
| 864 | */ |
||
| 865 | protected function checkBrowserUAWithVersion($uaNameToLookFor, $userAgent, $browserName, $isMobile = false, $isRobot = false) |
||
| 887 | /** |
||
| 888 | * Determine if the browser is the W3C Validator or not. |
||
| 889 | * @access protected |
||
| 890 | * @link http://validator.w3.org/ |
||
| 891 | * @return boolean Returns true if the browser is the W3C Validator, false otherwise. |
||
| 892 | */ |
||
| 893 | protected function checkBrowserW3CValidator() |
||
| 920 | /** |
||
| 921 | * Determine if the browser is the Yahoo! multimedia crawler or not. |
||
| 922 | * @access protected |
||
| 923 | * @return boolean Returns true if the browser is the Yahoo! multimedia crawler, false otherwise. |
||
| 924 | */ |
||
| 925 | protected function checkBrowserYahooMultimedia() |
||
| 929 | /** |
||
| 930 | * Determine if the user is using an AOL "optimized" browser or not. |
||
| 931 | * @access protected |
||
| 932 | * @return boolean Returns true if the browser is AOL optimized, false otherwise. |
||
| 933 | */ |
||
| 934 | protected function checkForAol() |
||
| 953 | /** |
||
| 954 | * Determine the user's platform. |
||
| 955 | * @access protected |
||
| 956 | */ |
||
| 957 | protected function checkPlatform() |
||
| 1019 | /** |
||
| 1020 | * Test the user agent for a specific browser where the browser name is immediately followed by the version number. |
||
| 1021 | * The user agent should look like: "Browser name/1.0" or "Browser 1.0;". |
||
| 1022 | * @access protected |
||
| 1023 | * @param mixed $uaNameToLookFor The string (or array of strings) representing the browser name to find in the user |
||
| 1024 | * agent. |
||
| 1025 | * @param string $userAgent The user agent string to work with. |
||
| 1026 | * @param string $browserName The literal browser name. Always use a class constant! |
||
| 1027 | * @param boolean $isMobile Determines if the browser is from a mobile device. |
||
| 1028 | * @param boolean $isRobot Determines if the browser is a robot or not. |
||
| 1029 | * @param string $separator The separator string used to split the browser name and the version number in the user |
||
| 1030 | * agent. |
||
| 1031 | * @return boolean Returns true if we found the browser we were looking for, false otherwise. |
||
| 1032 | */ |
||
| 1033 | protected function checkSimpleBrowserUA($uaNameToLookFor, $userAgent, $browserName, $isMobile = false, $isRobot = false, $separator = '/') |
||
| 1059 | /** |
||
| 1060 | * Detect the user environment from the details in the user agent string. |
||
| 1061 | * @access protected |
||
| 1062 | */ |
||
| 1063 | protected function detect() |
||
| 1069 | /** |
||
| 1070 | * Clean a version string from unwanted characters. |
||
| 1071 | * @access protected |
||
| 1072 | * @param string $version The version string to clean. |
||
| 1073 | * @return string Returns the cleaned version number string. |
||
| 1074 | */ |
||
| 1075 | protected function cleanVersion($version) |
||
| 1089 | /** |
||
| 1090 | * Get the integer value of a string variable. |
||
| 1091 | * @access protected |
||
| 1092 | * @param string $intStr The scalar value being converted to an integer. |
||
| 1093 | * @return int The integer value of $intStr on success, or 0 on failure. |
||
| 1094 | */ |
||
| 1095 | protected function parseInt($intStr) |
||
| 1099 | /** |
||
| 1100 | * Reset all the properties of the class. |
||
| 1101 | * @access protected |
||
| 1102 | */ |
||
| 1103 | protected function reset() |
||
| 1116 | /** |
||
| 1117 | * Convert a Safari build number to a Safari version number. |
||
| 1118 | * @access protected |
||
| 1119 | * @param string $version A string representing the version number. |
||
| 1120 | * @link http://web.archive.org/web/20080514173941/http://developer.apple.com/internet/safari/uamatrix.html |
||
| 1121 | * @return string Returns the Safari version string. If the version can't be determined, an empty string is |
||
| 1122 | * returned. |
||
| 1123 | */ |
||
| 1124 | protected function safariBuildToSafariVer($version) |
||
| 1202 | /** |
||
| 1203 | * Set the browser to be from AOL or not. |
||
| 1204 | * @access protected |
||
| 1205 | * @param boolean $isAol Value that tells if the browser is AOL or not. |
||
| 1206 | */ |
||
| 1207 | protected function setAol($isAol) |
||
| 1211 | /** |
||
| 1212 | * Set the version of AOL. |
||
| 1213 | * @access protected |
||
| 1214 | * @param string $version The version of AOL (will be cleaned). |
||
| 1215 | */ |
||
| 1216 | protected function setAolVersion($version) |
||
| 1221 | /** |
||
| 1222 | * Set the name of the browser. |
||
| 1223 | * @access protected |
||
| 1224 | * @param string $browserName The name of the browser. |
||
| 1225 | */ |
||
| 1226 | protected function setBrowser($browserName) |
||
| 1230 | /** |
||
| 1231 | * Set the browser to be from a mobile device or not. |
||
| 1232 | * @access protected |
||
| 1233 | * @param boolean $isMobile Value that tells if the browser is on a mobile device or not. |
||
| 1234 | */ |
||
| 1235 | protected function setMobile($isMobile = true) |
||
| 1239 | /** |
||
| 1240 | * Set the platform on which the browser is on. |
||
| 1241 | * @access protected |
||
| 1242 | * @param string $platform The name of the platform. |
||
| 1243 | */ |
||
| 1244 | protected function setPlatform($platform) |
||
| 1248 | /** |
||
| 1249 | * Set the browser to be a robot (crawler) or not. |
||
| 1250 | * @access protected |
||
| 1251 | * @param boolean $isRobot Value that tells if the browser is a robot or not. |
||
| 1252 | */ |
||
| 1253 | protected function setRobot($isRobot = true) |
||
| 1257 | /** |
||
| 1258 | * Set the version of the browser. |
||
| 1259 | * @access protected |
||
| 1260 | * @param string $version The version of the browser. |
||
| 1261 | */ |
||
| 1262 | protected function setVersion($version) |
||
| 1271 | /** |
||
| 1272 | * Convert a WebKit build number to a Safari version number. |
||
| 1273 | * @access protected |
||
| 1274 | * @param string $version A string representing the version number. |
||
| 1275 | * @link http://web.archive.org/web/20080514173941/http://developer.apple.com/internet/safari/uamatrix.html |
||
| 1276 | * @return string Returns the Safari version string. If the version can't be determined, an empty string is |
||
| 1277 | * returned. |
||
| 1278 | */ |
||
| 1279 | protected function webKitBuildToSafariVer($version) |
||
| 1363 | } |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: