MediaWiki  1.34.0
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 }
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
SearchEngineFactory\$config
SearchEngineConfig $config
Configuration for SearchEngine classes.
Definition: SearchEngineFactory.php:16
SearchEngineFactory
Factory class for SearchEngine.
Definition: SearchEngineFactory.php:11
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
SearchEngineFactory\getSearchEngineClass
static getSearchEngineClass( $dbOrLb)
Definition: SearchEngineFactory.php:52
SearchEngineFactory\__construct
__construct(SearchEngineConfig $config)
Definition: SearchEngineFactory.php:18
SearchEngineConfig
Configuration handling class for SearchEngine.
Definition: SearchEngineConfig.php:9
SearchEngineFactory\create
create( $type=null)
Create SearchEngine of the given type.
Definition: SearchEngineFactory.php:27
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
$type
$type
Definition: testCompression.php:48