Development

Changeset 22656

You must first sign up to be able to contribute.

Changeset 22656

Show
Ignore:
Timestamp:
09/30/09 23:02:38 (4 years ago)
Author:
Tomek
Message:

New public function: getRE
Few more checks when parser object is created
More unit tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/tmApacheLogParserPlugin/lib/tmApacheLogParser.class.php

    r21799 r22656  
    3636  { 
    3737    return $this->lineParser->parse($line); 
     38  } 
     39   
     40   
     41  /** 
     42   * Returns a regular expression that is used to parse each line. 
     43   * 
     44   * @return string 
     45   */ 
     46  public function getRE() 
     47  { 
     48    return $this->lineParser->getRE(); 
    3849  } 
    3950   
  • plugins/tmApacheLogParserPlugin/lib/tmApacheLogParserException.class.php

    r21764 r22656  
    11<?php  
    22class tmApacheLogParserException extends Exception { 
     3  public static $INVALID_ARGUMENT = 1; 
    34} 
  • plugins/tmApacheLogParserPlugin/lib/tmLineParser.class.php

    r22650 r22656  
    77  public function __construct($re, $params) 
    88  { 
     9     
     10    if(! is_array($params) || !count($re) || !count($params)) { 
     11      throw new tmApacheLogParserException("You must provide arrays to the constructor",tmApacheLogParserException::$INVALID_ARGUMENT); 
     12    } 
     13     
    914    $all = array ( 
    1015      'remote_ip' => array ( 
     
    6065    } 
    6166    $this->re = vsprintf($re, $reParams); 
     67     
     68    if(! $this->re) { 
     69      throw new tmApacheLogParserException("Invalid argument(s)",tmApacheLogParserException::$INVALID_ARGUMENT); 
     70    } 
    6271  } 
    6372   
     
    6675    $matches = array (); 
    6776    $ret = preg_match('/' . $this->re . '/', $line, $matches); 
    68  
     77     
    6978    if(! $ret) { 
    7079      //ok, we didn't match the line - that's too bad! 
     
    7988      $result[$element['name']] = $element['parser']->parse($matches[$i ++]); 
    8089    } 
    81  
     90     
    8291    return $result; 
    8392  } 
     93   
     94  /** 
     95   * Returns a regular expression that is used to parse each line. 
     96   * 
     97   * @return string 
     98   */ 
     99  public function getRE() 
     100  { 
     101    return '/' . $this->re . '/'; 
     102  } 
    84103} 
  • plugins/tmApacheLogParserPlugin/package.xml

    r21800 r22656  
    3737   <file name="test/unit/test2.php" role="data"/> 
    3838   <file name="test/unit/test3.php" role="data"/> 
     39   <file name="test/unit/test4.php" role="data"/> 
     40   <file name="test/unit/test5.php" role="data"/> 
     41   <file name="test/unit/test6.php" role="data"/> 
    3942  </dir> 
    4043 </contents> 
     
    6164  <release> 
    6265    <version> 
    63       <release>0.1.0</release> 
    64       <api>0.1.0</api> 
     66      <release>0.1.5</release> 
     67      <api>0.1.5</api> 
    6568    </version> 
    6669    <stability>