File: BaseSearchResultSet.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (79 lines) | stat: -rw-r--r-- 2,235 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php

/**
 * BaseSearchResultSet is the base class that must be extended by SearchEngine
 * search result set implementations.
 *
 * This base class is meant to hold B/C behaviors and to be useful it must never:
 * - be used as type hints (ISearchResultSet must be used for this)
 * - implement a constructor
 * - declare utility methods
 *
 * @stable to extend
 * @ingroup Search
 */
abstract class BaseSearchResultSet implements ISearchResultSet {

	/**
	 * @var ArrayIterator|null Iterator supporting BC iteration methods
	 */
	private $bcIterator;

	/**
	 * Fetches next search result, or false.
	 * @deprecated since 1.32; Use self::extractResults() or foreach
	 * @return SearchResult|false
	 */
	public function next() {
		wfDeprecated( __METHOD__, '1.32' );
		$it = $this->bcIterator();
		$searchResult = $it->current();
		$it->next();
		return $searchResult ?? false;
	}

	/**
	 * Rewind result set back to beginning
	 * @deprecated since 1.32; Use self::extractResults() or foreach
	 */
	public function rewind() {
		wfDeprecated( __METHOD__, '1.32' );
		$this->bcIterator()->rewind();
	}

	private function bcIterator() {
		if ( $this->bcIterator === null ) {
			// @phan-suppress-next-line PhanTypeMismatchProperty Expected
			$this->bcIterator = 'RECURSION';
			$this->bcIterator = $this->getIterator();
		} elseif ( $this->bcIterator === 'RECURSION' ) {
			// @phan-suppress-previous-line PhanTypeComparisonFromArray Use of string is a hack
			// Either next/rewind or extractResults must be implemented.  This
			// class was potentially instantiated directly. It should be
			// abstract with abstract methods to enforce this but that's a
			// breaking change...
			wfDeprecated( static::class . ' without implementing extractResults', '1.32' );
			$this->bcIterator = new ArrayIterator( [] );
		}
		return $this->bcIterator;
	}

	/**
	 * Fetch an array of regular expression fragments for matching
	 * the search terms as parsed by this engine in a text extract.
	 * STUB
	 *
	 * @return string[]
	 * @deprecated since 1.34 (use SqlSearchResult)
	 */
	public function termMatches() {
		return [];
	}

	/**
	 * Frees the result set, if applicable.
	 * @deprecated since 1.34; noop
	 */
	public function free() {
	}
}