Merge "Allow putting the app ID in the password for bot passwords"
[lhc/web/wiklou.git] / includes / search / SearchEngineFactory.php
1 <?php
2
3 /**
4 * Factory class for SearchEngine.
5 * Allows to create engine of the specific type.
6 */
7 class SearchEngineFactory {
8
9 /**
10 * Configuration for SearchEngine classes.
11 * @var SearchEngineConfig
12 */
13 private $config;
14
15 public function __construct( SearchEngineConfig $config ) {
16 $this->config = $config;
17 }
18
19 /**
20 * Create SearchEngine of the given type.
21 * @param string $type
22 * @return SearchEngine
23 */
24 public function create( $type = null ) {
25 $dbr = null;
26
27 $configType = $this->config->getSearchType();
28 $alternatives = $this->config->getSearchTypes();
29
30 if ( $type && in_array( $type, $alternatives ) ) {
31 $class = $type;
32 } elseif ( $configType !== null ) {
33 $class = $configType;
34 } else {
35 $dbr = wfGetDB( DB_REPLICA );
36 $class = $dbr->getSearchEngine();
37 }
38
39 $search = new $class( $dbr );
40 return $search;
41 }
42 }