You are here

class WsConfigType in Web Service Data 7

The class used for wsconfig type entities

Hierarchy

Expanded class hierarchy of WsConfigType

1 string reference to 'WsConfigType'
wsconfig_entity_info in modules/wsconfig/wsconfig.module
Implements hook_entity_info().

File

modules/wsconfig/wsconfig.entity.inc, line 379
Entity classes

View source
class WsConfigType extends Entity {
  public $type;
  public $label;
  public function __construct($values = array()) {
    parent::__construct($values, 'wsconfig_type');
    if (is_array($this->data) and !isset($this->data['degraded_backoff'])) {
      $this->data['degraded_backoff'] = WSCONFIG_DEFAULT_DEGRADED_BACKOFF;
    }
  }

  /**
   * Gets the enabled language plugin
   *
   * @return array|boolean
   *  Returns the language plugin and settings, FALSE otherwise.
   */
  public function getEnabledLanguagePlugin() {
    $plugin = FALSE;
    if (!empty($this->data['language plugin'])) {
      $plugin = array(
        $this->data['language plugin'] => isset($this->data['language plugin settings']) ? $this->data['language plugin settings'] : array(),
      );
    }
    return $plugin;
  }

  /*
   * API function to get endpoint from the WSConfig Type
   */
  public function setEndpoint($endpoint) {
    $this->data['endpoint'] = $endpoint;
    return true;
  }

  /*
   * API function to set the endpoint in the WSConfig Type.
   */
  public function getEndpoint() {
    $endpoint = $this->data['endpoint'];
    $matches = array();
    preg_match_all('/\\$\\{(.+?)(:.+){0,1}\\}/', $endpoint, $matches);
    if (!empty($matches[0])) {
      for ($n = 0; $n < count($matches[0]); $n++) {
        $default = '';
        if (isset($matches[2][$n])) {
          $default = drupal_substr($matches[2][$n], 1);
        }
        $replacements[] = (string) variable_get($matches[1][$n], $default);
      }
      $endpoint = str_replace($matches[0], $replacements, $endpoint);
    }
    return $endpoint;
  }

  /**
   * API function to disabled this wsconfig type.
   */
  public function disable($degraded = FALSE) {
    $reason = '';
    if ($degraded) {
      if (!isset($this->data['degraded_backoff'])) {
        $this->data['degraded_backoff'] = WSCONFIG_DEFAULT_DEGRADED_BACKOFF;
      }
      if ($this->data['degraded_backoff'] == 0) {
        return;
      }
      $reason = '  ' . t('Automatically disabled due to degrated service.');
      $this->data['degraded'] = time();
    }
    $this->data['disabled'] = TRUE;
    watchdog('wsconfig', t('WSConfig Type %label (%type) was disabled.', array(
      '%label' => $this->label,
      '%type' => $this->type,
    )) . $reason);
    $this
      ->save();
  }

  /**
   * API function to enabled this wsconfig type.
   */
  public function enable($degraded = FALSE) {
    unset($this->data['degraded']);
    unset($this->data['disabled']);
    $reason = '';
    if ($degraded) {
      $reason = '  ' . t('Automatically re-enabling previously degrated service.');
    }
    watchdog('wsconfig', t('WSConfig Type %label (%type) was enabled.', array(
      '%label' => $this->label,
      '%type' => $this->type,
    )) . $reason);
    $this
      ->save();
  }

  /**
   * API function to check if this wsconfig type is disabled.
   */
  public function isDisabled() {
    if (!isset($this->data['degraded_backoff'])) {
      $this->data['degraded_backoff'] = WSCONFIG_DEFAULT_DEGRADED_BACKOFF;
    }
    if (isset($this->data['degraded']) and $this->data['degraded'] < time() - $this->data['degraded_backoff']) {
      $this
        ->enable(TRUE);
      return FALSE;
    }
    return isset($this->data['disabled']) ? $this->data['disabled'] : FALSE;
  }
  public function getDegraded() {
    if (!isset($this->data['degraded_backoff'])) {
      $this->data['degraded_backoff'] = WSCONFIG_DEFAULT_DEGRADED_BACKOFF;
    }
    if (isset($this->data['degraded'])) {
      return $this->data['degraded'] - time() + $this->data['degraded_backoff'];
    }
    return 0;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Entity::$defaultLabel protected property 1
Entity::$entityInfo protected property
Entity::$entityType protected property
Entity::$idKey protected property
Entity::$wrapper protected property
Entity::buildContent public function Builds a structured array representing the entity's content. Overrides EntityInterface::buildContent 1
Entity::bundle public function Returns the bundle of the entity. Overrides EntityInterface::bundle
Entity::defaultLabel protected function Defines the entity label if the 'entity_class_label' callback is used. 1
Entity::defaultUri protected function Override this in order to implement a custom default URI and specify 'entity_class_uri' as 'uri callback' hook_entity_info().
Entity::delete public function Permanently deletes the entity. Overrides EntityInterface::delete
Entity::entityInfo public function Returns the info of the type of the entity. Overrides EntityInterface::entityInfo
Entity::entityType public function Returns the type of the entity. Overrides EntityInterface::entityType
Entity::export public function Exports the entity. Overrides EntityInterface::export
Entity::getTranslation public function Gets the raw, translated value of a property or field. Overrides EntityInterface::getTranslation
Entity::hasStatus public function Checks if the entity has a certain exportable status. Overrides EntityInterface::hasStatus
Entity::identifier public function Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface::identifier
Entity::internalIdentifier public function Returns the internal, numeric identifier. Overrides EntityInterface::internalIdentifier
Entity::isDefaultRevision public function Checks whether the entity is the default revision. Overrides EntityInterface::isDefaultRevision
Entity::label public function Returns the label of the entity. Overrides EntityInterface::label
Entity::save public function Permanently saves the entity. Overrides EntityInterface::save
Entity::setUp protected function Set up the object instance on construction or unserializiation.
Entity::uri public function Returns the uri of the entity just as entity_uri(). Overrides EntityInterface::uri
Entity::view public function Generate an array for rendering the entity. Overrides EntityInterface::view
Entity::wrapper public function Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface::wrapper
Entity::__sleep public function Magic method to only serialize what's necessary.
Entity::__wakeup public function Magic method to invoke setUp() on unserialization.
WsConfigType::$label public property
WsConfigType::$type public property
WsConfigType::disable public function API function to disabled this wsconfig type.
WsConfigType::enable public function API function to enabled this wsconfig type.
WsConfigType::getDegraded public function
WsConfigType::getEnabledLanguagePlugin public function Gets the enabled language plugin
WsConfigType::getEndpoint public function
WsConfigType::isDisabled public function API function to check if this wsconfig type is disabled.
WsConfigType::setEndpoint public function
WsConfigType::__construct public function Overrides Entity::__construct