| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Title\Title; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class FauxSearchResultSet extends SearchResultSet { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
private $totalHits; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public function __construct( array $results, $totalHits = null ) { |
| 23 |
$totalHits = max( count( $results ), $totalHits ); |
| 24 |
$hasMoreResults = count( $results ) < $totalHits; |
| 25 |
parent::__construct( false, $hasMoreResults ); |
| 26 |
$this->results = array_map( static function ( $result ) { |
| 27 |
if ( $result instanceof SearchResult ) { |
| 28 |
return $result; |
| 29 |
} elseif ( $result instanceof Title ) { |
| 30 |
return new FauxSearchResult( $result ); |
| 31 |
} else { |
| 32 |
throw new InvalidArgumentException( '$results must contain Title or SearchResult' ); |
| 33 |
} |
| 34 |
}, $results ); |
| 35 |
$this->totalHits = $totalHits; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
public function getTotalHits() { |
| 40 |
return $this->totalHits; |
| 41 |
} |
| 42 |
|
| 43 |
} |