-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from FLUX-SE/fix-psr-http-message-factory
Fix psr http message factory
- Loading branch information
Showing
7 changed files
with
177 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
services: | ||
app.payum.http_client: | ||
public: true | ||
class: Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\HttpClient\HttpClient | ||
arguments: | ||
$client: '@Psr\Http\Client\ClientInterface' | ||
app.payum.message_factory: | ||
public: true | ||
class: Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\Factory\MessageFactory | ||
arguments: | ||
$requestFactory: '@Psr\Http\Client\ClientInterface' | ||
$responseFactory: '@nyholm.psr17.factory' | ||
$streamFactory: '@Psr\Http\Client\ClientInterface' | ||
|
||
nyholm.psr17.factory: | ||
public: true | ||
class: Nyholm\Psr7\Factory\Psr17Factory | ||
|
||
payum: | ||
gateways: | ||
core: | ||
httplug.message_factory: '@app.payum.message_factory' | ||
httplug.stream_factory: '@app.payum.message_factory' | ||
httplug.client: '@Symfony\Component\HttpClient\HttplugClient' | ||
payum.http_client: '@app.payum.http_client' |
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 @@ | ||
services: | ||
app.payum.http_client: | ||
public: true | ||
class: Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\HttpClient\HttpClient | ||
arguments: | ||
$client: '@Psr\Http\Client\ClientInterface' | ||
app.payum.message_factory: | ||
public: true | ||
class: Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\Factory\MessageFactory | ||
arguments: | ||
$requestFactory: '@Psr\Http\Client\ClientInterface' | ||
$responseFactory: '@nyholm.psr17.factory' | ||
$streamFactory: '@Psr\Http\Client\ClientInterface' | ||
|
||
nyholm.psr17.factory: | ||
public: true | ||
class: Nyholm\Psr7\Factory\Psr17Factory | ||
|
||
framework: | ||
http_client: | ||
enabled: true # require to alias the service Psr\Http\Client\ClientInterface | ||
|
||
payum: | ||
gateways: | ||
core: | ||
httplug.message_factory: '@app.payum.message_factory' | ||
httplug.stream_factory: '@app.payum.message_factory' | ||
httplug.client: '@Symfony\Component\HttpClient\HttplugClient' | ||
payum.http_client: '@app.payum.http_client' |
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 @@ | ||
services: | ||
app.payum.http_client: | ||
public: true | ||
class: Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\HttpClient\HttpClient | ||
arguments: | ||
$client: '@Psr\Http\Client\ClientInterface' | ||
app.payum.message_factory: | ||
public: true | ||
class: Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\Factory\MessageFactory | ||
arguments: | ||
$requestFactory: '@Psr\Http\Client\ClientInterface' | ||
$responseFactory: '@nyholm.psr17.factory' | ||
$streamFactory: '@Psr\Http\Client\ClientInterface' | ||
|
||
nyholm.psr17.factory: | ||
public: true | ||
class: Nyholm\Psr7\Factory\Psr17Factory | ||
|
||
payum: | ||
gateways: | ||
core: | ||
httplug.message_factory: '@app.payum.message_factory' | ||
httplug.stream_factory: '@app.payum.message_factory' | ||
httplug.client: '@Symfony\Component\HttpClient\HttplugClient' | ||
payum.http_client: '@app.payum.http_client' |
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,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\Factory; | ||
|
||
use Psr\Http\Message\RequestFactoryInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseFactoryInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\StreamFactoryInterface; | ||
use Psr\Http\Message\StreamInterface; | ||
|
||
class MessageFactory implements RequestFactoryInterface, ResponseFactoryInterface, StreamFactoryInterface | ||
{ | ||
/** @var RequestFactoryInterface */ | ||
private $requestFactory; | ||
|
||
/** @var ResponseFactoryInterface */ | ||
private $responseFactory; | ||
|
||
/** @var StreamFactoryInterface */ | ||
private $streamFactory; | ||
|
||
public function __construct( | ||
RequestFactoryInterface $requestFactory, | ||
ResponseFactoryInterface $responseFactory, | ||
StreamFactoryInterface $streamFactory | ||
) { | ||
$this->requestFactory = $requestFactory; | ||
$this->responseFactory = $responseFactory; | ||
$this->streamFactory = $streamFactory; | ||
} | ||
|
||
public function createRequest(string $method, $uri): RequestInterface | ||
{ | ||
return $this->requestFactory->createRequest($method, $uri); | ||
} | ||
|
||
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface | ||
{ | ||
return $this->responseFactory->createResponse($code, $reasonPhrase); | ||
} | ||
|
||
|
||
public function createStream(string $content = ''): StreamInterface | ||
{ | ||
return $this->streamFactory->createStream($content); | ||
} | ||
|
||
public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface | ||
{ | ||
return $this->streamFactory->createStreamFromFile($filename, $mode); | ||
} | ||
|
||
public function createStreamFromResource($resource): StreamInterface | ||
{ | ||
return $this->streamFactory->createStreamFromResource($resource); | ||
} | ||
} |
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 Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\HttpClient; | ||
|
||
use Payum\Core\HttpClientInterface; | ||
use Psr\Http\Client\ClientInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
final class HttpClient implements HttpClientInterface | ||
{ | ||
/** @var ClientInterface */ | ||
private $client; | ||
public function __construct(ClientInterface $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
public function send(RequestInterface $request): ResponseInterface | ||
{ | ||
return $this->client->sendRequest($request); | ||
} | ||
} |