Apply live hack from Wikimedia code base: profiling point around SVN version lookup
[lhc/web/wiklou.git] / includes / Parser_DiffTest.php
1 <?php
2
3 class Parser_DiffTest
4 {
5 var $parsers, $conf;
6
7 function __construct( $conf ) {
8 if ( !isset( $conf['parsers'] ) ) {
9 throw new MWException( __METHOD__ . ': no parsers specified' );
10 }
11 $this->conf = $conf;
12 }
13
14 function init() {
15 if ( !is_null( $this->parsers ) ) {
16 return;
17 }
18 foreach ( $this->conf['parsers'] as $i => $parserConf ) {
19 if ( !is_array( $parserConf ) ) {
20 $class = $parserConf;
21 $parserConf = array( 'class' => $parserConf );
22 } else {
23 $class = $parserConf['class'];
24 }
25 $this->parsers[$i] = new $class( $parserConf );
26 }
27 }
28
29 function __call( $name, $args ) {
30 $this->init();
31 $results = array();
32 $mismatch = false;
33 $lastResult = null;
34 $first = true;
35 foreach ( $this->parsers as $i => $parser ) {
36 $currentResult = call_user_func_array( array( &$this->parsers[$i], $name ), $args );
37 if ( $first ) {
38 $first = false;
39 } else {
40 if ( $lastResult !== $currentResult ) {
41 $mismatch = true;
42 }
43 }
44 $results[$i] = $currentResult;
45 $lastResult = $currentResult;
46 }
47 if ( $mismatch ) {
48 throw new MWException( "Parser_DiffTest: results mismatch on call to $name\n" .
49 'Arguments: ' . var_export( $args, true ) . "\n" .
50 'Results: ' . var_export( $results, true ) . "\n" );
51 }
52 return $lastResult;
53 }
54
55 function setFunctionHook( $id, $callback, $flags = 0 ) {
56 $this->init();
57 foreach ( $this->parsers as $i => $parser ) {
58 $parser->setFunctionHook( $id, $callback, $flags );
59 }
60 }
61 }
62