-
Notifications
You must be signed in to change notification settings - Fork 188
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
34 changed files
with
1,303 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\Adapter\HttpDiscovery; | ||
|
||
use Http\Client\HttpAsyncClient; | ||
use Http\Client\HttpClient; | ||
use OpenTelemetry\SDK\Common\Http\DependencyResolverInterface; | ||
use OpenTelemetry\SDK\Common\Http\HttpPlug\Client\ResolverInterface as HttpPlugClientResolverInterface; | ||
use OpenTelemetry\SDK\Common\Http\Psr\Client\ResolverInterface as PsrClientResolverInterface; | ||
use OpenTelemetry\SDK\Common\Http\Psr\Message\FactoryResolverInterface as MessageFactoryResolverInterface; | ||
use Psr\Http\Client\ClientInterface; | ||
use Psr\Http\Message\RequestFactoryInterface; | ||
use Psr\Http\Message\ResponseFactoryInterface; | ||
use Psr\Http\Message\ServerRequestFactoryInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
use Psr\Http\Message\UploadedFileFactoryInterface; | ||
use Psr\Http\Message\UriFactoryInterface; | ||
|
||
final class DependencyResolver implements DependencyResolverInterface | ||
{ | ||
private MessageFactoryResolverInterface $messageFactoryResolver; | ||
private PsrClientResolverInterface $psrClientResolver; | ||
private HttpPlugClientResolverInterface $httpPlugClientResolver; | ||
|
||
public function __construct( | ||
?MessageFactoryResolverInterface $messageFactoryResolver = null, | ||
?PsrClientResolverInterface $psrClientResolver = null, | ||
?HttpPlugClientResolverInterface $httpPlugClientResolver = null | ||
) { | ||
$this->messageFactoryResolver = $messageFactoryResolver ?? MessageFactoryResolver::create(); | ||
$this->psrClientResolver = $psrClientResolver ?? PsrClientResolver::create(); | ||
$this->httpPlugClientResolver = $httpPlugClientResolver ?? HttpPlugClientResolver::create(); | ||
} | ||
|
||
public static function create( | ||
?MessageFactoryResolverInterface $messageFactoryResolver = null, | ||
?PsrClientResolverInterface $psrClientResolver = null, | ||
?HttpPlugClientResolverInterface $httpPlugClientResolver = null | ||
): self { | ||
return new self($messageFactoryResolver, $psrClientResolver, $httpPlugClientResolver); | ||
} | ||
|
||
public function resolveRequestFactory(): RequestFactoryInterface | ||
{ | ||
return $this->messageFactoryResolver->resolveRequestFactory(); | ||
} | ||
|
||
public function resolveResponseFactory(): ResponseFactoryInterface | ||
{ | ||
return $this->messageFactoryResolver->resolveResponseFactory(); | ||
} | ||
|
||
public function resolveServerRequestFactory(): ServerRequestFactoryInterface | ||
{ | ||
return $this->messageFactoryResolver->resolveServerRequestFactory(); | ||
} | ||
|
||
public function resolveStreamFactory(): StreamFactoryInterface | ||
{ | ||
return $this->messageFactoryResolver->resolveStreamFactory(); | ||
} | ||
|
||
public function resolveUploadedFileFactory(): UploadedFileFactoryInterface | ||
{ | ||
return $this->messageFactoryResolver->resolveUploadedFileFactory(); | ||
} | ||
|
||
public function resolveUriFactory(): UriFactoryInterface | ||
{ | ||
return $this->messageFactoryResolver->resolveUriFactory(); | ||
} | ||
|
||
public function resolveHttpPlugClient(): HttpClient | ||
{ | ||
return $this->httpPlugClientResolver->resolveHttpPlugClient(); | ||
} | ||
|
||
public function resolveHttpPlugAsyncClient(): HttpAsyncClient | ||
{ | ||
return $this->httpPlugClientResolver->resolveHttpPlugAsyncClient(); | ||
} | ||
|
||
public function resolvePsrClient(): ClientInterface | ||
{ | ||
return $this->psrClientResolver->resolvePsrClient(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\Adapter\HttpDiscovery; | ||
|
||
use Http\Client\HttpAsyncClient; | ||
use Http\Client\HttpClient; | ||
use Http\Discovery\HttpAsyncClientDiscovery; | ||
use Http\Discovery\HttpClientDiscovery; | ||
use OpenTelemetry\SDK\Common\Http\HttpPlug\Client\ResolverInterface; | ||
|
||
final class HttpPlugClientResolver implements ResolverInterface | ||
{ | ||
private ?HttpClient $httpClient; | ||
private ?HttpAsyncClient $httpAsyncClient; | ||
|
||
public function __construct(?HttpClient $httpClient = null, ?HttpAsyncClient $httpAsyncClient = null) | ||
{ | ||
$this->httpClient = $httpClient; | ||
$this->httpAsyncClient = $httpAsyncClient; | ||
} | ||
|
||
public static function create(?HttpClient $httpClient = null, ?HttpAsyncClient $httpAsyncClient = null): self | ||
{ | ||
return new self($httpClient, $httpAsyncClient); | ||
} | ||
|
||
public function resolveHttpPlugClient(): HttpClient | ||
{ | ||
return $this->httpClient ??= HttpClientDiscovery::find(); | ||
} | ||
|
||
public function resolveHttpPlugAsyncClient(): HttpAsyncClient | ||
{ | ||
return $this->httpAsyncClient ??= HttpAsyncClientDiscovery::find(); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
src/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\Adapter\HttpDiscovery; | ||
|
||
use Http\Discovery\Psr17FactoryDiscovery; | ||
use OpenTelemetry\SDK\Common\Http\Psr\Message\FactoryResolverInterface; | ||
use Psr\Http\Message\RequestFactoryInterface; | ||
use Psr\Http\Message\ResponseFactoryInterface; | ||
use Psr\Http\Message\ServerRequestFactoryInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
use Psr\Http\Message\UploadedFileFactoryInterface; | ||
use Psr\Http\Message\UriFactoryInterface; | ||
|
||
final class MessageFactoryResolver implements FactoryResolverInterface | ||
{ | ||
private ?RequestFactoryInterface $requestFactory; | ||
private ?ResponseFactoryInterface $responseFactory; | ||
private ?ServerRequestFactoryInterface $serverRequestFactory; | ||
private ?StreamFactoryInterface $streamFactory; | ||
private ?UploadedFileFactoryInterface $uploadedFileFactory; | ||
private ?UriFactoryInterface $uriFactory; | ||
|
||
public function __construct( | ||
?RequestFactoryInterface $requestFactory = null, | ||
?ResponseFactoryInterface $responseFactory = null, | ||
?ServerRequestFactoryInterface $serverRequestFactory = null, | ||
?StreamFactoryInterface $streamFactory = null, | ||
?UploadedFileFactoryInterface $uploadedFileFactory = null, | ||
?UriFactoryInterface $uriFactory = null | ||
) { | ||
$this->requestFactory = $requestFactory; | ||
$this->responseFactory = $responseFactory; | ||
$this->serverRequestFactory = $serverRequestFactory; | ||
$this->streamFactory = $streamFactory; | ||
$this->uploadedFileFactory = $uploadedFileFactory; | ||
$this->uriFactory = $uriFactory; | ||
} | ||
|
||
public static function create( | ||
?RequestFactoryInterface $requestFactory = null, | ||
?ResponseFactoryInterface $responseFactory = null, | ||
?ServerRequestFactoryInterface $serverRequestFactory = null, | ||
?StreamFactoryInterface $streamFactory = null, | ||
?UploadedFileFactoryInterface $uploadedFileFactory = null, | ||
?UriFactoryInterface $uriFactory = null | ||
): self { | ||
return new self( | ||
$requestFactory, | ||
$responseFactory, | ||
$serverRequestFactory, | ||
$streamFactory, | ||
$uploadedFileFactory, | ||
$uriFactory | ||
); | ||
} | ||
|
||
public function resolveRequestFactory(): RequestFactoryInterface | ||
{ | ||
return $this->requestFactory ??= Psr17FactoryDiscovery::findRequestFactory(); | ||
} | ||
|
||
public function resolveResponseFactory(): ResponseFactoryInterface | ||
{ | ||
return $this->responseFactory ??= Psr17FactoryDiscovery::findResponseFactory(); | ||
} | ||
|
||
public function resolveServerRequestFactory(): ServerRequestFactoryInterface | ||
{ | ||
return $this->serverRequestFactory ??= Psr17FactoryDiscovery::findServerRequestFactory(); | ||
} | ||
|
||
public function resolveStreamFactory(): StreamFactoryInterface | ||
{ | ||
return $this->streamFactory ??= Psr17FactoryDiscovery::findStreamFactory(); | ||
} | ||
|
||
public function resolveUploadedFileFactory(): UploadedFileFactoryInterface | ||
{ | ||
return $this->uploadedFileFactory ??= Psr17FactoryDiscovery::findUploadedFileFactory(); | ||
} | ||
|
||
public function resolveUriFactory(): UriFactoryInterface | ||
{ | ||
return $this->uriFactory ??= Psr17FactoryDiscovery::findUriFactory(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/SDK/Common/Adapter/HttpDiscovery/PsrClientResolver.php
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\Adapter\HttpDiscovery; | ||
|
||
use Http\Discovery\Psr18ClientDiscovery; | ||
use OpenTelemetry\SDK\Common\Http\Psr\Client\ResolverInterface; | ||
use Psr\Http\Client\ClientInterface; | ||
|
||
final class PsrClientResolver implements ResolverInterface | ||
{ | ||
private ?ClientInterface $client; | ||
|
||
public function __construct(?ClientInterface $client = null) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
public static function create(?ClientInterface $client = null): self | ||
{ | ||
return new self($client); | ||
} | ||
|
||
public function resolvePsrClient(): ClientInterface | ||
{ | ||
return $this->client ??= Psr18ClientDiscovery::find(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\Http; | ||
|
||
use OpenTelemetry\SDK\Common\Http\HttpPlug\Client\ResolverInterface as HttpPlugClientResolverInterface; | ||
use OpenTelemetry\SDK\Common\Http\Psr\Client\ResolverInterface as PsrClientResolverInterface; | ||
use OpenTelemetry\SDK\Common\Http\Psr\Message\FactoryResolverInterface; | ||
|
||
interface DependencyResolverInterface extends FactoryResolverInterface, PsrClientResolverInterface, HttpPlugClientResolverInterface | ||
{ | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\Http\HttpPlug\Client; | ||
|
||
use Http\Client\HttpAsyncClient; | ||
use Http\Client\HttpClient; | ||
|
||
interface ResolverInterface | ||
{ | ||
public function resolveHttpPlugClient(): HttpClient; | ||
|
||
public function resolveHttpPlugAsyncClient(): HttpAsyncClient; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\Http\Psr\Client; | ||
|
||
use Psr\Http\Client\ClientInterface; | ||
|
||
interface ResolverInterface | ||
{ | ||
public function resolvePsrClient(): ClientInterface; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/SDK/Common/Http/Psr/Message/FactoryDecoratorInterface.php
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\Http\Psr\Message; | ||
|
||
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; | ||
|
||
interface FactoryDecoratorInterface | ||
{ | ||
public function getPropagator(): TextMapPropagatorInterface; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\Http\Psr\Message; | ||
|
||
use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; | ||
use Psr\Http\Message\RequestFactoryInterface; | ||
use Psr\Http\Message\ResponseFactoryInterface; | ||
use Psr\Http\Message\ServerRequestFactoryInterface; | ||
|
||
trait FactoryDecoratorTrait | ||
{ | ||
private TextMapPropagatorInterface $propagator; | ||
|
||
/** | ||
* @var RequestFactoryInterface|ServerRequestFactoryInterface|ResponseFactoryInterface | ||
*/ | ||
private $decorated; | ||
|
||
public function getPropagator(): TextMapPropagatorInterface | ||
{ | ||
return $this->propagator; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/SDK/Common/Http/Psr/Message/FactoryResolverInterface.php
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\SDK\Common\Http\Psr\Message; | ||
|
||
use Psr\Http\Message\RequestFactoryInterface; | ||
use Psr\Http\Message\ResponseFactoryInterface; | ||
use Psr\Http\Message\ServerRequestFactoryInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
use Psr\Http\Message\UploadedFileFactoryInterface; | ||
use Psr\Http\Message\UriFactoryInterface; | ||
|
||
interface FactoryResolverInterface | ||
{ | ||
public function resolveRequestFactory(): RequestFactoryInterface; | ||
public function resolveResponseFactory(): ResponseFactoryInterface; | ||
public function resolveServerRequestFactory(): ServerRequestFactoryInterface; | ||
public function resolveStreamFactory(): StreamFactoryInterface; | ||
public function resolveUploadedFileFactory(): UploadedFileFactoryInterface; | ||
public function resolveUriFactory(): UriFactoryInterface; | ||
} |
Oops, something went wrong.