34 foreach ( $this->configs as $serviceId => $config ) {
35 $type = $config[
'type'] ??
'';
36 if ( $type ===
'ttmserver' || $type ===
'remote-ttmserver' ) {
37 $ttmServersIds[] = $serviceId;
43 $serviceClass = $config[
'class'] ??
null;
44 if ( $serviceClass !==
null ) {
45 foreach ( self::TTMSERVER_CLASSES as $ttmClass ) {
46 if ( $serviceClass instanceof $ttmClass ) {
47 $ttmServersIds[] = $serviceId;
53 return $ttmServersIds;
123 $writableServers = $readOnlyServers = [];
124 $ttmServerIds = $this->getNames();
126 foreach ( $ttmServerIds as $serverId ) {
127 $isWritable = $this->configs[ $serverId ][
'writable' ] ??
null;
128 $mirrors = $this->configs[ $serverId ][
'mirrors' ] ??
null;
130 if ( $mirrors !==
null ) {
131 if ( $isWritable !==
null || $writableServers !== [] ) {
132 throw new InvalidArgumentException(
133 "TTM server configurations cannot use both writable and mirrors parameter."
139 if ( $serverId === $this->
default ) {
140 throw new InvalidArgumentException(
141 "Default TTM server {$this->default} cannot be write only"
145 $server = $this->create( $serverId );
146 if ( !$server instanceof WritableTtmServer ) {
147 throw new InvalidArgumentException(
148 "Server '$serverId' marked writable does not implement WritableTtmServer interface"
151 $writableServers[ $serverId ] = $server;
152 } elseif ( $isWritable ===
false ) {
153 $readOnlyServers[] = $serverId;
157 if ( $writableServers ) {
158 return $writableServers;
162 if ( $this->
default ) {
164 $defaultTtmServer = $this->create( $this->
default );
166 if ( $defaultTtmServer instanceof WritableTtmServer ) {
167 if ( !in_array( $this->
default, $readOnlyServers ) ) {
168 $writableServers[ $this->default ] = $defaultTtmServer;
170 $mirrorIds = $defaultTtmServer->getMirrors();
173 foreach ( $mirrorIds as $id ) {
174 if ( !in_array( $id, $readOnlyServers ) ) {
175 $writableServers[ $id ] = $writableServers[ $id ] ?? $this->create( $id );
179 if ( $writableServers ) {
180 return $writableServers;
190 $ttmServerIds = $this->getNames();
191 $writableServers = [];
192 foreach ( $ttmServerIds as $serverId ) {
193 if ( $this->configs[ $serverId ][
'writable' ] ??
false ) {
194 $server = $this->create( $serverId );
196 throw new \InvalidArgumentException(
197 "Server '$serverId' marked writable does not implement WritableTtmServer interface"
200 $writableServers[ $serverId ] = $server;
204 return $writableServers;