Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psr17 Stream Factory #54

Merged
merged 9 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ on:
push:
branches:
- 2.x
- 3.x
pull_request:
branches:
- 2.x
- 3.x

jobs:
test:
Expand All @@ -18,10 +20,11 @@ jobs:
fail-fast: false
matrix:
php-version:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
composer-version:
- "2"
steps:
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
"type": "library",
"keywords": ["payment"],
"require": {
"php": "^7.2 || ^8.0",
"php": "^7.4 || ^8.0",
"psr/http-message": "^1.0",
"psr/http-client-implementation": "^1.0",
"php-http/message": "^1.6",
"php-http/httplug": "^1.0 || ^2.0",
"php-http/discovery": "^1.17",
"eloquent/enumeration": "^5.1",
"jms/serializer": "^1.8 || ^3.0"
"jms/serializer": "^1.8 || ^3.0",
"doctrine/annotations": "^2.0"
},
"require-dev": {
"guzzlehttp/guzzle": "^7",
"php-http/guzzle7-adapter": "^1",
"phpunit/phpunit": ">=5 <9",
"symfony/yaml": "^2.0",
"symfony/filesystem": "^3.1",
Expand Down
8 changes: 0 additions & 8 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ parameters:
count: 2
path: src/Exceptions/VippsException.php

-
message: """
#^Call to deprecated method getOrderStatus\\(\\) of class zaporylie\\\\Vipps\\\\Api\\\\PaymentInterface\\:
Get order status was deprecated and can be removed in version 3\\.0\\.$#
"""
count: 1
path: test/Integration/Api/PaymentsTest.php

-
message: "#^Call to an undefined static method zaporylie\\\\Vipps\\\\Endpoint\\:\\:error\\(\\)\\.$#"
count: 1
Expand Down
17 changes: 17 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Http\Discovery\Psr18ClientDiscovery;
use Psr\Http\Client\ClientInterface as HttpClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use zaporylie\Vipps\Authentication\TokenMemoryCacheStorage;
use zaporylie\Vipps\Authentication\TokenStorageInterface;
use zaporylie\Vipps\Exceptions\Client\InvalidArgumentException;
Expand All @@ -32,6 +33,11 @@ class Client implements ClientInterface
*/
protected $requestFactory;

/**
* @var \Psr\Http\Message\StreamFactoryInterface
*/
protected StreamFactoryInterface $streamFactory;

/**
* @var string
*/
Expand Down Expand Up @@ -193,6 +199,17 @@ public function getRequestFactory(): RequestFactoryInterface
return $this->requestFactory;
}

/**
* {@inheritdoc}
*/
public function getStreamFactory(): StreamFactoryInterface
{
if (!isset($this->streamFactory)) {
$this->streamFactory = Psr17FactoryDiscovery::findStreamFactory();
}
return $this->streamFactory;
}

/**
* Use this static method to get default HTTP Client.
*
Expand Down
10 changes: 9 additions & 1 deletion src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Psr\Http\Client\ClientInterface as HttpClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use zaporylie\Vipps\Authentication\TokenStorageInterface;

interface ClientInterface
Expand Down Expand Up @@ -69,9 +70,16 @@ public function getHttpClient() : HttpClientInterface;
public function setHttpClient(?HttpClientInterface $httpClient);

/**
* Gets messageFactory value.
* Gets requestFactoru value.
*
* @return \Psr\Http\Message\RequestFactoryInterface
*/
public function getRequestFactory(): RequestFactoryInterface;

/**
* Gets streamFactory value.
*
* @return \Psr\Http\Message\StreamFactoryInterface
*/
public function getStreamFactory(): StreamFactoryInterface;
}
2 changes: 1 addition & 1 deletion src/Resource/Authorization/GetToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GetToken extends ResourceBase
/**
* @var string
*/
protected $path = '/accessToken/get';
protected $path = '/accesstoken/get';

/**
* GetToken constructor.
Expand Down
14 changes: 8 additions & 6 deletions src/Resource/ResourceBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

use Doctrine\Common\Annotations\AnnotationRegistry;
use Http\Client\Exception\HttpException;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use JMS\Serializer\SerializerBuilder;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
Expand Down Expand Up @@ -206,12 +204,16 @@ protected function handleRequest(RequestInterface $request)
*/
protected function getRequest()
{
return $this->app->getClient()->getRequestFactory()->createRequest(
$request = $this->app->getClient()->getRequestFactory()->createRequest(
$this->getMethod(),
$this->getUri($this->getPath()),
$this->getHeaders(),
$this->getBody()
$this->getUri($this->getPath())
);
$body = $this->app->getClient()->getStreamFactory()->createStream($this->getBody());
$request = $request->withBody($body);
foreach ($this->getHeaders() as $header => $value) {
$request = $request->withAddedHeader($header, $value);
}
return $request;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/Resource/Authorization/GetTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testMethod()
*/
public function testPath()
{
$this->assertEquals('/accessToken/get', $this->resource->getPath());
$this->assertEquals('/accesstoken/get', $this->resource->getPath());
}

/**
Expand Down
Loading