Skip to content

Commit

Permalink
Merge 1f51491 into 5c3109a
Browse files Browse the repository at this point in the history
  • Loading branch information
tidal authored Jun 28, 2022
2 parents 5c3109a + 1f51491 commit a784918
Show file tree
Hide file tree
Showing 34 changed files with 1,303 additions and 0 deletions.
89 changes: 89 additions & 0 deletions src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php
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 src/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php
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 src/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php
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 src/SDK/Common/Adapter/HttpDiscovery/PsrClientResolver.php
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();
}
}
13 changes: 13 additions & 0 deletions src/SDK/Common/Http/DependencyResolverInterface.php
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
{
}
15 changes: 15 additions & 0 deletions src/SDK/Common/Http/HttpPlug/Client/ResolverInterface.php
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;
}
12 changes: 12 additions & 0 deletions src/SDK/Common/Http/Psr/Client/ResolverInterface.php
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 src/SDK/Common/Http/Psr/Message/FactoryDecoratorInterface.php
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;
}
25 changes: 25 additions & 0 deletions src/SDK/Common/Http/Psr/Message/FactoryDecoratorTrait.php
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 src/SDK/Common/Http/Psr/Message/FactoryResolverInterface.php
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;
}
Loading

0 comments on commit a784918

Please sign in to comment.