findForPath.php in Crumbs, the Breadcrumbs suite 7
File
lib/PluginOperation/findForPath.php
View source
<?php
abstract class crumbs_PluginOperation_findForPath implements crumbs_PluginOperationInterface_find {
protected $path;
protected $item;
protected $method;
protected $methodSuffix;
protected $methods = array();
protected $candidateKey;
protected $candidateValue;
protected $candidateWeight;
protected $log;
function __construct($path, $item) {
$this->path = $path;
$this->item = $item;
$method_suffix = crumbs_build_method_suffix($item['path']);
if ($method_suffix !== FALSE) {
$this->methods[] = $this->method . '__' . $method_suffix;
}
$this->methods[] = $this->method;
}
function invoke($plugin, $plugin_key, $weight_keeper) {
$smallest_weight = $weight_keeper
->getSmallestWeight();
if (isset($this->candidateWeight) && $this->candidateWeight <= $smallest_weight) {
return TRUE;
}
foreach ($this->methods as $method) {
if (method_exists($plugin, $method)) {
$result = $this
->_invoke($plugin, $method);
break;
}
}
if ($plugin instanceof crumbs_MultiPlugin) {
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) {
if (isset($result)) {
$weight = $weight_keeper
->findWeight();
$this
->_setValue($plugin_key, $result, $weight);
}
else {
$this->log[$plugin_key] = array(
NULL,
NULL,
);
}
}
}
function getValue() {
return $this->candidateValue;
}
function getCandidateKey() {
return $this->candidateKey;
}
function getLoggedCandidates() {
return $this->log;
}
protected function _setValue($key, $value, $weight) {
if ($weight !== FALSE) {
if (!isset($this->candidateWeight) || $weight < $this->candidateWeight) {
$this->candidateWeight = $weight;
$this->candidateValue = $value;
$this->candidateKey = $key;
}
}
$this->log[$key] = array(
$value,
$weight,
);
}
protected abstract function _invoke($plugin, $method);
}