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

v5.0 #28

Merged
merged 12 commits into from
Oct 16, 2023
Merged

v5.0 #28

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
File renamed without changes.
8 changes: 5 additions & 3 deletions .github/prepare-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ __DIR__=$(cd `dirname $0`; pwd)

cd $__DIR__

if [[ `expr $PHP_DOCKER_VERSION \< 7` -eq 0 ]]; then
if [[ `expr $PHP_DOCKER_VERSION \< 7.1` -eq 0 ]]; then
export PHP_DOCKER_FILE="php.dockerfile"
else
export PHP_DOCKER_FILE="php-5.dockerfile"
export PHP_DOCKER_FILE="php-low.dockerfile"
fi

containerName=$1

docker-compose up -d $containerName \
&& docker exec $containerName php -v \
&& docker exec $containerName php -m \
&& docker exec $containerName composer -V \
&& docker exec $containerName php --ri curl
docker exec $containerName php --ri swoole
docker exec $containerName composer -V \
&& docker ps -a

n=0
Expand Down
16 changes: 16 additions & 0 deletions .github/print-logs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

$dir = dirname(__DIR__) . '/tests/server/';

foreach ([
$dir . 'Http/log.log',
$dir . 'Http2/log.log',
$dir . 'WebSocket/log.log',
] as $fileName)
{
echo '[',$fileName,']', \PHP_EOL;
if (is_file($fileName))
{
echo file_get_contents($fileName), \PHP_EOL;
}
}
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [5.5, 5.6, 7.0, 7.1]
php: ["7.1"]

env:
PHP_DOCKER_VERSION: ${{ matrix.php }}
Expand All @@ -24,6 +24,10 @@ jobs:
- name: test
run: docker exec php composer test

- name: Print logs
if: failure()
run: php .github/print-logs.php

ci-curl-swoole:
runs-on: ubuntu-20.04

Expand All @@ -32,6 +36,9 @@ jobs:
matrix:
swoole:
[
5.1-php8.0,
5.1-php8.1,
5.1-php8.2,
5.0-php8.0,
5.0-php8.1,
5.0-php8.2,
Expand All @@ -54,3 +61,7 @@ jobs:

- name: test
run: docker exec swoole composer test

- name: Print logs
if: failure()
run: php .github/print-logs.php
4 changes: 2 additions & 2 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
swoole: [4.6-php7.4]
swoole: [5.0-php8.2]

env:
SWOOLE_DOCKER_VERSION: ${{ matrix.swoole }}
Expand All @@ -20,7 +20,7 @@ jobs:
- name: Prepare
run: |
./.github/prepare-test.sh swoole
docker exec swoole composer require friendsofphp/php-cs-fixer:^2.19 --dev
docker exec swoole composer require php-cs-fixer/shim:~3.35.0 --dev

- name: Test
run: docker exec swoole ./vendor/bin/php-cs-fixer fix --dry-run --diff
4 changes: 2 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
swoole: [4.6-php7.4]
swoole: [5.0-php8.2]

env:
SWOOLE_DOCKER_VERSION: ${{ matrix.swoole }}
Expand All @@ -20,7 +20,7 @@ jobs:
- name: Prepare
run: |
./.github/prepare-test.sh swoole
docker exec swoole composer require phpstan/phpstan:^0.12.91 --dev
docker exec swoole composer require phpstan/phpstan:~1.10.0 --dev

- name: Test
run: docker exec swoole ./vendor/bin/phpstan analyse --memory-limit 1G
114 changes: 114 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

if (!file_exists(__DIR__ . '/src'))
{
exit(0);
}

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'php_unit_dedicate_assert' => ['target' => '5.6'],
'array_syntax' => ['syntax' => 'short'],
'array_indentation' => true,
'binary_operator_spaces' => [
'operators' => [
'=>' => 'align_single_space',
],
],
'concat_space' => [
'spacing' => 'one',
],
'fopen_flags' => false,
'protected_to_private' => false,
'native_constant_invocation' => true,
'single_quote' => true,
'single_space_around_construct' => [
'constructs_followed_by_a_single_space' => [
'abstract',
'as',
'attribute',
'break',
'case',
'catch',
'class',
'clone',
'comment',
'const',
'const_import',
'continue',
'do',
'echo',
'else',
'elseif',
'enum',
'extends',
'final',
'finally',
'for',
'foreach',
'function',
'function_import',
'global',
'goto',
'if',
'implements',
'include',
'include_once',
'instanceof',
'insteadof',
'interface',
'match',
'named_argument',
// 'namespace', // 兼容性移除
'new',
'open_tag_with_echo',
'php_doc',
'php_open',
'print',
'private',
'protected',
'public',
'readonly',
'require',
'require_once',
'return',
'static',
'switch',
'throw',
'trait',
'try',
'type_colon',
'use',
'use_lambda',
'use_trait',
'var',
'while',
'yield',
'yield_from',
],
],
'control_structure_continuation_position' => [
'position' => 'next_line',
],
'curly_braces_position' => [
'control_structures_opening_brace' => 'next_line_unless_newline_at_signature_end',
],
'no_superfluous_phpdoc_tags' => false,
'single_line_comment_style' => false,
'combine_nested_dirname' => false,
'backtick_to_shell_exec' => false,
'visibility_required' => false,
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->exclude(__DIR__ . '/vendor')
->in(__DIR__ . '/.github')
->in(__DIR__ . '/src')
->in(__DIR__ . '/examples')
->in(__DIR__ . '/tests')
->append([__FILE__])
)
;
44 changes: 0 additions & 44 deletions .php_cs.dist

