9 var $shortOutput = false;
13 function __construct( $conf ) {
14 if ( !isset( $conf['parsers'] ) ) {
15 throw new MWException( __METHOD__
. ': no parsers specified' );
18 $this->dtUniqPrefix
= "\x7fUNIQ" . Parser
::getRandomString();
22 if ( !is_null( $this->parsers
) ) {
27 static $doneHook = false;
30 $wgHooks['ParserClearState'][] = array( $this, 'onClearState' );
32 if ( isset( $this->conf
['shortOutput'] ) ) {
33 $this->shortOutput
= $this->conf
['shortOutput'];
36 foreach ( $this->conf
['parsers'] as $i => $parserConf ) {
37 if ( !is_array( $parserConf ) ) {
39 $parserConf = array( 'class' => $parserConf );
41 $class = $parserConf['class'];
43 $this->parsers
[$i] = new $class( $parserConf );
47 function __call( $name, $args ) {
53 foreach ( $this->parsers
as $i => $parser ) {
54 $currentResult = call_user_func_array( array( &$this->parsers
[$i], $name ), $args );
58 if ( is_object( $lastResult ) ) {
59 if ( $lastResult != $currentResult ) {
63 if ( $lastResult !== $currentResult ) {
68 $results[$i] = $currentResult;
69 $lastResult = $currentResult;
72 if ( count( $results ) == 2 ) {
73 $resultsList = array();
74 foreach ( $this->parsers
as $i => $parser ) {
75 $resultsList[] = var_export( $results[$i], true );
77 $diff = wfDiff( $resultsList[0], $resultsList[1] );
79 $diff = '[too many parsers]';
81 $msg = "Parser_DiffTest: results mismatch on call to $name\n";
82 if ( !$this->shortOutput
) {
83 $msg .= 'Arguments: ' . $this->formatArray( $args ) . "\n";
85 $msg .= 'Results: ' . $this->formatArray( $results ) . "\n" .
87 throw new MWException( $msg );
92 function formatArray( $array ) {
93 if ( $this->shortOutput
) {
94 foreach ( $array as $key => $value ) {
95 if ( $value instanceof ParserOutput
) {
96 $array[$key] = "ParserOutput: {$value->getText()}";
100 return var_export( $array, true );
103 function setFunctionHook( $id, $callback, $flags = 0 ) {
105 foreach ( $this->parsers
as $i => $parser ) {
106 $parser->setFunctionHook( $id, $callback, $flags );
110 function onClearState( &$parser ) {
111 // hack marker prefixes to get identical output
112 $parser->mUniqPrefix
= $this->dtUniqPrefix
;