DeviceDetector\DeviceDetector::setCache PHP Méthode

setCache() public méthode

Sets the Cache class
public setCache ( DeviceDetector\Cache\Cache | CacheProvider $cache )
$cache DeviceDetector\Cache\Cache | Doctrine\Common\Cache\CacheProvider
    public function setCache($cache)
    {
        if ($cache instanceof Cache || class_exists('\\Doctrine\\Common\\Cache\\CacheProvider') && $cache instanceof \Doctrine\Common\Cache\CacheProvider) {
            $this->cache = $cache;
            return;
        }
        throw new \Exception('Cache not supported');
    }

Usage Example

 public function __construct(RequestStack $stack, CacheProvider $cache, $deviceDetectorOptions)
 {
     $this->cacheManager = $cache;
     $this->requestStack = $stack;
     $this->setOptions($deviceDetectorOptions);
     if (null !== $this->requestStack && $this->requestStack->getCurrentRequest()) {
         $userAgent = $this->requestStack->getCurrentRequest()->headers->get('User-Agent');
     } else {
         $userAgent = '';
     }
     $this->deviceDetector = new \DeviceDetector\DeviceDetector($userAgent);
     $this->deviceDetector->setCache($this->getCacheManager());
     if (!empty($this->deviceDetectorOptions['discard_bot_information'])) {
         $this->deviceDetector->discardBotInformation();
     }
     if (!empty($this->deviceDetectorOptions['skip_bot_detection'])) {
         $this->deviceDetector->skipBotDetection();
     }
     $this->deviceDetector->parse();
 }
All Usage Examples Of DeviceDetector\DeviceDetector::setCache