Skip to content

Commit

Permalink
update to php 8.3 - refactoring, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Eroslaev committed Sep 12, 2024
1 parent 93ebaa8 commit 4009cfa
Show file tree
Hide file tree
Showing 148 changed files with 1,948 additions and 2,098 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2015-2020 Virgil Security Inc.
Copyright (C) 2015-2024 Virgil Security Inc.

All rights reserved.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.2.0
v3.2.1
31 changes: 12 additions & 19 deletions src/Http/HttpBaseClient.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2015-2020 Virgil Security Inc.
* Copyright (c) 2015-2024 Virgil Security Inc.
*
* All rights reserved.
*
Expand Down Expand Up @@ -37,8 +37,10 @@

namespace Virgil\PureKit\Http;

use Exception;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException;
use Purekit\HttpError as ProtoHttpError;
use Psr\Http\Message\ResponseInterface;
use Virgil\PureKit\Http\_\HttpMethod;
Expand All @@ -54,27 +56,15 @@ class HttpBaseClient
/**
* @var GuzzleClient
*/
private $httpClient;
/**
* @var string
*/
private $serviceBaseUrl;
/**
* @var string
*/
private $appToken;
private GuzzleClient $httpClient;

/**
* BaseHttpClient constructor.
* @param string $serviceBaseUrl
* @param string $appToken
* @param bool $debug
*/
public function __construct(string $serviceBaseUrl, string $appToken)
public function __construct(private readonly string $serviceBaseUrl, private readonly string $appToken)
{
$this->serviceBaseUrl = $serviceBaseUrl;
$this->appToken = $appToken;

$this->httpClient = new GuzzleClient(['base_uri' => $this->_getServiceBaseUrl()]);
}

