Skip to content

Commit

Permalink
Symfony components 7.x #2787
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Jan 22, 2024
1 parent 5e13dca commit d5c6de2
Show file tree
Hide file tree
Showing 49 changed files with 132 additions and 133 deletions.
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
"overtrue/socialite": "^3.5.4|^4.0.1",
"psr/simple-cache": "^1.0|^2.0|^3.0",
"psr/http-client": "^1.0",
"symfony/cache": "^5.4|^6.0",
"symfony/http-foundation": "^5.4|^6.0",
"symfony/cache": "^5.4|^6.0|^7.0",
"symfony/http-foundation": "^5.4|^6.0|^7.0",
"symfony/psr-http-message-bridge": "^2.1.2|^6.4.0",
"symfony/http-client": "^5.4|^6.0",
"symfony/mime": "^5.4|^6.0",
"symfony/http-client": "^5.4|^6.0|^7.0",
"symfony/mime": "^5.4|^6.0|^7.0",
"symfony/polyfill-php81": "^1.25",
"thenorthmemory/xml": "^1.0"
},
Expand Down Expand Up @@ -93,7 +93,8 @@
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true
"composer/package-versions-deprecated": true,
"php-http/discovery": true
}
}
}
4 changes: 2 additions & 2 deletions src/Kernel/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function get(array|string $key, mixed $default = null): mixed

/**
* @param array<string> $keys
* @return array<string, mixed>
* @return array<string, mixed>
*/
#[Pure]
public function getMany(array $keys): array
Expand All @@ -78,7 +78,7 @@ public function set(string $key, mixed $value = null): void
}

/**
* @return array<string, mixed>
* @return array<string, mixed>
*/
public function all(): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Kernel/Contracts/Aes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

interface Aes
{
public static function encrypt(string $plaintext, string $key, string $iv = null): string;
public static function encrypt(string $plaintext, string $key, ?string $iv = null): string;

public static function decrypt(string $ciphertext, string $key, string $iv = null): string;
public static function decrypt(string $ciphertext, string $key, ?string $iv = null): string;
}
4 changes: 2 additions & 2 deletions src/Kernel/Encryptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Encryptor

protected ?string $receiveId = null;