This file was deleted.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "yurunsoft/yurun-http",
"description": "YurunHttp 是开源的 PHP HTTP 类库,支持链式操作,简单易用。支持 Curl、Swoole,支持 Http、Http2、WebSocket!",
"require": {
"php": ">=5.5.0",
"psr/http-message": "~1.0",
"php": ">=7.1",
"psr/http-message": "~1.0|~2.0",
"psr/log": "~1.0|~2.0|~3.0"
},
"require-dev": {
Expand Down
6 changes: 4 additions & 2 deletions examples/http2Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
{
$response = $client->recv();
var_dump($response->body());
} while ($response->success);
}
while ($response->success);
});

// 客户端请求和响应获取
Expand Down Expand Up @@ -52,7 +53,8 @@
{
++$returnCount;
}
} while ($returnCount < $count);
}
while ($returnCount < $count);

$client->close();
});
2 changes: 1 addition & 1 deletion examples/psr7Ex.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function test()
->withAttribute(Attributes::DOWNLOAD_SPEED, 30000)
// 上传限速,单位:字节,仅Curl有效
->withAttribute(Attributes::UPLOAD_SPEED, 30000)
;
;
$response = YurunHttp::send($request);
var_dump($response);
}
12 changes: 6 additions & 6 deletions src/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class HttpRequest
*
* @var callable|null
*/
public $retryCallback = null;
public $retryCallback;

/**
* 是否使用代理,默认false.
Expand Down Expand Up @@ -175,7 +175,7 @@ class HttpRequest
*
* @var string
*/
public $certPassword = null;
public $certPassword;

/**
* certType规定的私钥的加密类型,支持的密钥类型为"PEM"(默认值)、"DER"和"ENG".
Expand All @@ -196,7 +196,7 @@ class HttpRequest
*
* @var string
*/
public $keyPassword = null;
public $keyPassword;

/**
* 请求方法.
Expand All @@ -217,7 +217,7 @@ class HttpRequest
*
* @var bool|null
*/
public $connectionPool = null;
public $connectionPool;

/**
* 代理认证方式.
Expand Down Expand Up @@ -654,7 +654,7 @@ public function ua($userAgent)
*/
public function retry($retry, $callback = null)
{
$this->retry = $retry < 0 ? 0 : $retry; //至少请求1次,即重试0次
$this->retry = $retry < 0 ? 0 : $retry; // 至少请求1次,即重试0次
$this->retryCallback = $callback;

return $this;
Expand Down Expand Up @@ -951,7 +951,7 @@ public function buildRequest($url = null, $requestBody = null, $method = null, $
->withAttribute(Attributes::RETRY, $this->retry)
->withAttribute(Attributes::RETRY_CALLBACK, $this->retryCallback)
->withProtocolVersion($this->protocolVersion)
;
;
foreach ($this->proxy as $name => $value)
{
$request = $request->withAttribute('proxy.' . $name, $value);
Expand Down
Loading
Loading