MediaWiki  master
SearchEngineFactory.php
Go to the documentation of this file.
1 <?php
2 
6 
16  private $config;
17 
18  public function __construct( SearchEngineConfig $config ) {
19  $this->config = $config;
20  }
21 
27  public function create( $type = null ) {
28  $configuredClass = $this->config->getSearchType();
29  $alternativesClasses = $this->config->getSearchTypes();
30 
31  $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
32  if ( $type !== null && in_array( $type, $alternativesClasses ) ) {
33  $class = $type;
34  } elseif ( $configuredClass !== null ) {
35  $class = $configuredClass;
36  } else {
37  $class = self::getSearchEngineClass( $lb );
38  }
39 
40  if ( is_subclass_of( $class, SearchDatabase::class ) ) {
41  return new $class( $lb );
42  } else {
43  return new $class();
44  }
45  }
46 
52  public static function getSearchEngineClass( $dbOrLb ) {
53  $type = ( $dbOrLb instanceof IDatabase )
54  ? $dbOrLb->getType()
55  : $dbOrLb->getServerType( $dbOrLb->getWriterIndex() );
56 
57  switch ( $type ) {
58  case 'sqlite':
59  return SearchSqlite::class;
60  case 'mysql':
61  return SearchMySQL::class;
62  case 'postgres':
63  return SearchPostgres::class;
64  default:
65  return SearchEngineDummy::class;
66  }
67  }
68 }
SearchEngineConfig $config
Configuration for SearchEngine classes.
create( $type=null)
Create SearchEngine of the given type.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
static getSearchEngineClass( $dbOrLb)
__construct(SearchEngineConfig $config)