public function __construct(string $appId, string $token, string $aesKey, string $receiveId = null)
public function __construct(string $appId, string $token, string $aesKey, ?string $receiveId = null)
{
$this->appId = $appId;
$this->token = $token;
Expand All @@ -82,7 +82,7 @@ public function getToken(): string
* @throws RuntimeException
* @throws Exception
*/
public function encrypt(string $plaintext, string $nonce = null, int|string $timestamp = null): string
public function encrypt(string $plaintext, ?string $nonce = null, int|string|null $timestamp = null): string
{
try {
$plaintext = Pkcs7::padding(random_bytes(16).pack('N', strlen($plaintext)).$plaintext.$this->appId, 32);
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/Exceptions/HttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class HttpException extends Exception
/**
* HttpException constructor.
*/
public function __construct(string $message, ResponseInterface $response = null, int $code = 0)
public function __construct(string $message, ?ResponseInterface $response = null, int $code = 0)
{
parent::__construct($message, $code);

Expand Down
20 changes: 10 additions & 10 deletions src/Kernel/Form/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class File extends DataPart
*/
public static function from(
string $pathOrContents,
string $filename = null,
string $contentType = null,
string $encoding = null
?string $filename = null,
?string $contentType = null,
?string $encoding = null
): DataPart {
if (file_exists($pathOrContents)) {
return static::fromPath($pathOrContents, $filename, $contentType);
Expand All @@ -38,11 +38,11 @@ public static function from(
*/
public static function fromContents(
string $contents,
string $filename = null,
string $contentType = null,
string $encoding = null
?string $filename = null,
?string $contentType = null,
?string $encoding = null
): DataPart {
if (null === $contentType) {
if ($contentType === null) {
$mimeTypes = new MimeTypes();

if ($filename) {
Expand Down Expand Up @@ -70,9 +70,9 @@ public static function fromContents(
*/
public static function withContents(
string $contents,
string $filename = null,
string $contentType = null,
string $encoding = null
?string $filename = null,
?string $contentType = null,
?string $encoding = null
): DataPart {
return self::fromContents(...func_get_args());

Check failure on line 77 in src/Kernel/Form/File.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $contents of static method EasyWeChat\Kernel\Form\File::fromContents() expects string, mixed given.
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function create(array $fields): Form
}

/**
* @return array<string,mixed>
* @return array<string,mixed>
*/
#[ArrayShape(['headers' => 'array', 'body' => 'string'])]
public function toArray(): array
Expand Down
4 changes: 2 additions & 2 deletions src/Kernel/HttpClient/AccessTokenAwareClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class AccessTokenAwareClient implements AccessTokenAwareHttpClientInterface
{
use AsyncDecoratorTrait;
use HttpClientMethods;
use RetryableClient;
use MockableHttpClient;
use RequestWithPresets;
use RetryableClient;

public function __construct(
HttpClientInterface $client = null,
?HttpClientInterface $client = null,
protected ?AccessTokenInterface $accessToken = null,
protected ?Closure $failureJudge = null,
protected bool $throw = true
Expand Down
4 changes: 2 additions & 2 deletions src/Kernel/HttpClient/RequestWithPresets.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function with(string|array $key, mixed $value = null): static
* @throws RuntimeException
* @throws InvalidArgumentException
*/
public function withFile(string $pathOrContents, string $formName = 'file', string $filename = null): static
public function withFile(string $pathOrContents, string $formName = 'file', ?string $filename = null): static
{
$file = is_file($pathOrContents) ? File::fromPath(
$pathOrContents,
Expand All @@ -111,7 +111,7 @@ public function withFile(string $pathOrContents, string $formName = 'file', stri
* @throws RuntimeException
* @throws InvalidArgumentException
*/
public function withFileContents(string $contents, string $formName = 'file', string $filename = null): static
public function withFileContents(string $contents, string $formName = 'file', ?string $filename = null): static
{
return $this->withFile($contents, $formName, $filename);
}
Expand Down
26 changes: 13 additions & 13 deletions src/Kernel/HttpClient/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*
* @see \Symfony\Contracts\HttpClient\ResponseInterface
*/
class Response implements Jsonable, Arrayable, ArrayAccess, ResponseInterface, StreamableInterface
class Response implements Arrayable, ArrayAccess, Jsonable, ResponseInterface, StreamableInterface
{
public function __construct(
protected ResponseInterface $response,
Expand Down Expand Up @@ -98,7 +98,7 @@ public function isFailed(): bool
}

try {
return 400 <= $this->getStatusCode();
return $this->getStatusCode() >= 400;
} catch (Throwable $e) {
return true;
}
Expand All @@ -112,7 +112,7 @@ public function isFailed(): bool
* @throws ClientExceptionInterface
* @throws BadResponseException
*/
public function toArray(bool $throw = null): array
public function toArray(?bool $throw = null): array
{
$throw ??= $this->throw;

Expand Down Expand Up @@ -143,15 +143,15 @@ public function toArray(bool $throw = null): array
* @throws ClientExceptionInterface
* @throws BadResponseException
*/
public function toJson(bool $throw = null): string|false
public function toJson(?bool $throw = null): string|false
{
return json_encode($this->toArray($throw), JSON_UNESCAPED_UNICODE);
}

/**
* {@inheritdoc}
*/
public function toStream(bool $throw = null)
public function toStream(?bool $throw = null)
{
if ($this->response instanceof StreamableInterface) {
return $this->response->toStream($throw ?? $this->throw);
Expand All @@ -175,11 +175,11 @@ public function toDataUrl(): string
return 'data:'.$this->getHeaderLine('content-type').';base64,'.base64_encode($this->getContent());
}

public function toPsrResponse(ResponseFactoryInterface $responseFactory = null, StreamFactoryInterface $streamFactory = null): \Psr\Http\Message\ResponseInterface
public function toPsrResponse(?ResponseFactoryInterface $responseFactory = null, ?StreamFactoryInterface $streamFactory = null): \Psr\Http\Message\ResponseInterface
{
$streamFactory ??= $responseFactory instanceof StreamFactoryInterface ? $responseFactory : null;

if (null === $responseFactory || null === $streamFactory) {
if ($responseFactory === null || $streamFactory === null) {
if (! class_exists(Psr17Factory::class) && ! class_exists(Psr17FactoryDiscovery::class)) {
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\Psr18Client" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".');
}
Expand Down Expand Up @@ -290,12 +290,12 @@ public function getStatusCode(): int
return $this->response->getStatusCode();
}

public function getHeaders(bool $throw = null): array
public function getHeaders(?bool $throw = null): array
{
return $this->response->getHeaders($throw ?? $this->throw);
}

public function getContent(bool $throw = null): string
public function getContent(?bool $throw = null): string
{
return $this->response->getContent($throw ?? $this->throw);
}
Expand All @@ -305,7 +305,7 @@ public function cancel(): void
$this->response->cancel();
}

public function getInfo(string $type = null): mixed
public function getInfo(?string $type = null): mixed
{
return $this->response->getInfo($type);
}
Expand All @@ -329,7 +329,7 @@ public function __toString(): string
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function hasHeader(string $name, bool $throw = null): bool
public function hasHeader(string $name, ?bool $throw = null): bool
{
return isset($this->getHeaders($throw)[$name]);
}
Expand All @@ -342,7 +342,7 @@ public function hasHeader(string $name, bool $throw = null): bool
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function getHeader(string $name, bool $throw = null): array
public function getHeader(string $name, ?bool $throw = null): array
{
$name = strtolower($name);
$throw ??= $this->throw;
Expand All @@ -356,7 +356,7 @@ public function getHeader(string $name, bool $throw = null): array
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function getHeaderLine(string $name, bool $throw = null): string
public function getHeaderLine(string $name, ?bool $throw = null): string
{
$name = strtolower($name);
$throw ??= $this->throw;
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/HttpClient/RetryableClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function retry(array $config = []): static
public function retryUsing(
RetryStrategyInterface $strategy,
int $maxRetries = 3,
LoggerInterface $logger = null
?LoggerInterface $logger = null
): static {
$this->client = new RetryableHttpClient($this->client, $strategy, $maxRetries, $logger);

Expand Down
5 changes: 3 additions & 2 deletions src/Kernel/HttpClient/ScopingHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
use Symfony\Contracts\Service\ResetInterface;

class ScopingHttpClient implements HttpClientInterface, ResetInterface, LoggerAwareInterface
class ScopingHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
{
use HttpClientTrait;

private HttpClientInterface $client;

private array $defaultOptionsByRegexp;

public function __construct(HttpClientInterface $client, array $defaultOptionsByRegexp)
Expand All @@ -37,7 +38,7 @@ public function request(string $method, string $url, array $options = []): Respo
return $this->client->request($method, $url, $options);
}

public function stream(ResponseInterface|iterable $responses, float $timeout = null): ResponseStreamInterface
public function stream(ResponseInterface|iterable $responses, ?float $timeout = null): ResponseStreamInterface
{
return $this->client->stream($responses, $timeout);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Kernel/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @implements ArrayAccess<array-key, mixed>
*/
abstract class Message implements ArrayAccess, Jsonable, \JsonSerializable
abstract class Message implements \JsonSerializable, ArrayAccess, Jsonable
{
use HasAttributes;

Expand Down Expand Up @@ -47,14 +47,14 @@ public static function createFromRequest(ServerRequestInterface $request): Messa
*/
public static function format(string $originContent): array
{
if (0 === stripos($originContent, '<')) {
if (stripos($originContent, '<') === 0) {
$attributes = Xml::parse($originContent);
}

// Handle JSON format.
$dataSet = json_decode($originContent, true);

if (JSON_ERROR_NONE === json_last_error() && $originContent) {
if (json_last_error() === JSON_ERROR_NONE && $originContent) {
$attributes = $dataSet;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/ServerResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function sendHeaders(): static
}

foreach ($this->getHeaders() as $name => $values) {
$replace = 0 === \strcasecmp($name, 'Content-Type');
$replace = \strcasecmp($name, 'Content-Type') === 0;

foreach ($values as $value) {
header($name.': '.$value, $replace, $this->getStatusCode());
Expand Down
8 changes: 4 additions & 4 deletions src/Kernel/Support/AesCbc.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class AesCbc implements Aes
/**
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
*/
public static function encrypt(string $plaintext, string $key, string $iv = null): string
public static function encrypt(string $plaintext, string $key, ?string $iv = null): string
{
$ciphertext = \openssl_encrypt($plaintext, 'aes-128-cbc', $key, OPENSSL_RAW_DATA, (string) $iv);

if (false === $ciphertext) {
if ($ciphertext === false) {
throw new InvalidArgumentException(openssl_error_string() ?: 'Encrypt AES CBC error.');
}

Expand All @@ -30,7 +30,7 @@ public static function encrypt(string $plaintext, string $key, string $iv = null
/**
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
*/
public static function decrypt(string $ciphertext, string $key, string $iv = null): string
public static function decrypt(string $ciphertext, string $key, ?string $iv = null): string
{
$plaintext = openssl_decrypt(
base64_decode($ciphertext),
Expand All @@ -40,7 +40,7 @@ public static function decrypt(string $ciphertext, string $key, string $iv = nul
(string) $iv
);

if (false === $plaintext) {
if ($plaintext === false) {
throw new InvalidArgumentException(openssl_error_string() ?: 'Decrypt AES CBC error.');
}

Expand Down
Loading

1 comment on commit d5c6de2

@vercel
Copy link

@vercel vercel bot commented on d5c6de2 Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

easywechat – ./

easywechat.vercel.app
easywechat-git-6x-overtrue.vercel.app
easywechat-overtrue.vercel.app

Please sign in to comment.