Skip to content

Commit

Permalink
Merge pull request #14 from maciej-sz/2.0.2-updates
Browse files Browse the repository at this point in the history
2.0.2 updates
  • Loading branch information
maciej-sz authored May 8, 2023
2 parents 15420c1 + 081803c commit 7734e5e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ Gold rate from 2013-12-31 is 116.890000

## Using cache

> Note that a library implementing PSR-6 has to be provided in order to use the caching
abilities.
_Note that a library implementing PSR-6 has to be provided in order to use the caching
abilities._

The `CachedTransport` class is a proxy for all other transport implementations.
This transport has to be backed by another transport, as it relies on it to
Expand Down Expand Up @@ -370,15 +370,15 @@ $took = $end - $start;
printf('Getting the rate took %F ms', $took * 1000);
```

### Using different transport
## Using custom transport

The library uses Symfony HTTP Client and Guzzle as default transports.
If those packages are not available then it falls back to the `file_get_contents`
method. This may not be ideal in some situations. Especially when there is no access
to HTTP client packages as may be the case when using PHP version prior to 8.0.

In such cases it is suggested to use different transport. It can be achieved
by replacing the TransportFactory of the NbpClient with your own implementation.
by replacing the `TransportFactory` of the `NbpClient` with your own implementation.

```php
$customTransportFactory = new class() implements TransportFactory {
Expand Down
15 changes: 15 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,20 @@
"suggest": {
"psr/cache": "Allows local cache",
"symfony/http-foundation": "Symfony HTTP Transport layer"
},
"scripts": {
"test": "vendor/bin/phpunit -vv --testsuite unit,functional,integration",
"test-all": "vendor/bin/phpunit -vv --testsuite unit,functional,integration,e2e",
"test-coverage": "php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html var/coverage/html-report -vv --testsuite unit,functional,integration",
"cs-check": "vendor/bin/php-cs-fixer --config=./.php-cs-fixer.dist.php fix --dry-run --diff --allow-risky=yes",
"phpstan-analyse": "vendor/bin/phpstan",
"analyse": [
"@cs-check",
"@phpstan-analyse"
],
"pre-commit-checks": [
"@analyse",
"@test-all"
]
}
}
4 changes: 2 additions & 2 deletions src/Shared/Infrastructure/Transport/HttpTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function create(string $baseUri): Transport

public function tryCreateSymfonyTransport(string $baseUri): ?Transport
{
if (!class_exists(SymfonyHttpClient::class)) {
if (PHP_VERSION_ID < 80100 || !class_exists(SymfonyHttpClient::class)) {
return null;
}

Expand All @@ -29,7 +29,7 @@ public function tryCreateSymfonyTransport(string $baseUri): ?Transport

public function tryCreateGuzzleTransport(string $baseUri): ?Transport
{
if (!class_exists(GuzzleHttpClient::class)) {
if (PHP_VERSION_ID < 70205 || !class_exists(GuzzleHttpClient::class)) {
return null;
}

Expand Down

0 comments on commit 7734e5e

Please sign in to comment.