You are here

function notifications_object in Notifications 7

Same name and namespace in other branches
  1. 6.4 notifications.module \notifications_object()

Create a wrapped object and keep a static cache of created objects.

@parma $value Object or object key

Parameters

$type: Object type

7 calls to notifications_object()
notifications_content_node_links in notifications_content/notifications_content.module
Attach subscription links to the node object.
notifications_content_notifications_subscription in notifications_content/notifications_content.module
Implementation of hook notifications_subscription()
Notifications_Event::add_object in ./notifications.event.inc
Add Drupal Object, converting it into a Notifications_Object
Notifications_Field::get_object in ./notifications.field.inc
Get related Notifications object
Notifications_Node_Author_Field::get_object in notifications_user/notifications_user.inc
Get object.

... See full list

File

./notifications.module, line 856
Notifications module

Code

function notifications_object($type, $value) {
  $cache =& drupal_static(__FUNCTION__);
  $class = notifications_object_type($type, 'class', 'Notifications_Drupal_Object');
  if (is_object($value) && is_a($value, $class)) {

    // Already an instance of the right class, just return
    return $object;
  }
  elseif (is_numeric($value) || is_string($value)) {
    $key = $value;
  }
  if (isset($key) && isset($cache[$type][$key])) {
    return $cache[$type][$key];
  }
  else {
    $object = Notifications_Object::build($type, $value);

    // Not all objects are cacheable, only if they have a value
    if ($key = $object
      ->get_value()) {
      $cache[$type][$key] = $object;
    }
    return $object;
  }
}