Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ git tag v<x.y.z>
git push --tag
```
4. Go on release page: https://github.com/upsun/upsun-sdk-php/releases
7. create a new release based on the previously created tag (Do not forget to autogenerate description in the form)
8. check publishing action status: https://github.com/upsun/upsun-sdk-php/actions
9. check new release version on https://packagist.org/packages/upsun/upsun-sdk-php
5. create a new release based on the previously created tag (Do not forget to autogenerate description in the form)
6. check publishing action status: https://github.com/upsun/upsun-sdk-php/actions
7. check new release version on https://packagist.org/packages/upsun/upsun-sdk-php

## Tests

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
"php-http/client-common": "^2.4",
"php-http/discovery": "^1.14",
"php-http/httplug": "^2.2",
"symfony/http-client": "^6.3|^7",
"psr/http-client-implementation": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-factory-implementation": "^1.0",
"psr/http-message": "^1.0",
"nyholm/psr7": "^1.8"
},
"suggest": {
"symfony/http-client": "Install a PSR-18 HTTP client implementation if your application does not already provide one"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.89",
"guzzlehttp/guzzle": "^7.0",
Expand Down
9 changes: 4 additions & 5 deletions src/UpsunClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Upsun;

use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Psr\Http\Client\ClientInterface;
use Symfony\Component\HttpClient\Psr18Client;
use Upsun\Api\AddOnsApi;
use Upsun\Api\ApiConfiguration;
use Upsun\Api\ApiTokensApi;
Expand Down Expand Up @@ -145,18 +145,17 @@ class UpsunClient

public WorkersTask $workers;

public function __construct(protected UpsunConfig $upsunConfig)
public function __construct(protected UpsunConfig $upsunConfig, ?ClientInterface $apiClient = null)
{
$this->apiConfig = ApiConfiguration::getDefaultConfiguration()
->setHost(host: $this->upsunConfig->base_url);

// Symfony HTTP client compatible PSR-18
$this->apiClient = new Psr18Client();
$this->apiClient = $apiClient ?? Psr18ClientDiscovery::find();

$requestFactory = Psr17FactoryDiscovery::findRequestFactory();

$this->auth = new OAuthProvider(
httpClient: $this->apiClient, // Symfony PSR-18 client
httpClient: $this->apiClient,
requestFactory: $requestFactory,
tokenEndpoint: $this->upsunConfig->auth_url . "/" . $this->upsunConfig->token_endpoint,
clientId: $this->upsunConfig->clientId,
Expand Down
20 changes: 20 additions & 0 deletions templates/php/README.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ Contributions are welcome!<br>
Please open a [pull request](https://github.com/{{composerPackageName}}/compare) or an [issue](https://github.com/{{composerPackageName}}/issues/new)
for any improvements, bug fixes, or new features.

## Publishing
To generate a new version of the Upsun SDK PHP and automatically publish it on https://packagist.org

1. update your local
```bash
git fetch
git checkout main
git pull
```
2. check existing tags on https://github.com/upsun/upsun-sdk-php/tags
3. create a new tag from your local
```bash
git tag v<x.y.z>
git push --tag
```
4. Go on release page: https://github.com/upsun/upsun-sdk-php/releases
5. create a new release based on the previously created tag (Do not forget to autogenerate description in the form)
6. check publishing action status: https://github.com/upsun/upsun-sdk-php/actions
7. check new release version on https://packagist.org/packages/upsun/upsun-sdk-php

## Tests

To run the tests, use:
Expand Down
4 changes: 3 additions & 1 deletion templates/php/libraries/psr-18/composer.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
"php-http/client-common": "^2.4",
"php-http/discovery": "^1.14",
"php-http/httplug": "^2.2",
"symfony/http-client": "^6.3|^7",
"psr/http-client-implementation": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-factory-implementation": "^1.0",
"psr/http-message": "^1.0",
"nyholm/psr7": "^1.8"
},
"suggest": {
"symfony/http-client": "Install a PSR-18 HTTP client implementation if your application does not already provide one"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.89",
"guzzlehttp/guzzle": "^7.0",
Expand Down
16 changes: 16 additions & 0 deletions tests/UpsunClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ public function testConstructorInitializesHttpClient()
$this->assertInstanceOf(ClientInterface::class, $this->upsunClient->apiClient);
}

public function testConstructorUsesInjectedHttpClient()
{
$customConfig = new UpsunConfig(
base_url: 'https://api.upsun.com',
auth_url: 'https://auth.upsun.com',
apiToken: 'test-api-token',
token_endpoint: 'oauth2/token',
clientId: 'test-client-id'
);

$apiClient = $this->createMock(ClientInterface::class);
$upsunClient = new UpsunClient($customConfig, $apiClient);

$this->assertSame($apiClient, $upsunClient->apiClient);
}

public function testConstructorInitializesOAuthProvider()
{
$this->assertInstanceOf(OAuthProvider::class, $this->upsunClient->auth);
Expand Down