2declare( strict_types = 1 );
4namespace MediaWiki\Extension\Translate\TtmServer;
24 public function __construct( array $configs, ?
string $default =
null ) {
25 $this->configs = $configs;
26 $this->
default = $default;
32 foreach ( $this->configs as $serviceId => $config ) {
33 $type = $config[
'type'] ??
'';
34 if ( $type ===
'ttmserver' || $type ===
'remote-ttmserver' ) {
35 $ttmServersIds[] = $serviceId;
38 return $ttmServersIds;
41 public function has(
string $name ): bool {
42 $ttmServersIds = $this->getNames();
43 return in_array( $name, $ttmServersIds );
46 public function create(
string $name ):
TTMServer {
47 if ( !$this->has( $name ) ) {
48 throw new ServiceCreationFailure(
"No configuration for name '$name'" );
51 $config = $this->configs[$name];
52 if ( !is_array( $config ) ) {
53 throw new ServiceCreationFailure(
"Invalid configuration for name '$name'" );
56 if ( isset( $config[
'class'] ) ) {
57 $class = $config[
'class'];
58 return new $class( $config );
59 } elseif ( isset( $config[
'type'] ) ) {
60 $type = $config[
'type'];
64 case 'remote-ttmserver':
67 throw new ServiceCreationFailure(
"Unknown type for name '$name': $type" );
71 throw new ServiceCreationFailure(
"Invalid configuration for name '$name': type not specified" );
79 if ( $this->
default !==
null ) {
80 $service = $this->create( $this->
default );
NO-OP version of TTMServer when it is disabled.
Class for handling remote TTMServers over MediaWiki API.
Some general static methods for instantiating TTMServer and helpers.
Interface for TTMServer that can be updated.