Skip to content

Commit

Permalink
Use static function baseUri (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jenky authored Jul 5, 2023
1 parent 048005b commit e2d9e76
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/advanced/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ final class Github implements ConnectorInterface
$this->version = $version;
}

public function baseUri(): ?string
public static function baseUri(): ?string
{
return 'https://api.github.com';
}

protected function defaultClient(): ClientInterface
{
return new Client([
'base_uri' => $this->baseUri(),
'base_uri' => static::baseUri(),
'headers' => array_filter([
'Accept' => 'application/vnd.github+json',
'Authorization' => 'Bearer '.trim($this->token),
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/connectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class MyConnector implements ConnectorInterface
$this->token = $token;
}

public function baseUri(): ?string
public static function baseUri(): ?string
{
return 'https://my-service.api';
}
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ First, you should [install the package](./installation.md).

In order to send a request. You should create a `Connector` class that implements `Jenky\Atlas\Contracts\ConnectorInterface` interface and add `Jenky\Atlas\Traits\ConnectorTrait` trait to the connector to fullfil the contract interface.

Additionally, you can set the request base URI by utilizing the `baseUri` method. If a relative URI is specified in the request `endpoint` method, the connector will merge the base URI with the relative URI, following the guidelines outlined in [RFC 3986, section 5.2](https://www.rfc-editor.org/rfc/rfc3986#section-5.2).
Additionally, you can set the request base URI by utilizing the `baseUri` static method. If a relative URI is specified in the request `endpoint` method, the connector will merge the base URI with the relative URI, following the guidelines outlined in [RFC 3986, section 5.2](https://www.rfc-editor.org/rfc/rfc3986#section-5.2).

```php
<?php
Expand All @@ -22,7 +22,7 @@ final class Connector implements ConnectorInterface
{
use ConnectorTrait;

public function baseUri(): ?string
public static function baseUri(): ?string
{
return 'https://mydomain.com/api';
}
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/ConnectorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait ConnectorTrait
/**
* Get the base uri for the HTTP client.
*/
public function baseUri(): ?string
public static function baseUri(): ?string
{
return null;
}
Expand All @@ -33,7 +33,7 @@ public function baseUri(): ?string
public function send(Request $request): Response
{
$response = $this->sendRequest(
Util::request($request, $this->baseUri())
Util::request($request, static::baseUri())
);

return new Response($response, $request->decoder());
Expand Down
2 changes: 1 addition & 1 deletion tests/Services/HTTPBin/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Connector implements ConnectorInterface
use ConnectorTrait;
use Retryable;

public function baseUri(): ?string
public static function baseUri(): ?string
{
return 'https://httpbin.org';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Services/PostmanEcho/EchoConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class EchoConnector implements EchoConnectorInterface
{
use ConnectorTrait;

public function baseUri(): ?string
public static function baseUri(): ?string
{
return 'https://postman-echo.com/';
}
Expand Down

0 comments on commit e2d9e76

Please sign in to comment.