cvs: pear /Log_Parser/Parser/Filter Filter.php Filter_Personal.php Filter_Regex.php
| From: | Xavier Noguer Gallego | Date: | Wed, 24 Sep 2003 15:18:31 +0000 |
| Subject: | cvs: pear /Log_Parser/Parser/Filter Filter.php Filter_Personal.php Filter_Regex.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-13059@lists.php.net to get a copy of this message | ||
xnoguer Wed Sep 24 11:18:31 2003 EDT
Added files:
/pear/Log_Parser/Parser/Filter Filter.php Filter_Personal.php
Filter_Regex.php
Log:
commiting for toby
Index: pear/Log_Parser/Parser/Filter/Filter.php
+++ pear/Log_Parser/Parser/Filter/Filter.php
<?php
define('LOG_PARSER_FILTER_DYNAMIC', 'dynamic', true);
define('LOG_PARSER_FILTER_STATIC', 'static', true);
/**
* PEAR::Log_Parser::Filter
*
* This are the baseclasses for Log_Parser_Filter objects.
*
* @author Tobias Schlitt <toby@php.net>
* @package Log_Parser
* @version $Revision: 1.1 $
*/
// These two classes represent the base of all Log_Parser filters.
// There exist 2 different types of filters: Dynamic and static filter.
//
// A dynamic filter 'binds' it's methods to different tokens, which means,
// that you have to define your methods i style linename_tokenname. E.g. if
// you want to filter a token 'date' in a line 'standard' your method has to
// be named standard_date(). Your method has to return a boolean value which
// determines if a token has passed the filtering (true) or not (false). As parameter
// the method has to take the token as a reference. So you are able to change the
// token inside your method.
//
// A static filter provides a method 'filter', which does the complete filtering.
// You can do everything inside your filtering class, but you have to provide a
// method called filter(). This method has to take 3 parameters: The name of the
// current line, the name of the token and the token itself (as a reference), so
// you can change the token in your class, if needed.
class Log_Parser_Filter_Dynamic {
/**
* The filter constructor
* The constructor of a dynamic filter class has to get no parameters.
*/
function Log_Parser_Filter_Dynamic ( ) {
}
/**
* Filtering method
* The filtering methods will be called for each token to filter. The name of the
* methods is constructed by 'linename' + '_' + 'tokenname'.
The methods have to take
* only 1 parameter, which will be the contents of the token to filter, as a reference.
* This enables you to change the token while filtering it.
*
* @param string $token The token to check
* @return bool True if filter applies, otherwise false.
*/
function linename_tokenname ( &$token ) {
}
}
class Log_Parser_Filter_Static {
/**
* The filter constructor
* The constructor of a dynamic filter class has to get no parameters.
*/
function Log_Parser_Filter_Static ( ) {
}
/**
* Filtering method
* The filtering method of a static filter class is allways called 'filter'.
* The method will take $lineName (the name of the parsed line), $tokenName (the
* name of the current token) and $token (the content of the token) as parameter.
*
* @param string $lineName The name of the line to check
* @param string $tokenName The name of the token to check
* @param string $token The token to check
* @return bool True if filter applies, otherwise false.
*/
function filter ( $lineName, $tokenName, $token ) {
}
}
?>
Index: pear/Log_Parser/Parser/Filter/Filter_Personal.php
+++ pear/Log_Parser/Parser/Filter/Filter_Personal.php
<?php
require_once 'Log_Parser/Parser/Filter/Filter.php';
/**
* PEAR::Log_Parser::Filter_Personal
*
* This is an example PEAR::Log_Parser::Filter class which
* shows dynamic filtering.
*
* @author Tobias Schlitt <toby@php.net>
* @package Log_Parser
* @version $Revision: 1.1 $
*/
// This is an example for a dynamic filter
//
// The class shows how to provide a basic dynamic filtering class for
// Log_Parser. The class binds functionality to the token 'date' in line
// 'standard', which changes the date format from english to german.
class Log_Parser_Filter_Personal extends Log_Parser_Filter_Dynamic {
function Log_Parser_Filter_Personal ( ) {
}
function standard_date ( &$token ) {
$tmpDate = explode('/', $token);
$token = implode('-', $tmpDate);
$token = strtotime($token);
$token = date('d.m.Y', $token);
return true;
}
}
?>
Index: pear/Log_Parser/Parser/Filter/Filter_Regex.php
+++ pear/Log_Parser/Parser/Filter/Filter_Regex.php
<?php
require_once 'Log_Parser/Parser/Filter/Filter.php';
/**
* PEAR::Log_Parser::Filter_Regex
*
* This is a standard PEAR::Log_Parser::Filter class which
* implements RegEx filtering.
*
* @author Tobias Schlitt <toby@php.net>
* @package Log_Parser
* @version $Revision: 1.1 $
*/
// This is an example for a static filter.
//
// The class provides basic regex filtering for Log_Parser. You can define
// multiple regex for each token to filter your log by creating a new object
// of this class and add as many regex by calling addConfition() on it.
// addCondition() takes 3 parameters. The name of the line and token as first
// and second and the regex to apply to the token.
class Log_Parser_Filter_Regex extends Log_Parser_Filter_Static {
var $_regex = array();
function Log_Parser_Filter_Regex ( ) {
}
function addCondition ( $lineName, $tokenName, $regex ) {
$this->_regex[$lineName][$tokenName][] = $regex;
}
function filter ( $lineName, $tokenName, &$token ) {
if (isset($this->_regex[$lineName][$tokenName])) {
foreach ($this->_regex[$lineName][$tokenName] as $regex) {
echo "<b>$regex -- $token</b><br>";
if (!preg_match($regex, $token)) {
return false;
}
}
}
return true;
}
}
?>