MediaWiki REL1_34
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}
MediaWikiServices is the service locator for the application scope of MediaWiki.
Configuration handling class for SearchEngine.
Factory class for SearchEngine.
create( $type=null)
Create SearchEngine of the given type.
static getSearchEngineClass( $dbOrLb)
__construct(SearchEngineConfig $config)
SearchEngineConfig $config
Configuration for SearchEngine classes.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
Database cluster connection, tracking, load balancing, and transaction manager interface.