You are here

private function MobileDeviceDetectionObject::check in Mobile Device Detection 8

1 call to MobileDeviceDetectionObject::check()
MobileDeviceDetectionObject::init in src/Object/MobileDeviceDetectionObject.php

File

src/Object/MobileDeviceDetectionObject.php, line 166

Class

MobileDeviceDetectionObject

Namespace

Drupal\mobile_device_detection\Object

Code

private function check($type) {
  if ($this
    ->getUserAgentHeaders() === 'Amazon CloudFront') {
    $headers = $this
      ->setCloudHeaders();
    if (array_key_exists('HTTP_CLOUDFRONT_IS_MOBILE_VIEWER', $headers) && $headers['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER'] === 'true') {
      return true;
    }
  }
  switch ($type) {
    case 'mobile':
      $options = array_merge($this
        ->getAttributes()
        ->get('phone_devices'));
      $headers = array_intersect_key($this
        ->getAttributes()
        ->get('mobile_headers'), $this
        ->getMobileHeaders());
      foreach ($headers as $key => $value) {
        foreach ($value as $v) {
          if (strpos($this
            ->getMobileHeaders()[$key], $v) !== false) {
            return true;
          }
        }
      }
      goto device_detect;
      break;
    case 'tablet':
      $options = array_merge($this
        ->getAttributes()
        ->get('tablet_devices'));
    case 'deviceDetect':
      device_detect:
      foreach ($options as $value) {
        if (!empty($value)) {
          if ($this
            ->_match($value)) {
            return true;
          }
        }
      }
      break;
  }
  return false;
}