diff --git a/src/Client/Action/ActionApi.php b/src/Client/Action/ActionApi.php index c67de96..474cd57 100644 --- a/src/Client/Action/ActionApi.php +++ b/src/Client/Action/ActionApi.php @@ -37,17 +37,21 @@ class ActionApi implements Requester, LoggerAwareInterface { private LoggerInterface $logger; + private array $config; + /** * @param string $apiUrl The API Url * @param AuthMethod|null $auth Auth method to use. null for NoAuth * @param ClientInterface|null $client Guzzle Client * @param Tokens|null $tokens Inject a custom tokens object here + * @param array $config ClientInterface compatible configuration array */ public function __construct( string $apiUrl, AuthMethod $auth = null, ?ClientInterface $client = null, - Tokens $tokens = null + Tokens $tokens = null, + array $config = [] ) { if ( $auth === null ) { $auth = new NoAuth(); @@ -61,6 +65,7 @@ public function __construct( $this->auth = $auth; $this->client = $client; $this->tokens = $tokens; + $this->config = $config; $this->logger = new NullLogger(); } @@ -71,7 +76,7 @@ public function getApiUrl(): string { private function getClient(): ClientInterface { if ( !$this->client instanceof ClientInterface ) { - $clientFactory = new ClientFactory(); + $clientFactory = new ClientFactory( $this->config ); $clientFactory->setLogger( $this->logger ); $this->client = $clientFactory->getClient(); } diff --git a/src/Client/MediaWiki.php b/src/Client/MediaWiki.php index 3255155..e626f28 100644 --- a/src/Client/MediaWiki.php +++ b/src/Client/MediaWiki.php @@ -32,21 +32,25 @@ class MediaWiki { private RestApi $rest; - public function __construct( string $baseUrl, AuthMethod $auth = null ) { + private array $config; + + public function __construct( string $baseUrl, AuthMethod $auth = null, array $config = [] ) { if ( $auth === null ) { $auth = new NoAuth(); } $this->baseUrl = $baseUrl; $this->auth = $auth; + $this->config = $config; } /** * @param string $anApiEndpoint Either the REST or Action API endpoint e.g. https://en.wikipedia.org/w/api.php * @param AuthMethod|null $auth + * @param array $config ClientInterface compatible configuration array */ - public static function newFromEndpoint( string $anApiEndpoint, AuthMethod $auth = null ): self { - return new self( self::pruneActionOrRestPhp( $anApiEndpoint ), $auth ); + public static function newFromEndpoint( string $anApiEndpoint, AuthMethod $auth = null, array $config = [] ): self { + return new self( self::pruneActionOrRestPhp( $anApiEndpoint ), $auth, $config ); } private static function pruneActionOrRestPhp( string $url ): string { @@ -56,14 +60,15 @@ private static function pruneActionOrRestPhp( string $url ): string { /** * @param string $anApiEndpoint A page on a MediaWiki site e.g. https://en.wikipedia.org/wiki/Main_Page * @param AuthMethod|null $auth + * @param array $config ClientInterface compatible configuration array */ - public static function newFromPage( string $pageUrl, AuthMethod $auth = null ): self { - return new self( ReallySimpleDiscovery::baseFromPage( $pageUrl ), $auth ); + public static function newFromPage( string $pageUrl, AuthMethod $auth = null, array $config = [] ): self { + return new self( ReallySimpleDiscovery::baseFromPage( $pageUrl ), $auth, $config ); } public function action(): ActionApi { if ( !isset( $this->action ) ) { - $this->action = new ActionApi( $this->baseUrl . self::ACTION_PHP, $this->auth ); + $this->action = new ActionApi( $this->baseUrl . self::ACTION_PHP, $this->auth, null, null, $this->config ); } return $this->action; @@ -72,7 +77,7 @@ public function action(): ActionApi { public function rest(): RestApi { if ( !isset( $this->rest ) ) { // TODO perhaps use the same Tokens object between the 2 APIs - $this->rest = new RestApi( $this->baseUrl . self::REST_PHP, $this->auth, null, new Tokens( $this->action() ) ); + $this->rest = new RestApi( $this->baseUrl . self::REST_PHP, $this->auth, null, new Tokens( $this->action() ), $this->config ); } return $this->rest; diff --git a/src/Guzzle/ClientFactory.php b/src/Guzzle/ClientFactory.php index 435c7be..3216c89 100644 --- a/src/Guzzle/ClientFactory.php +++ b/src/Guzzle/ClientFactory.php @@ -47,7 +47,9 @@ private function newClient(): Client { ]; $this->setUaHeaderFromConfigOrDefault(); $this->setDefaultHandlerIfNotInConfigAlready(); - $this->setMiddlewareFromConfigWithDefaultRetry(); + if( !array_key_exists( 'noretry', $this->config ) ) { + $this->setMiddlewareFromConfigWithDefaultRetry(); + } return new Client( $this->config ); }