PHP Classes

File: classes/debugger.php

Recommend this page to a friend!
  Classes of Janne   PHP Apache Log Parser and Filter   classes/debugger.php   Download  
File: classes/debugger.php
Role: Auxiliary script
Content type: text/plain
Description: debugger class for ApacheAccessLogFilter
Class: PHP Apache Log Parser and Filter
Parse and filter Apache logs to discard crawlers
Author: By
Last change:
Date: 11 years ago
Size: 2,699 bytes
 

Contents

Class file image Download
<?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);
    }
}

?>