class crumbs_RuleWeightKeeper in Crumbs, the Breadcrumbs suite 6.2
Same name and namespace in other branches
- 7 lib/RuleWeightKeeper.php \crumbs_RuleWeightKeeper
Hierarchy
- class \crumbs_RuleWeightKeeper
Expanded class hierarchy of crumbs_RuleWeightKeeper
File
- ./
crumbs.plugin_engine.inc, line 235
View source
class crumbs_RuleWeightKeeper {
protected $_rule_weights;
protected $_prefixedKeepers = array();
protected $_prefixSorted = array();
protected $_soloSorted = array();
function __construct(array $rule_weights) {
asort($rule_weights);
$this->_rule_weights = $rule_weights;
}
function prefixedWeightKeeper($prefix) {
if (!isset($this->_prefixedKeepers[$prefix])) {
$this->_prefixedKeepers[$prefix] = $this
->_buildPrefixedWeightKeeper($prefix);
}
return $this->_prefixedKeepers[$prefix];
}
protected function _buildPrefixedWeightKeeper($prefix) {
$weights = array();
$k = strlen($prefix);
$weights[''] = $weights['*'] = $this
->_findWildcardWeight($prefix);
if (isset($this->_rule_weights[$prefix])) {
$weights[''] = $this->_rule_weights[$prefix];
}
if (isset($this->_rule_weights[$prefix . '.*'])) {
$weights['*'] = $this->_rule_weights[$prefix . '.*'];
}
foreach ($this->_rule_weights as $key => $weight) {
if (strlen($key) > $k && substr($key, 0, $k + 1) === $prefix . '.') {
$weights[substr($key, $k + 1)] = $weight;
}
}
return new crumbs_RuleWeightKeeper($weights);
}
function getSmallestWeight() {
foreach ($this->_rule_weights as $weight) {
if ($weight !== FALSE) {
return $weight;
}
}
return FALSE;
}
/**
* Determine the weight for the rule specified by the key.
*/
function findWeight($key = NULL) {
if (!isset($key)) {
return $this->_rule_weights[''];
}
if (isset($this->_rule_weights[$key])) {
return $this->_rule_weights[$key];
}
return $this
->_findWildcardWeight($key);
}
protected function _findWildcardWeight($key) {
$fragments = explode('.', $key);
$partial_key = array_shift($fragments);
$weight = $this->_rule_weights['*'];
while (!empty($fragments)) {
if (isset($this->_rule_weights[$partial_key . '.*'])) {
$weight = $this->_rule_weights[$partial_key . '.*'];
}
$partial_key .= '.' . array_shift($fragments);
}
return $weight;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
crumbs_RuleWeightKeeper:: |
protected | property | ||
crumbs_RuleWeightKeeper:: |
protected | property | ||
crumbs_RuleWeightKeeper:: |
protected | property | ||
crumbs_RuleWeightKeeper:: |
protected | property | ||
crumbs_RuleWeightKeeper:: |
function | Determine the weight for the rule specified by the key. | ||
crumbs_RuleWeightKeeper:: |
function | |||
crumbs_RuleWeightKeeper:: |
function | |||
crumbs_RuleWeightKeeper:: |
protected | function | ||
crumbs_RuleWeightKeeper:: |
protected | function | ||
crumbs_RuleWeightKeeper:: |
function |