<?php
/**
* @author janne
* The BSD 2-Clause
* Copyright (c) 2012-2013, Janne Hyytiä
* phpclAl rights reserved.
*
* This is a debugger class for the ApacheAccessLogFilter. Basically it's just
* a proxying class for the ApacheAccessLogFilter. Not very finnished one, but
* there isn't a bit debugging need for the class as of yet, so I think it's
* sufficient.
*
* @example
* $debugger = new Debugger(null, $ip2nation);
* $ip2nation = $debugger;
* $accessLogStr = new ApacheAccessLogFilter($source, explode(",", $_POST['needles']), $ip2nation);
* $debugger->apacheLogClass = $accessLogStr;
* $accessLogStr = $debugger;
*/
class Debugger {
public
$timeSpentDB = 0,
$timeSpentRegExp = 0,
$total = 0,
$apacheLogClass,
$ip2NationClass;
public function __construct(ApacheAccessLogFilter $class1 = null, Ip2Nation $class2 = null) {
$this->total = $this->getTime();
$this->apacheLogClass = $class1;
$this->ip2NationClass = $class2;
}
// ========= Proxy functions
public function resolveCountry($IPv4)
{
$time = $this->getTime();
$helppi = $this->ip2NationClass->resolveCountry($IPv4);
$this->addToRegExpCounter($this->getTime() - $time);
return $helppi;
}
public function filterVariable($value)
{
$time = $this->getTime();
$helppi = $this->ip2NationClass->filterVariable($value);
$this->addToRegExpCounter($this->getTime() - $time);
return $helppi;
}
public function filterAll()
{
$this->apacheLogClass->filterAll();
}
public function __toString()
{
return $this->apacheLogClass->getStringi();
}
public function showNeedles()
{
return implode(",", $this->apacheLogClass->needles);
}
public function showDefaultNeedles()
{
return implode(",", $this->apacheLogClass->defaultNeedles);
}
public function applyMods($string)
{
$time = $this->getTime();
var_dump($time);
$helppi = $this->apacheLogClass->applyMods($string);
$this->addToDBCounter($this->getTime() - $time);
return $helppi;
}
// =========
private function addToDBCounter($time) {
$this->timeSpentDB += $time;
}
private function addToRegExpCounter($time) {
$this->timeSpentDB += $time;
}
private function getTime() {
return microtime();
}
public function showTotal() {
return ($this->getTime() - $this->total);
}
}
?>
|