Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
InsertableFactory.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\TranslatorInterface\Insertable;
5
6use InvalidArgumentException;
7
21 public static function make( string $class, $params = null ): InsertablesSuggester {
22 // FIXME: We should look at using "id / class" similar to what we do with the ValidatorFactory
23 $checkedClasses = [];
24
25 // This check is done for custom insertables that might be added for certain groups.
26 if ( !class_exists( $class ) ) {
27 $checkedClasses[] = $class;
28 // Custom class not found, so lets try to load pre-provided Insertables.
29 $class = __NAMESPACE__ . '\\' . $class;
30 }
31
32 if ( !class_exists( $class ) ) {
33 $checkedClasses[] = $class;
34 throw new InvalidArgumentException(
35 'Could not find InsertableSuggester with class: ' . implode( ', ', $checkedClasses )
36 );
37 }
38
39 $suggester = new $class( $params );
40 if ( !$suggester instanceof InsertablesSuggester ) {
41 throw new InvalidArgumentException(
42 "$class does not implement the InsertableSuggester interface"
43 );
44 }
45
46 return $suggester;
47 }
48}
A factory class used to instantiate instances of Insertables.
static make(string $class, $params=null)
Takes a InsertableSuggester class name, and returns an instance of that class.