1<?php
2
3/*
4 * This file is part of pgFouine.
5 *
6 * pgFouine - a PostgreSQL log analyzer
7 * Copyright (c) 2005-2008 Guillaume Smet
8 *
9 * pgFouine is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
13 *
14 * pgFouine is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with pgFouine; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
22 */
23
24class NormalizedErrorsListener extends ErrorListener {
25	var $errorsList = array();
26	var $errorsNumber = 10;
27
28	function NormalizedErrorsListener() {
29		$this->errorsNumber = CONFIG_TOP_QUERIES_NUMBER;
30	}
31
32	function fireEvent(& $error) {
33		$normalizedText = $error->getNormalizedText();
34		if(isset($this->errorsList[$normalizedText])) {
35			$this->errorsList[$normalizedText]->addError($error);
36		} else {
37			$this->errorsList[$normalizedText] = new NormalizedError($error);
38		}
39	}
40
41	function & getMostFrequentErrors() {
42		$errorsList = $this->errorsList;
43		usort($errorsList, array($this, 'compareMostFrequent'));
44		$errors =& array_slice($errorsList, 0, $this->errorsNumber);
45		return $errors;
46	}
47
48	function compareMostFrequent(& $a, & $b) {
49		if($a->getTimesExecuted() == $b->getTimesExecuted()) {
50			return 0;
51		} elseif($a->getTimesExecuted() < $b->getTimesExecuted()) {
52			return 1;
53		} else {
54			return -1;
55		}
56	}
57
58	function getUniqueErrorCount() {
59		return count($this->errorsList);
60	}
61}
62
63?>