You are here

class PurgePurgerBundleAPI in Purge 7.2

Provides a full bundle.

The full bundle contains the complete purge module configuration. Used for management and operations that require all items, including disabled ones.

Hierarchy

Expanded class hierarchy of PurgePurgerBundleAPI

File

includes/purge.class.inc, line 828
Contains all class and interface definitions for Purge.

View source
class PurgePurgerBundleAPI extends PurgePurgerBundle implements PurgeValidateable {

  /**
   * Constructs the full bundle.
   */
  public function __construct() {

    // Get the data from the given dataset.
    $select_data = $this
      ->get_data();

    // Then get the datastructure of the types up.
    foreach ($select_data['type'] as $type_name => $type_data) {
      $this->type[$type_name] = unserialize($type_data);

      // And create an object for each item
      foreach ($select_data[$type_name] as $item_name => $item_data) {
        $this->{$type_name}[$item_name] = unserialize($item_data);
      }
    }

    // Purgers need special handling
    foreach ($this->purger as $purger_name => $purger) {

      // Each type name that is a pointer.
      foreach ($purger->pointers as $pointer_type => $item_names) {
        $this->purger[$purger_name]->{$pointer_type} = array();
      }
    }
  }

  /**
   * Merges another bundle into this one.
   *
   * @param object $merge_bundle
   *   A bundle, instance of PurgeBundleBasic.
   * @param bool $overwrite
   *   Overwrites with the merge bundle value should a duplicate be found.
   */
  public function merge($merge_bundle, $overwrite = 1) {

    // First check if this is actually another bundle.
    if (!$merge_bundle instanceof PurgePurgerBundle) {
      return;
    }

    // Loop through all types.
    foreach ($this->type as $type_name => $type) {

      // Walk the merge bundle item.
      foreach ($merge_bundle->{$type_name} as $item_name => $item) {

        // Check if the item exists in this bundle.
        if ($overwrite == 1 || !isset($this->{$type_name}[$item_name])) {

          // Set the merged item.
          $this->{$type_name}[$item_name] = clone $merge_bundle->{$type_name}[$item_name];
        }
      }
    }
  }

  /**
   * Validates the bundle.
   *
   * @return array $errors
   */
  public function validate() {
    $errors = array();
    foreach ($this->type as $type_name => $type) {
      foreach ($this->{$type_name} as $item) {
        if ($item instanceof PurgeValidateable) {
          $item_errors = $item
            ->validate();
          if (count($item_errors) > 0) {
            foreach ($item_errors as $item_error) {
              $errors[] = $item_error;
            }
          }
        }
      }
    }
    return $errors;
  }

  /**
   * Saves the bundle to the variable.
   */
  public function save() {
    $data = array();

    // Serialize this bundle.
    $data = serialize($this);

    // Replace the object type in the serialized data with the default api
    // Strip off the first double quote (object name length)
    for ($i = 0; $i <= 1; $i++) {
      $data = ltrim($data, chr(34));
      $data = strstr($data, chr(34));
    }
    $data = 'O:20:"PurgePurgerBundleAPI' . $data;

    // Store the data in the variable
    variable_set('purge_config', $data);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Purge::$access public property
Purge::$available public property
Purge::$depend public property
Purge::$description public property
Purge::$enabled public property
Purge::$item public property
Purge::$name public property
Purge::$option public property
PurgePurger::$domain public property
PurgePurger::$handler public property
PurgePurger::$header public property
PurgePurger::$queue public property
PurgePurger::$target public property
PurgePurgerBundle::$type public property
PurgePurgerBundle::get_data public function Function to select data from the dataset.
PurgePurgerBundle::set_types public function Function to set the type objects.
PurgePurgerBundle::__sleep public function Override for parents sleep to make sure we include the bundled objects. Overrides Purge::__sleep
PurgePurgerBundle::__wakeup public function Set the item objects linked in this bundle when waking up.
PurgePurgerBundleAPI::merge public function Merges another bundle into this one.
PurgePurgerBundleAPI::save public function Saves the bundle to the variable.
PurgePurgerBundleAPI::validate public function Validates the bundle. Overrides Purge::validate
PurgePurgerBundleAPI::__construct public function Constructs the full bundle. 1