You are here

private function MobileDeviceDetection::check in Mobile Device Detection 8.3

Same name and namespace in other branches
  1. 8.2 src/Object/MobileDeviceDetection.php \Drupal\mobile_device_detection\Object\MobileDeviceDetection::check()

Is checking which kind of device using.

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

File

src/Object/MobileDeviceDetection.php, line 193

Class

MobileDeviceDetection
MobileDeviceDetection object.

Namespace

Drupal\mobile_device_detection\Object

Code

private function check($type) {
  if ($this
    ->getUserAgentHeaders() === 'Amazon CloudFront') {
    $headers = $this
      ->setCloudHeaders($this
      ->getRequest()
      ->getCurrentRequest()->server
      ->all());
    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:
      $device = false;
      foreach ($options as $value) {
        if (!empty($value)) {
          if ($this
            ->match($value)) {
            $device = TRUE;
          }
        }
      }
      if ($device) {
        foreach ($this
          ->getAttributes()
          ->get('browsers') as $value) {
          if (!empty($value)) {
            if ($this
              ->match($value)) {
              return TRUE;
            }
          }
        }
      }
      break;
  }
  return FALSE;
}