-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
48 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
namespace FreezyBee\Httplug\ClientFactory; | ||
|
||
use Http\Client\HttpClient; | ||
use Psr\Http\Client\ClientInterface; | ||
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
|
@@ -14,5 +14,5 @@ interface ClientFactory | |
/** | ||
* @param array<mixed> $config | ||
*/ | ||
public function createClient(array $config = []): HttpClient; | ||
public function createClient(array $config = []): ClientInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,15 @@ | |
namespace FreezyBee\Httplug\ClientFactory; | ||
|
||
use Http\Client\Curl\Client; | ||
use Http\Client\HttpClient; | ||
use LogicException; | ||
use Psr\Http\Client\ClientInterface; | ||
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class CurlFactory implements ClientFactory | ||
{ | ||
public function createClient(array $config = []): HttpClient | ||
public function createClient(array $config = []): ClientInterface | ||
{ | ||
if (!class_exists(Client::class)) { | ||
throw new LogicException('To use the Curl client you need to install the "php-http/curl-client" package.'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,15 @@ | |
namespace FreezyBee\Httplug\ClientFactory; | ||
|
||
use Http\Adapter\Guzzle7\Client; | ||
use Http\Client\HttpClient; | ||
use LogicException; | ||
use Psr\Http\Client\ClientInterface; | ||
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class Guzzle7Factory implements ClientFactory | ||
{ | ||
public function createClient(array $config = []): HttpClient | ||
public function createClient(array $config = []): ClientInterface | ||
{ | ||
if (!class_exists(Client::class)) { | ||
throw new LogicException( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,21 +9,19 @@ | |
use FreezyBee\Httplug\Tracy\MessagePanel; | ||
use FreezyBee\Httplug\Tracy\PluginClientDecorator; | ||
use Http\Client\Common\PluginClient; | ||
use Http\Client\HttpClient; | ||
use Http\Discovery\HttpClientDiscovery; | ||
use Http\Discovery\MessageFactoryDiscovery; | ||
use Http\Discovery\StreamFactoryDiscovery; | ||
use Http\Discovery\UriFactoryDiscovery; | ||
use Http\Message\MessageFactory; | ||
use Http\Message\StreamFactory; | ||
use Http\Message\UriFactory; | ||
use Http\Discovery\Psr17FactoryDiscovery; | ||
use Http\Discovery\Psr18ClientDiscovery; | ||
use InvalidArgumentException; | ||
use Nette\DI\CompilerExtension; | ||
use Nette\DI\ContainerBuilder; | ||
use Nette\DI\Definitions\Definition; | ||
use Nette\DI\Definitions\ServiceDefinition; | ||
use Nette\DI\Definitions\Statement; | ||
use Nette\DI\Helpers; | ||
use Psr\Http\Client\ClientInterface; | ||
use Psr\Http\Message\RequestFactoryInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
use Psr\Http\Message\UriFactoryInterface; | ||
|
||
/** | ||
* @author Jakub Janata <[email protected]> | ||
|
@@ -37,7 +35,7 @@ class HttplugExtension extends CompilerExtension | |
# uses discovery if not specified | ||
'classes' => [ | ||
'client' => null, | ||
'messageFactory' => null, | ||
'requestFactory' => null, | ||
'uriFactory' => null, | ||
'streamFactory' => null | ||
], | ||
|
@@ -56,18 +54,18 @@ class HttplugExtension extends CompilerExtension | |
|
||
/** @var array<string, string> */ | ||
private array $classes = [ | ||
'client' => HttpClient::class, | ||
'messageFactory' => MessageFactory::class, | ||
'uriFactory' => UriFactory::class, | ||
'streamFactory' => StreamFactory::class, | ||
'client' => ClientInterface::class, | ||
'requestFactory' => RequestFactoryInterface::class, | ||
'uriFactory' => UriFactoryInterface::class, | ||
'streamFactory' => StreamFactoryInterface::class, | ||
]; | ||
|
||
/** @var array<string, mixed> */ | ||
private array $factoryClasses = [ | ||
'client' => [HttpClientDiscovery::class, 'find'], | ||
'messageFactory' => [MessageFactoryDiscovery::class, 'find'], | ||
'uriFactory' => [UriFactoryDiscovery::class, 'find'], | ||
'streamFactory' => [StreamFactoryDiscovery::class, 'find'], | ||
'client' => [Psr18ClientDiscovery::class, 'find'], | ||
'requestFactory' => [Psr17FactoryDiscovery::class, 'findRequestFactory'], | ||
'uriFactory' => [Psr17FactoryDiscovery::class, 'findUriFactory'], | ||
'streamFactory' => [Psr17FactoryDiscovery::class, 'findStreamFactory'], | ||
]; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,30 +5,26 @@ | |
namespace FreezyBee\Httplug\Tracy; | ||
|
||
use Http\Client\Common\PluginClient; | ||
use Http\Client\HttpAsyncClient; | ||
use Http\Client\HttpClient; | ||
use Http\Promise\Promise; | ||
use Nette\SmartObject; | ||
use Psr\Http\Client\ClientInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* @author Jakub Janata <[email protected]> | ||
*/ | ||
class PluginClientDecorator implements HttpClient, HttpAsyncClient | ||
class PluginClientDecorator implements ClientInterface | ||
{ | ||
use SmartObject; | ||
|
||
private PluginClient $pluginClient; | ||
private TracyPlugin $tracyPlugin; | ||
|
||
/** | ||
* PluginClientDecorator constructor. | ||
* @param HttpClient|HttpAsyncClient $client | ||
* @param array<mixed> $plugins | ||
* @param array<mixed> $options | ||
*/ | ||
public function __construct($client, array $plugins = [], array $options = []) | ||
public function __construct(ClientInterface $client, array $plugins = [], array $options = []) | ||
{ | ||
$plugins[] = $this->tracyPlugin = new TracyPlugin(); | ||
$this->pluginClient = new PluginClient($client, $plugins, $options); | ||
|
@@ -51,13 +47,4 @@ public function sendRequest(RequestInterface $request): ResponseInterface | |
|
||
return $response; | ||
} | ||
|
||
/** | ||
* @param RequestInterface $request | ||
* @return Promise | ||
*/ | ||
public function sendAsyncRequest(RequestInterface $request): Promise | ||
{ | ||
return $this->pluginClient->sendAsyncRequest($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,9 @@ | |
namespace FreezyBee\Httplug\Tests\Utils; | ||
|
||
use Http\Client\Common\PluginClient; | ||
use Http\Message\MessageFactory; | ||
use Nette\Application\Responses\TextResponse; | ||
use Nette\Application\UI\Presenter; | ||
use Psr\Http\Message\RequestFactoryInterface; | ||
|
||
/** | ||
* @author Jakub Janata <[email protected]> | ||
|
@@ -26,8 +26,8 @@ public function actionDefault(): void | |
/** @var PluginClient $pluginClient */ | ||
$pluginClient = $this->context->getService('httplug.client.test5'); | ||
|
||
/** @var MessageFactory $factory */ | ||
$factory = $this->context->getByType(MessageFactory::class); | ||
/** @var RequestFactoryInterface $factory */ | ||
$factory = $this->context->getByType(RequestFactoryInterface::class); | ||
$request = $factory->createRequest('GET', '/test'); | ||
|
||
$pluginClient->sendRequest($request); | ||
|