CandidateLogger.php in Crumbs, the Breadcrumbs suite 7.2
File
lib/Debug/CandidateLogger.php
View source
<?php
class crumbs_Debug_CandidateLogger {
protected $logFindParent = array();
protected $logFindTitle = array();
protected $info = array();
function getLogFindParent() {
return $this->logFindParent;
}
function getLogFindTitle() {
return $this->logFindTitle;
}
function getAsMatrix($trail) {
$rows = array();
$weights = array();
$empty_row = array();
$default_row = array();
$paths = array_keys($trail);
foreach ($paths as $i => $path) {
$empty_row["{$path}:title"] = '';
$default_row["{$path}:title"] = isset($trail[$path]['title']) ? $trail[$path]['title'] : 'NULL';
$empty_row["{$path}:parent"] = '';
$default_row["{$path}:parent"] = isset($paths[$i + 1]) ? $paths[$i + 1] : 'END';
}
if (isset($path)) {
unset($empty_row["{$path}:parent"]);
unset($default_row["{$path}:parent"]);
}
$best_cells = array();
foreach (array(
'parent' => $this->logFindParent,
'title' => $this->logFindTitle,
) as $type => $log) {
foreach ($log as $info) {
if (isset($info['bestCandidateKey'])) {
$best_cells[$info['bestCandidateKey']][$info['path'] . ':' . $type] = TRUE;
}
else {
$best_cells['(default)'][$info['path'] . ':' . $type] = TRUE;
}
if (isset($info['candidates'])) {
foreach ($info['candidates'] as $key => $candidate) {
if (!isset($rows[$key])) {
$rows[$key] = $empty_row;
$weights[$key] = $candidate['weight'];
}
if (!isset($candidate['raw'])) {
$value = '(NULL)';
}
elseif (FALSE === $candidate['raw']) {
$value = '(FALSE)';
}
else {
$value = check_plain($candidate['raw']);
if ($candidate['processed'] !== $candidate['raw']) {
$value .= '<br/>->' . check_plain($candidate['processed']);
}
}
$rows[$key][$info['path'] . ':' . $type] = $value;
}
}
if (isset($info['path'])) {
$cols[$info['path']] = array();
}
}
}
asort($weights);
$matrix = array();
foreach ($weights as $key => $weight) {
$matrix[$key] = $rows[$key];
}
$weights['(default)'] = '-';
$matrix['(default)'] = $default_row;
return array(
$matrix,
$best_cells,
$weights,
);
}
function endFindParent($path, $item) {
$this->logFindParent[] = $this->info + compact('path', 'item');
$this->info = array();
}
function endFindTitle($path, $item, $breadcrumb) {
$this->logFindTitle[] = $this->info + compact('path', 'item', 'breadcrumb');
$this->info = array();
}
function addCandidate($key, $weight, $raw, $processed) {
$this->info['candidates'][$key] = compact('weight', 'raw', 'processed');
}
function setBestCandidateKey($key) {
$this->info['bestCandidateKey'] = $key;
if (isset($this->info['candidates'][$key])) {
$this->info['bestCandidate'] = $this->info['candidates'][$key];
}
}
}