You are here

function mobile_detect_get_object in Mobile Detect 7

Getter function to retrieve a Mobile_Detect() singleton.

Return value

object Instance of Mobile_Detect(), NULL if failure.

4 calls to mobile_detect_get_object()
mobile_detect_check_type in ./mobile_detect.module
Predicate function to test a device type.
mobile_detect_ctools_access_settings in mobile_detect_ctools/plugins/access/mobile_detect_ctools.inc
Settings form callback.
mobile_detect_variables_preprocess in mobile_detect_variables/mobile_detect_variables.module
Implements template_preprocess().
_mobile_detect_full_debug in ./mobile_detect.module
Content generator for hook_block_view('mobile_detect_full_debug')

File

./mobile_detect.module, line 54
Lightweight mobile detection based on the Mobile_Detect.php library.

Code

function mobile_detect_get_object() {
  $detect =& drupal_static(__FUNCTION__);
  if (!isset($detect)) {
    if (class_exists('Mobile_Detect')) {
      try {
        $detect = new Mobile_Detect();
      } catch (Exception $e) {
        $detect = NULL;
        watchdog('mobile_detect', 'Could not instantiate Mobile_Detect(): %message', array(
          '%message' => $e
            ->getMessage(),
        ), WATCHDOG_ALERT);
      }
    }
    else {
      $detect = NULL;
      watchdog('mobile_detect', 'Mobile_Detect() class does not exist', array(), WATCHDOG_ALERT);
    }
  }
  return $detect;
}