MediaWiki fundraising/REL1_35
SearchEngineFactory.php
Go to the documentation of this file.
1<?php
2
5use Wikimedia\ObjectFactory;
8
18 private $config;
19
22
23 public function __construct( SearchEngineConfig $config, HookContainer $hookContainer ) {
24 $this->config = $config;
25 $this->hookContainer = $hookContainer;
26 }
27
34 public function create( $type = null ) {
35 $configuredClass = $this->config->getSearchType();
36 $alternativesClasses = $this->config->getSearchTypes();
37
38 $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
39 if ( $type !== null && in_array( $type, $alternativesClasses ) ) {
40 $class = $type;
41 } elseif ( $configuredClass !== null ) {
42 $class = $configuredClass;
43 } else {
44 $class = self::getSearchEngineClass( $lb );
45 }
46
47 $mappings = $this->config->getSearchMappings();
48
49 if ( isset( $mappings[$class] ) ) {
50 $spec = $mappings[$class];
51 } else {
52 // Convert non mapped classes to ObjectFactory spec
53 $spec = [ 'class' => $class ];
54 }
55
56 $args = [];
57
58 if ( isset( $spec['class'] ) && is_subclass_of( $spec['class'], SearchDatabase::class ) ) {
59 $args['extraArgs'][] = $lb;
60 }
61
63 $engine = ObjectFactory::getObjectFromSpec( $spec, $args );
64 $engine->setHookContainer( $this->hookContainer );
65 return $engine;
66 }
67
73 public static function getSearchEngineClass( $dbOrLb ) {
74 $type = ( $dbOrLb instanceof IDatabase )
75 ? $dbOrLb->getType()
76 : $dbOrLb->getServerType( $dbOrLb->getWriterIndex() );
77
78 switch ( $type ) {
79 case 'sqlite':
80 return SearchSqlite::class;
81 case 'mysql':
82 return SearchMySQL::class;
83 case 'postgres':
84 return SearchPostgres::class;
85 default:
86 return SearchEngineDummy::class;
87 }
88 }
89}
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.
__construct(SearchEngineConfig $config, HookContainer $hookContainer)
static getSearchEngineClass( $dbOrLb)
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.
if( $line===false) $args
Definition mcc.php:124