requestFactory = $requestFactory; $this->urls = $urls; $this->key = $key; } /** * Test whether remote Shellbox is enabled by configuration. * * @param string|null $service Same as the service option for getClient. * @return bool */ public function isEnabled( ?string $service = null ): bool { return $this->getUrl( $service ) !== null; } /** * Get a Shellbox client with the specified options. If remote Shellbox is * not configured (isEnabled() returns false), an exception will be thrown. * * @param array $options Associative array of options: * - timeout: The request timeout in seconds * - service: the shellbox backend name to get the URL from the mapping * @return Client * @throws \RuntimeException */ public function getClient( array $options = [] ) { $url = $this->getUrl( $options['service'] ?? null ); if ( $url === null ) { throw new \RuntimeException( 'To use a remote shellbox to run shell commands, ' . '$wgShellboxUrls and $wgShellboxSecretKey must be configured.' ); } return new Client( new ShellboxHttpClient( $this->requestFactory, $options['timeout'] ?? self::DEFAULT_TIMEOUT ), new Uri( $url ), $this->key ); } private function getUrl( ?string $service ): ?string { if ( $this->urls === null || !strlen( $this->key ) ) { return null; } $url = $this->urls[$service] ?? $this->urls['default'] ?? null; if ( !is_string( $url ) ) { return null; } return $url; } }