class RulesElementMap
Helper object for mapping elements to ids.
Hierarchy
- class \RulesElementMap
Expanded class hierarchy of RulesElementMap
File
-
ui/
ui.core.inc, line 90
View source
class RulesElementMap {
/**
* @var RulesPlugin
*/
protected $configuration;
protected $index = array();
protected $counter = 0;
/**
* Constructor.
*/
public function __construct(RulesPlugin $config) {
$this->configuration = $config->root();
}
/**
* Makes sure each element has an assigned id.
*/
public function index() {
foreach ($this->getUnIndexedElements($this->configuration) as $element) {
$id =& $element->property('elementId');
$id = ++$this->counter;
$this->index[$id] = $element;
}
}
protected function getUnIndexedElements($element, &$unindexed = array()) {
// Remember unindexed elements.
$id = $element->property('elementId');
if (!isset($id)) {
$unindexed[] = $element;
}
else {
// Make sure $this->counter refers to the highest id.
if ($id > $this->counter) {
$this->counter = $id;
}
$this->index[$id] = $element;
}
// Recurse down the tree.
if ($element instanceof RulesContainerPlugin) {
foreach ($element as $child) {
$this->getUnIndexedElements($child, $unindexed);
}
}
return $unindexed;
}
/**
* Looks up the element with the given id.
*/
public function lookup($id) {
if (!$this->index) {
$this->index();
}
return isset($this->index[$id]) ? $this->index[$id] : FALSE;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
RulesElementMap::$configuration | protected | property | |
RulesElementMap::$counter | protected | property | |
RulesElementMap::$index | protected | property | |
RulesElementMap::getUnIndexedElements | protected | function | |
RulesElementMap::index | public | function | Makes sure each element has an assigned id. |
RulesElementMap::lookup | public | function | Looks up the element with the given id. |
RulesElementMap::__construct | public | function | Constructor. |