Skip to content

Commit

Permalink
added missing class DeviceDetectorFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Jun 8, 2014
1 parent 6229e8f commit 18f9b8c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions core/DeviceDetectorFactory.php
Original file line number Diff line number Diff line change
@@ -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;
}

}

0 comments on commit 18f9b8c

Please sign in to comment.