You are here

function crumbs_PluginOperation_findForPath::invoke in Crumbs, the Breadcrumbs suite 7

This should run once for each plugin object. It should be called by the PluginEngine, during invokeUntilFound().

Overrides crumbs_PluginOperationInterface_find::invoke

File

lib/PluginOperation/findForPath.php, line 40

Class

crumbs_PluginOperation_findForPath

Code

function invoke($plugin, $plugin_key, $weight_keeper) {
  $smallest_weight = $weight_keeper
    ->getSmallestWeight();
  if (isset($this->candidateWeight) && $this->candidateWeight <= $smallest_weight) {

    // any further candidate would have a higher weight, thus lower priority,
    // than what we already have found. Thus, we can stop searching.
    return TRUE;
  }
  foreach ($this->methods as $method) {
    if (method_exists($plugin, $method)) {
      $result = $this
        ->_invoke($plugin, $method);
      break;
    }
  }
  if ($plugin instanceof crumbs_MultiPlugin) {

    // we expect an array result.
    if (!empty($result) && is_array($result)) {
      foreach ($result as $key => $value) {
        $weight = $weight_keeper
          ->findWeight($key);
        $this
          ->_setValue($plugin_key . '.' . $key, $value, $weight);
      }
    }
    else {
      $this->log[$plugin_key . '.*'] = array(
        NULL,
        NULL,
      );
    }
  }
  elseif ($plugin instanceof crumbs_MonoPlugin) {

    // we expect a simple value as a result
    if (isset($result)) {
      $weight = $weight_keeper
        ->findWeight();
      $this
        ->_setValue($plugin_key, $result, $weight);
    }
    else {
      $this->log[$plugin_key] = array(
        NULL,
        NULL,
      );
    }
  }
}