Skip to content

Commit

Permalink
prefer psr 17 factory discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed May 21, 2023
1 parent 7d046f4 commit 3d7c8c6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Change Log

## 1.5.2 - 2023-05-23
## 1.6.0 - 2023-05-21

### Fixed

- We actually did fallback to the legacy message factory discovery so 1.5.2 is broken.
Changed to use PSR 17 factory discovery.
If you allow the composer plugin of `php-http/discovery`, things will work out of the box.
When disabled and you do not have a PSR-17 factory installed, you will need to explicitly require one, e.g. `nyholm/psr7`.

## 1.5.2 - 2023-05-17

**Broken, use 1.6.0 instead**

### Removed

Expand Down
17 changes: 16 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Http\Client\Exception;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Http\Discovery\Exception\NotFoundException;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Message\RequestMatcher;
Expand Down Expand Up @@ -73,7 +74,21 @@ public function __construct($responseFactory = null)
);
}

$this->responseFactory = $responseFactory ?: Psr17FactoryDiscovery::findResponseFactory();
if ($responseFactory) {
$this->responseFactory = $responseFactory;

return;
}
try {
$this->responseFactory = Psr17FactoryDiscovery::findResponseFactory();
} catch (NotFoundException $notFoundException) {
try {
$this->responseFactory = MessageFactoryDiscovery::find();
} catch (NotFoundException $e) {
// throw the psr-17 exception to make people install the new way and not the old
throw $notFoundException;
}
}
}

/**
Expand Down

0 comments on commit 3d7c8c6

Please sign in to comment.