From 18f9b8c4ed39df73b540c91168c56e615e441975 Mon Sep 17 00:00:00 2001 From: sgiehl <stefan@piwik.org> Date: Sun, 8 Jun 2014 19:53:31 +0200 Subject: [PATCH] added missing class DeviceDetectorFactory --- core/DeviceDetectorFactory.php | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 core/DeviceDetectorFactory.php diff --git a/core/DeviceDetectorFactory.php b/core/DeviceDetectorFactory.php new file mode 100644 index 0000000000..f8bd1ad5ac --- /dev/null +++ b/core/DeviceDetectorFactory.php @@ -0,0 +1,39 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik; + +use DeviceDetector\DeviceDetector; + +class DeviceDetectorFactory +{ + protected static $deviceDetectorInstances = array(); + + /** + * Returns a Singleton instance of DeviceDetector for the given user agent + * @param string $userAgent + * @return DeviceDetector + */ + public static function getInstance($userAgent) + { + if (array_key_exists($userAgent, self::$deviceDetectorInstances)) { + + return self::$deviceDetectorInstances[$userAgent]; + } + + $deviceDetector = new DeviceDetector($userAgent); + $deviceDetector->discardBotInformation(); + $deviceDetector->setCache(new DeviceDetectorCache('tracker', 86400)); + $deviceDetector->parse(); + + self::$deviceDetectorInstances[$userAgent] = $deviceDetector; + + return $deviceDetector; + } + +} -- GitLab