示例#1
0
 /**
  * @param crumbs_Container_WildcardDataSorted $weight_keeper
  */
 function initWeights($weight_keeper)
 {
     if ('user' !== $this->entityType) {
         return;
     }
     foreach (user_roles(TRUE) as $rid => $role) {
         $weight = $weight_keeper->valueAtKey($role);
         if (FALSE !== $weight) {
             $this->weights[$rid] = $weight;
         }
     }
     asort($this->weights);
 }
示例#2
0
 /**
  * Invoke all relevant plugins to find title or parent for a given path.
  *
  * @param array $plugin_methods
  * @param array $args
  * @param bool $processFindParent
  * @return mixed|null|void
  */
 protected function find($plugin_methods, $args, $processFindParent = FALSE)
 {
     $best_candidate = NULL;
     $best_candidate_weight = 999999;
     $best_candidate_key = NULL;
     foreach ($plugin_methods as $plugin_key => $method) {
         if (empty($this->plugins[$plugin_key])) {
             // Probably need a cache clear.
             continue;
         }
         $plugin = $this->plugins[$plugin_key];
         if ($plugin instanceof crumbs_MultiPlugin) {
             // That's a MultiPlugin
             /**
              * @var crumbs_Container_WildcardDataSorted $keeper
              */
             $keeper = $this->weightKeeper->prefixedContainer($plugin_key);
             if ($best_candidate_weight <= $keeper->smallestValue()) {
                 return $best_candidate;
             }
             if (!method_exists($plugin, $method)) {
                 // This means the code has changed, without the cache being cleared.
                 // It is the user's responsibility to clear the cache.
                 // Until then, we simply ignore and move on.
                 continue;
             }
             $candidates = call_user_func_array(array($plugin, $method), $args);
             if (!empty($candidates)) {
                 foreach ($candidates as $candidate_key => $candidate_raw) {
                     if (isset($candidate_raw)) {
                         $candidate_weight = $keeper->valueAtKey($candidate_key);
                         if (FALSE === $candidate_weight) {
                             continue;
                         }
                         $candidate = $processFindParent ? $this->processFindParent($candidate_raw) : $candidate_raw;
                         if ($this->candidateLogger) {
                             $this->candidateLogger->addCandidate("{$plugin_key}.{$candidate_key}", $candidate_weight, $candidate_raw, $candidate);
                         }
                         if ($best_candidate_weight > $candidate_weight && isset($candidate)) {
                             $best_candidate = $candidate;
                             $best_candidate_weight = $candidate_weight;
                             if ($this->candidateLogger) {
                                 $this->candidateLogger->setBestCandidateKey("{$plugin_key}.{$candidate_key}");
                             }
                         }
                     }
                 }
             }
         } elseif ($plugin instanceof crumbs_MonoPlugin) {
             // That's a MonoPlugin
             $candidate_weight = $this->weightKeeper->valueAtKey($plugin_key);
             if ($best_candidate_weight <= $candidate_weight) {
                 return $best_candidate;
             }
             if (!method_exists($plugin, $method)) {
                 // This means the code has changed, without the cache being cleared.
                 // It is the user's responsibility to clear the cache.
                 // Until then, we simply ignore and move on.
                 continue;
             }
             $candidate_raw = call_user_func_array(array($plugin, $method), $args);
             if (isset($candidate_raw)) {
                 $candidate = $processFindParent ? $this->processFindParent($candidate_raw) : $candidate_raw;
                 if ($this->candidateLogger) {
                     $this->candidateLogger->addCandidate($plugin_key, $candidate_weight, $candidate_raw, $candidate);
                 }
                 if (isset($candidate)) {
                     $best_candidate = $candidate;
                     $best_candidate_weight = $candidate_weight;
                     if ($this->candidateLogger) {
                         $this->candidateLogger->setBestCandidateKey($plugin_key);
                     }
                 }
             }
         }
     }
     return $best_candidate;
 }