Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeviceDetectorFactory.php 996B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Piwik - free/libre analytics platform
  4. *
  5. * @link http://piwik.org
  6. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7. *
  8. */
  9. namespace Piwik;
  10. use DeviceDetector\DeviceDetector;
  11. class DeviceDetectorFactory
  12. {
  13. protected static $deviceDetectorInstances = array();
  14. /**
  15. * Returns a Singleton instance of DeviceDetector for the given user agent
  16. * @param string $userAgent
  17. * @return DeviceDetector
  18. */
  19. public static function getInstance($userAgent)
  20. {
  21. if (array_key_exists($userAgent, self::$deviceDetectorInstances)) {
  22. return self::$deviceDetectorInstances[$userAgent];
  23. }
  24. $deviceDetector = new DeviceDetector($userAgent);
  25. $deviceDetector->discardBotInformation();
  26. $deviceDetector->setCache(new DeviceDetectorCache('tracker', 86400));
  27. $deviceDetector->parse();
  28. self::$deviceDetectorInstances[$userAgent] = $deviceDetector;
  29. return $deviceDetector;
  30. }
  31. }