Expand All @@ -83,22 +73,25 @@ public function __construct(string $serviceBaseUrl, string $appToken)
* @param string $endpoint
* @param HttpMethod|null $method
* @return ResponseInterface
* @throws ProtocolException
* @throws ProtocolException|GuzzleException
* @throws Exception
*/
protected function _send(BaseRequest $request, string $endpoint, HttpMethod $method = null):
ResponseInterface
{
$method = $method ?: HttpMethod::POST();

try {
return $this->httpClient->request($method->getValue(), "." . $endpoint .
return $this->httpClient->request(
$method->getValue(),
"." . $endpoint .
$request->getParams(),
[
"headers" => $request->getOptionsHeader($this->appToken),
"body" => $request->getOptionsBody(),
]);
]
);
} catch (ClientException $exception) {

$protoBody = $exception->getResponse()->getBody()->getContents();

$protoHttpErr = new ProtoHttpError();
Expand Down
19 changes: 12 additions & 7 deletions src/Http/HttpKmsClient.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2015-2020 Virgil Security Inc.
* Copyright (c) 2015-2024 Virgil Security Inc.
*
* All rights reserved.
*
Expand Down Expand Up @@ -37,8 +37,14 @@

namespace Virgil\PureKit\Http;

use Exception;
use GuzzleHttp\Exception\GuzzleException;
use PurekitV3Client\DecryptResponse as ProtoDecryptResponse;
use Virgil\PureKit\Http\Request\Kms\DecryptRequest;
use Virgil\PureKit\Pure\Exception\EmptyArgumentException;
use Virgil\PureKit\Pure\Exception\IllegalStateException;
use Virgil\PureKit\Pure\Exception\NullArgumentException;
use Virgil\PureKit\Pure\Exception\ProtocolException;
use Virgil\PureKit\Pure\Util\ValidationUtils;

/**
Expand All @@ -47,15 +53,14 @@
*/
class HttpKmsClient extends HttpBaseClient
{
public const SERVICE_ADDRESS = "https://api.virgilsecurity.com/kms/v1";
public const string SERVICE_ADDRESS = "https://api.virgilsecurity.com/kms/v1";

/**
* HttpKmsClient constructor.
* @param string $appToken
* @param string $serviceBaseUrl
* @throws \Virgil\PureKit\Pure\Exception\EmptyArgumentException
* @throws \Virgil\PureKit\Pure\Exception\IllegalStateException
* @throws \Virgil\PureKit\Pure\Exception\NullArgumentException
* @throws EmptyArgumentException
* @throws NullArgumentException
*/
public function __construct(string $appToken, string $serviceBaseUrl = self::SERVICE_ADDRESS)
{
Expand All @@ -68,7 +73,7 @@ public function __construct(string $appToken, string $serviceBaseUrl = self::SER
/**
* @param DecryptRequest $request
* @return ProtoDecryptResponse
* @throws \Virgil\PureKit\Pure\Exception\ProtocolException | \Exception
* @throws ProtocolException | Exception|GuzzleException
*/
public function decrypt(DecryptRequest $request): ProtoDecryptResponse
{
Expand All @@ -79,4 +84,4 @@ public function decrypt(DecryptRequest $request): ProtoDecryptResponse

return $res;
}
}
}
20 changes: 12 additions & 8 deletions src/Http/HttpPheClient.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2015-2020 Virgil Security Inc.
* Copyright (c) 2015-2024 Virgil Security Inc.
*
* All rights reserved.
*
Expand Down Expand Up @@ -37,10 +37,15 @@

namespace Virgil\PureKit\Http;

use Exception;
use GuzzleHttp\Exception\GuzzleException;
use Purekit\EnrollmentResponse as ProtoEnrollmentResponse;
use Purekit\VerifyPasswordResponse as ProtoVerifyPasswordResponse;
use Virgil\PureKit\Http\Request\Phe\EnrollRequest;
use Virgil\PureKit\Http\Request\Phe\VerifyPasswordRequest;
use Virgil\PureKit\Pure\Exception\EmptyArgumentException;
use Virgil\PureKit\Pure\Exception\IllegalStateException;
use Virgil\PureKit\Pure\Exception\NullArgumentException;
use Virgil\PureKit\Pure\Util\ValidationUtils;

/**
Expand All @@ -49,15 +54,14 @@
*/
class HttpPheClient extends HttpBaseClient
{
public const SERVICE_ADDRESS = "https://api.virgilsecurity.com/phe/v1/";
public const string SERVICE_ADDRESS = "https://api.virgilsecurity.com/phe/v1/";

/**
* HttpPheClient constructor.
* @param string $appToken
* @param string $serviceBaseUrl
* @throws \Virgil\PureKit\Pure\Exception\EmptyArgumentException
* @throws \Virgil\PureKit\Pure\Exception\IllegalStateException
* @throws \Virgil\PureKit\Pure\Exception\NullArgumentException
* @throws EmptyArgumentException
* @throws NullArgumentException
*/
public function __construct(string $appToken, string $serviceBaseUrl = self::SERVICE_ADDRESS)
{
Expand All @@ -70,7 +74,7 @@ public function __construct(string $appToken, string $serviceBaseUrl = self::SER
/**
* @param EnrollRequest $request
* @return ProtoEnrollmentResponse
* @throws \Exception
* @throws Exception|GuzzleException
*/
public function enrollAccount(EnrollRequest $request): ProtoEnrollmentResponse
{
Expand All @@ -87,7 +91,7 @@ public function enrollAccount(EnrollRequest $request): ProtoEnrollmentResponse
/**
* @param VerifyPasswordRequest $request
* @return ProtoVerifyPasswordResponse
* @throws \Exception
* @throws Exception|GuzzleException
*/
public function verifyPassword(VerifyPasswordRequest $request): ProtoVerifyPasswordResponse
{
Expand All @@ -100,4 +104,4 @@ public function verifyPassword(VerifyPasswordRequest $request): ProtoVerifyPassw

return $res;
}
}
}
Loading

0 comments on commit 4009cfa

Please sign in to comment.