<?php #-*-Mode: php; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/*
jjfMapper, a cartography program for PHP 4.
Copyright (C) 2004 John J Foerch
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//This class maintains three lists: info, error, and warning.
//The keys of each array are a textual debug message.
//The values are numbers associated with the messages,
//treated as an incrementer by default.
class debugreport {
var $entries = array (
'info' => array(),
'error' => array(),
'warning' => array()
);
var $allowed_types;
function debugreport () {
$this->allowed_types = array_keys ($this->entries);
}
function add() {
$t = func_num_args();
if ($t == 0) { return; }
$s = func_get_arg(0);
if (is_array ($s))
{
foreach ($s as $s_k => $s_v) {
if (array_search ($s_k, $this->allowed_types) === false)
{
$type = $this->allowed_types[0];
} else {
$type = $s_k;
}
if (isset ($this->entries[$type][$s_v]))
{
++$this->entries[$type][$s_v];
} else {
$this->entries[$type][$s_v] = 1;
}
}
} else {
if (isset ($this->entries['info'][$s]))
{
++$this->entries['info'][$s];
} else {
$this->entries['info'][$s] = 1;
}
}
}
function merge (&$dbg_report) {
if (! isset ($dbg_report->entries)) return;
foreach ($dbg_report->entries as $src_k => $src_v) {
if (array_search ($src_k, $this->allowed_types) === false)
{
$dest_k = $this->allowed_types[0];
} else {
$dest_k = $src_k;
}
foreach ($src_v as $src_v_k => $src_v_v) {
if (isset ($this->entries[$dest_k][$src_v_k]))
{
$this->entries[$dest_k][$src_v_k] += $src_v_v;
} else {
$this->entries[$dest_k][$src_v_k] = $src_v_v;
}
}
}
}
function report () {
$report = '';
foreach ($this->entries as $t_k => $t_v) {
uksort($this->entries[$t_k], "strnatcmp");
$report .= '=== Section: '.$t_k.' ==='.LF;
foreach($this->entries[$t_k] as $entry_k => $entry_v) {
$report .= $entry_v .TAB. $entry_k .LF;
}
$report .= LF;
}
return $report;
}
}//debugreport
?>