Bump and prep 1.34.1
[lhc/web/wiklou.git] / includes / search / BaseSearchResultSet.php
1 <?php
2
3 /**
4 * BaseSearchResultSet is the base class that must be extended by SearchEngine
5 * search result set implementations.
6 *
7 * This base class is meant to hold B/C behaviors and to be useful it must never:
8 * - be used as type hints (ISearchResultSet must be used for this)
9 * - implement a constructor
10 * - declare utility methods
11 *
12 * @ingroup Search
13 */
14 abstract class BaseSearchResultSet implements ISearchResultSet {
15
16 /**
17 * @var ArrayIterator|null Iterator supporting BC iteration methods
18 */
19 private $bcIterator;
20
21 /**
22 * Fetches next search result, or false.
23 * @deprecated since 1.32; Use self::extractResults() or foreach
24 * @return SearchResult|false
25 */
26 public function next() {
27 wfDeprecated( __METHOD__, '1.32' );
28 $it = $this->bcIterator();
29 $searchResult = $it->current();
30 $it->next();
31 return $searchResult ?? false;
32 }
33
34 /**
35 * Rewind result set back to beginning
36 * @deprecated since 1.32; Use self::extractResults() or foreach
37 */
38 public function rewind() {
39 wfDeprecated( __METHOD__, '1.32' );
40 $this->bcIterator()->rewind();
41 }
42
43 private function bcIterator() {
44 if ( $this->bcIterator === null ) {
45 $this->bcIterator = 'RECURSION';
46 $this->bcIterator = $this->getIterator();
47 } elseif ( $this->bcIterator === 'RECURSION' ) {
48 // Either next/rewind or extractResults must be implemented. This
49 // class was potentially instantiated directly. It should be
50 // abstract with abstract methods to enforce this but that's a
51 // breaking change...
52 wfDeprecated( static::class . ' without implementing extractResults', '1.32' );
53 $this->bcIterator = new ArrayIterator( [] );
54 }
55 return $this->bcIterator;
56 }
57
58 /**
59 * Fetch an array of regular expression fragments for matching
60 * the search terms as parsed by this engine in a text extract.
61 * STUB
62 *
63 * @return string[]
64 * @deprecated since 1.34 (use SqlSearchResult)
65 */
66 public function termMatches() {
67 return [];
68 }
69
70 /**
71 * Frees the result set, if applicable.
72 * @deprecated noop since 1.34
73 */
74 public function free() {
75 }
76 }