Merge branch 'master' of github.com:hyperf/hyperf into socketio

This commit is contained in:
Reasno 2020-05-26 12:15:48 +08:00
commit ee55ad5f20
20 changed files with 316 additions and 43 deletions

View File

@ -5,11 +5,11 @@ sudo: required
matrix:
include:
- php: 7.2
env: SW_VERSION="4.5.0"
env: SW_VERSION="4.5.1"
- php: 7.3
env: SW_VERSION="4.5.0"
env: SW_VERSION="4.5.1"
- php: 7.4
env: SW_VERSION="4.5.0"
env: SW_VERSION="4.5.1"
- php: 7.2
env: SW_VERSION="4.4.18"
- php: 7.3

View File

@ -1,4 +1,6 @@
# v1.1.32 - TBD
# v1.1.33 - TBD
# v1.1.32 - 2020-05-21
## Fixed
@ -6,7 +8,19 @@
- [#1739](https://github.com/hyperf/hyperf/pull/1739) Fixed the wrong bitwise operator in oss hook.
- [#1743](https://github.com/hyperf/hyperf/pull/1743) Fixed the wrong `refId` for `grafana.json`.
- [#1748](https://github.com/hyperf/hyperf/pull/1748) Fixed `concurrent.limit` does not works when using another pool.
- [#1750](https://github.com/hyperf/hyperf/pull/1750) Fixed the incorrent number of current connections when close failed.
- [#1754](https://github.com/hyperf/hyperf/pull/1754) Fixed the wrong start info for base server.
- [#1764](https://github.com/hyperf/hyperf/pull/1764) Fixed datetime validate failed when the value is null.
- [#1769](https://github.com/hyperf/hyperf/pull/1769) Fixed a notice when client initiate disconnects in `socketio-server`.
## Added
- [#1724](https://github.com/hyperf/hyperf/pull/1724) Added `Model::orWhereHasMorph` ,`Model::whereDoesntHaveMorph` and `Model::orWhereDoesntHaveMorph`.
- [#1741](https://github.com/hyperf/hyperf/pull/1741) Added `Hyperf\Command\Command::choiceMultiple(): array` method, because the return type of `choice` method is `string`, so the methed cannot handle the multiple selections, even though setted `$multiple` argument.
- [#1742](https://github.com/hyperf/hyperf/pull/1742) Added Custom Casts for model.
- Added interface `Castable`, `CastsAttributes` and `CastsInboundAttributes`.
- Added `Model\Builder::withCasts`.
- Added `Model::loadMorph`, `Model::loadMorphCount` and `Model::syncAttributes`.
# v1.1.31 - 2020-05-14

View File

@ -46,7 +46,7 @@
"guzzlehttp/guzzle": "^6.3",
"influxdb/influxdb-php": "^1.15.0",
"ircmaxell/random-lib": "^1.2",
"jcchavezs/zipkin-opentracing": "^0.1.4",
"jcchavezs/zipkin-opentracing": "^0.1.5",
"jean85/pretty-package-versions": "^1.2",
"jonahgeorge/jaeger-client-php": "^0.4.4",
"laminas/laminas-mime": "^2.7",

View File

@ -35,7 +35,7 @@
mergeNavbar: true,
themeColor: '#3F51B5',
logo: '/logo.png',
autoHeader: true,
auto2top: true,
subMaxLevel: 4,
topMargin: 20,
search: {

View File

@ -1,18 +1,40 @@
# 版本更新记录
# v1.1.32 - 2020-05-21
## 修复
- [#1734](https://github.com/hyperf/hyperf/pull/1734) 修复模型多态查询,关联关系为空时,也会查询 SQL 的问题;
- [#1739](https://github.com/hyperf/hyperf/pull/1739) 修复 `hyperf/filesystem` 组件 OSS HOOK 位运算错误,导致 resource 判断不准确的问题;
- [#1743](https://github.com/hyperf/hyperf/pull/1743) 修复 `grafana.json` 中错误的`refId` 字段值;
- [#1748](https://github.com/hyperf/hyperf/pull/1748) 修复 `hyperf/amqp` 组件在使用其他连接池时,对应的 `concurrent.limit` 配置不生效的问题;
- [#1750](https://github.com/hyperf/hyperf/pull/1750) 修复连接池组件,在连接关闭失败时会导致计数有误的问题;
- [#1754](https://github.com/hyperf/hyperf/pull/1754) 修复 BASE Server 服务,启动提示没有考虑 UDP 服务的情况;
- [#1764](https://github.com/hyperf/hyperf/pull/1764) 修复当时间值为 null 时datatime 验证器执行失败的 BUG
- [#1769](https://github.com/hyperf/hyperf/pull/1769) 修复 `hyperf/socketio-server` 组件中,客户端初始化断开连接操作时会报 Notice 的错误的问题;
## 新增
- [#1724](https://github.com/hyperf/hyperf/pull/1724) 新增模型方法 `Model::orWhereHasMorph` ,`Model::whereDoesntHaveMorph` and `Model::orWhereDoesntHaveMorph`
- [#1741](https://github.com/hyperf/hyperf/pull/1741) 新增 `Hyperf\Command\Command::choiceMultiple(): array` 方法,因为 `choice` 方法的返回类型为 `string所以就算设置了 `$multiple` 参数也无法处理多个选择的情况;
- [#1742](https://github.com/hyperf/hyperf/pull/1742) 新增模型 自定义类型转换器 功能;
- 新增 interface `Castable`, `CastsAttributes``CastsInboundAttributes`
- 新增方法 `Model\Builder::withCasts`
- 新增方法 `Model::loadMorph`, `Model::loadMorphCount``Model::syncAttributes`
# v1.1.31 - 2020-05-14
## 新增
- [#1723](https://github.com/hyperf/hyperf/pull/1730) 异常处理器集成了 filp/whoops 。
- [#1723](https://github.com/hyperf/hyperf/pull/1723) 异常处理器集成了 filp/whoops 。
- [#1730](https://github.com/hyperf/hyperf/pull/1730) 为命令 `gen:model` 可选项 `--refresh-fillable` 添加简写 `-R`
## Fixed
## 修复
- [#1696](https://github.com/hyperf/hyperf/pull/1696) 修复方法 `Context::copy` 传入字段 `keys` 后无法正常使用的BUG。
- [#1708](https://github.com/hyperf/hyperf/pull/1708) [#1718](https://github.com/hyperf/hyperf/pull/1718) 修复 `hyperf/socketio-server` 组件内存溢出等BUG。
## Optimized
## 优化
- [#1710](https://github.com/hyperf/hyperf/pull/1710) MAC系统下不再使用 `cli_set_process_title` 方法设置进程名。

View File

@ -239,7 +239,7 @@ return [
'accessKey' => env('QINIU_ACCESS_KEY'),
'secretKey' => env('QINIU_SECRET_KEY'),
'bucket' => env('QINIU_BUCKET'),
'domain' => env('QINBIU_DOMAIN'),
'domain' => env('QINIU_DOMAIN'),
],
],
];

View File

@ -49,7 +49,6 @@ AbstractProvider::setGuzzleOptions([
<?php
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL | SWOOLE_HOOK_CURL);
```
## 如何使用 EasyWeChat
@ -78,6 +77,20 @@ $xml = $this->request->getBody()->getContents();
$app['request'] = new Request($get,$post,[],$cookie,$files,$server,$xml);
// Do something...
```
3. 服务器配置
如果需要使用微信公众平台的服务器配置功能,可以使用以下代码。
> 以下 `$response``Symfony\Component\HttpFoundation\Response` 并非 `Hyperf\HttpMessage\Server\Response`
> 所以只需将 `Body` 内容直接返回,即可通过微信验证。
```php
$response = $app->server->serve();
return $response->getBody()->getContents();
```
## 如何替换缓存
@ -92,5 +105,4 @@ use EasyWeChat\Factory;
$app = Factory::miniProgram([]);
$app['cache'] = ApplicationContext::getContainer()->get(CacheInterface::class);
```

View File

@ -1,18 +1,39 @@
# 版本更新記錄
# v1.1.32 - 2020-05-21
## 修復
- [#1734](https://github.com/hyperf/hyperf/pull/1734) 修復模型多態查詢,關聯關係為空時,也會查詢 SQL 的問題;
- [#1739](https://github.com/hyperf/hyperf/pull/1739) 修復 `hyperf/filesystem` 組件 OSS HOOK 位運算錯誤,導致 resource 判斷不準確的問題;
- [#1743](https://github.com/hyperf/hyperf/pull/1743) 修復 `grafana.json` 中錯誤的`refId` 字段值;
- [#1748](https://github.com/hyperf/hyperf/pull/1748) 修復 `hyperf/amqp` 組件在使用其他連接池時,對應的 `concurrent.limit` 配置不生效的問題;
- [#1750](https://github.com/hyperf/hyperf/pull/1750) 修復連接池組件,在連接關閉失敗時會導致計數有誤的問題;
- [#1754](https://github.com/hyperf/hyperf/pull/1754) 修復 BASE Server 服務,啟動提示沒有考慮 UDP 服務的情況;
- [#1764](https://github.com/hyperf/hyperf/pull/1764) 修復當時間值為 null 時datatime 驗證器執行失敗的 BUG
- [#1769](https://github.com/hyperf/hyperf/pull/1769) 修復 `hyperf/socketio-server` 組件中,客户端初始化斷開連接操作時會報 Notice 的錯誤的問題;
## 新增
- [#1724](https://github.com/hyperf/hyperf/pull/1724) 新增模型方法 `Model::orWhereHasMorph` ,`Model::whereDoesntHaveMorph` and `Model::orWhereDoesntHaveMorph`
- [#1742](https://github.com/hyperf/hyperf/pull/1742) 新增模型 自定義類型轉換器 功能;
- 新增 interface `Castable`, `CastsAttributes``CastsInboundAttributes`
- 新增方法 `Model\Builder::withCasts`
- 新增方法 `Model::loadMorph`, `Model::loadMorphCount``Model::syncAttributes`
# v1.1.31 - 2020-05-14
## 新增
- [#1723](https://github.com/hyperf/hyperf/pull/1730) 異常處理器集成了 filp/whoops 。
- [#1723](https://github.com/hyperf/hyperf/pull/1723) 異常處理器集成了 filp/whoops 。
- [#1730](https://github.com/hyperf/hyperf/pull/1730) 為命令 `gen:model` 可選項 `--refresh-fillable` 添加簡寫 `-R`
## Fixed
## 修復
- [#1696](https://github.com/hyperf/hyperf/pull/1696) 修復方法 `Context::copy` 傳入字段 `keys` 後無法正常使用的BUG。
- [#1708](https://github.com/hyperf/hyperf/pull/1708) [#1718](https://github.com/hyperf/hyperf/pull/1718) 修復 `hyperf/socketio-server` 組件內存溢出等BUG。
## Optimized
## 優化
- [#1710](https://github.com/hyperf/hyperf/pull/1710) MAC系統下不再使用 `cli_set_process_title` 方法設置進程名。

View File

@ -239,7 +239,7 @@ return [
'accessKey' => env('QINIU_ACCESS_KEY'),
'secretKey' => env('QINIU_SECRET_KEY'),
'bucket' => env('QINIU_BUCKET'),
'domain' => env('QINBIU_DOMAIN'),
'domain' => env('QINIU_DOMAIN'),
],
],
];

View File

@ -49,7 +49,6 @@ AbstractProvider::setGuzzleOptions([
<?php
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL | SWOOLE_HOOK_CURL);
```
## 如何使用 EasyWeChat
@ -78,6 +77,20 @@ $xml = $this->request->getBody()->getContents();
$app['request'] = new Request($get,$post,[],$cookie,$files,$server,$xml);
// Do something...
```
3. 服務器配置
如果需要使用微信公眾平台的服務器配置功能,可以使用以下代碼。
> 以下 `$response``Symfony\Component\HttpFoundation\Response` 並非 `Hyperf\HttpMessage\Server\Response`
> 所以只需將 `Body` 內容直接返回,即可通過微信驗證。
```php
$response = $app->server->serve();
return $response->getBody()->getContents();
```
## 如何替換緩存
@ -92,5 +105,4 @@ use EasyWeChat\Factory;
$app = Factory::miniProgram([]);
$app['cache'] = ApplicationContext::getContainer()->get(CacheInterface::class);
```

View File

@ -1,18 +1,39 @@
# 版本更新記錄
# v1.1.32 - 2020-05-21
## 修復
- [#1734](https://github.com/hyperf/hyperf/pull/1734) 修復模型多型查詢,關聯關係為空時,也會查詢 SQL 的問題;
- [#1739](https://github.com/hyperf/hyperf/pull/1739) 修復 `hyperf/filesystem` 元件 OSS HOOK 位運算錯誤,導致 resource 判斷不準確的問題;
- [#1743](https://github.com/hyperf/hyperf/pull/1743) 修復 `grafana.json` 中錯誤的`refId` 欄位值;
- [#1748](https://github.com/hyperf/hyperf/pull/1748) 修復 `hyperf/amqp` 元件在使用其他連線池時,對應的 `concurrent.limit` 配置不生效的問題;
- [#1750](https://github.com/hyperf/hyperf/pull/1750) 修復連線池元件,在連線關閉失敗時會導致計數有誤的問題;
- [#1754](https://github.com/hyperf/hyperf/pull/1754) 修復 BASE Server 服務,啟動提示沒有考慮 UDP 服務的情況;
- [#1764](https://github.com/hyperf/hyperf/pull/1764) 修復當時間值為 null 時datatime 驗證器執行失敗的 BUG
- [#1769](https://github.com/hyperf/hyperf/pull/1769) 修復 `hyperf/socketio-server` 元件中,客戶端初始化斷開連線操作時會報 Notice 的錯誤的問題;
## 新增
- [#1724](https://github.com/hyperf/hyperf/pull/1724) 新增模型方法 `Model::orWhereHasMorph` ,`Model::whereDoesntHaveMorph` and `Model::orWhereDoesntHaveMorph`
- [#1742](https://github.com/hyperf/hyperf/pull/1742) 新增模型 自定義型別轉換器 功能;
- 新增 interface `Castable`, `CastsAttributes``CastsInboundAttributes`
- 新增方法 `Model\Builder::withCasts`
- 新增方法 `Model::loadMorph`, `Model::loadMorphCount``Model::syncAttributes`
# v1.1.31 - 2020-05-14
## 新增
- [#1723](https://github.com/hyperf/hyperf/pull/1730) 異常處理器集成了 filp/whoops 。
- [#1723](https://github.com/hyperf/hyperf/pull/1723) 異常處理器集成了 filp/whoops 。
- [#1730](https://github.com/hyperf/hyperf/pull/1730) 為命令 `gen:model` 可選項 `--refresh-fillable` 新增簡寫 `-R`
## Fixed
## 修復
- [#1696](https://github.com/hyperf/hyperf/pull/1696) 修復方法 `Context::copy` 傳入欄位 `keys` 後無法正常使用的BUG。
- [#1708](https://github.com/hyperf/hyperf/pull/1708) [#1718](https://github.com/hyperf/hyperf/pull/1718) 修復 `hyperf/socketio-server` 元件記憶體溢位等BUG。
## Optimized
## 優化
- [#1710](https://github.com/hyperf/hyperf/pull/1710) MAC系統下不再使用 `cli_set_process_title` 方法設定程序名。

View File

@ -239,7 +239,7 @@ return [
'accessKey' => env('QINIU_ACCESS_KEY'),
'secretKey' => env('QINIU_SECRET_KEY'),
'bucket' => env('QINIU_BUCKET'),
'domain' => env('QINBIU_DOMAIN'),
'domain' => env('QINIU_DOMAIN'),
],
],
];

View File

@ -49,7 +49,6 @@ AbstractProvider::setGuzzleOptions([
<?php
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL | SWOOLE_HOOK_CURL);
```
## 如何使用 EasyWeChat
@ -78,6 +77,20 @@ $xml = $this->request->getBody()->getContents();
$app['request'] = new Request($get,$post,[],$cookie,$files,$server,$xml);
// Do something...
```
3. 伺服器配置
如果需要使用微信公眾平臺的伺服器配置功能,可以使用以下程式碼。
> 以下 `$response``Symfony\Component\HttpFoundation\Response` 並非 `Hyperf\HttpMessage\Server\Response`
> 所以只需將 `Body` 內容直接返回,即可通過微信驗證。
```php
$response = $app->server->serve();
return $response->getBody()->getContents();
```
## 如何替換快取
@ -92,5 +105,4 @@ use EasyWeChat\Factory;
$app = Factory::miniProgram([]);
$app['cache'] = ApplicationContext::getContainer()->get(CacheInterface::class);
```

View File

@ -159,12 +159,26 @@ abstract class Command extends SymfonyCommand
return $this->output->askQuestion($question);
}
/**
* Give the user a multiple choice from an array of answers.
*/
public function choiceMultiple(
string $question,
array $choices,
$default = null,
?int $attempts = null
): array {
$question = new ChoiceQuestion($question, $choices, $default);
$question->setMaxAttempts($attempts)->setMultiselect(true);
return $this->output->askQuestion($question);
}
/**
* Give the user a single choice from an array of answers.
*
* @param null|mixed $default
* @param null|mixed $attempts
* @param null|mixed $multiple
* @param null|bool $multiple Deprecated: use choiceMultiple method instead.
*/
public function choice(
string $question,
@ -173,11 +187,7 @@ abstract class Command extends SymfonyCommand
$attempts = null,
$multiple = null
): string {
$question = new ChoiceQuestion($question, $choices, $default);
$question->setMaxAttempts($attempts)->setMultiselect($multiple);
return $this->output->askQuestion($question);
return $this->choiceMultiple($question, $choices, $default, $attempts)[0];
}
/**

View File

@ -15,6 +15,7 @@ use Hyperf\Contract\ConnectionInterface;
use Hyperf\Contract\FrequencyInterface;
use Hyperf\Contract\PoolInterface;
use Hyperf\Contract\PoolOptionInterface;
use Hyperf\Contract\StdoutLoggerInterface;
use Psr\Container\ContainerInterface;
use RuntimeException;
use Throwable;
@ -83,9 +84,16 @@ abstract class Pool implements PoolInterface
if ($num > 0) {
/** @var ConnectionInterface $conn */
while ($this->currentConnections > $this->option->getMinConnections() && $conn = $this->channel->pop($this->option->getWaitTimeout())) {
$conn->close();
--$this->currentConnections;
--$num;
try {
$conn->close();
} catch (\Throwable $exception) {
if ($this->container->has(StdoutLoggerInterface::class) && $logger = $this->container->get(StdoutLoggerInterface::class)) {
$logger->error((string) $exception);
}
} finally {
--$this->currentConnections;
--$num;
}
if ($num <= 0) {
// Ignore connections queued during flushing.

View File

@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Pool;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Utils\ApplicationContext;
use HyperfTest\Pool\Stub\FooPool;
use Mockery;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
/**
* @internal
* @coversNothing
*/
class PoolTest extends TestCase
{
protected function tearDown()
{
Mockery::close();
}
public function testPoolFlush()
{
$container = $this->getContainer();
$container->shouldReceive('has')->with(StdoutLoggerInterface::class)->andReturn(true);
$container->shouldReceive('get')->with(StdoutLoggerInterface::class)->andReturn(value(function () {
$logger = Mockery::mock(StdoutLoggerInterface::class);
$logger->shouldReceive('error')->withAnyArgs()->times(4)->andReturn(true);
return $logger;
}));
$pool = new FooPool($container, []);
$conns = [];
for ($i = 0; $i < 5; ++$i) {
$conns[] = $pool->get();
}
foreach ($conns as $conn) {
$pool->release($conn);
}
$pool->flush();
$this->assertSame(1, $pool->getConnectionsInChannel());
$this->assertSame(1, $pool->getCurrentConnections());
}
protected function getContainer()
{
$container = Mockery::mock(ContainerInterface::class);
ApplicationContext::setContainer($container);
return $container;
}
}

View File

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Pool\Stub;
use Hyperf\Contract\ConnectionInterface;
use Hyperf\Pool\Pool;
use Mockery;
class FooPool extends Pool
{
protected function createConnection(): ConnectionInterface
{
return Mockery::mock(ConnectionInterface::class);
}
}

View File

@ -57,19 +57,16 @@ class AfterWorkerStartListener implements ListenerInterface
case Server::SERVER_BASE:
if (($sockType === SWOOLE_SOCK_TCP) || ($sockType === SWOOLE_SOCK_TCP6)) {
return 'TCP';
} else if (($sockType === SWOOLE_SOCK_UDP) || ($sockType === SWOOLE_SOCK_UDP6)) {
return 'UDP';
} else {
return 'UNKNOWN';
}
break;
if (($sockType === SWOOLE_SOCK_UDP) || ($sockType === SWOOLE_SOCK_UDP6)) {
return 'UDP';
}
return 'UNKNOWN';
case Server::SERVER_WEBSOCKET:
return 'WebSocket';
break;
case Server::SERVER_HTTP:
default:
return 'HTTP';
break;
}
});
$this->logger->info(sprintf('%s Server listening at %s', $type, $listen));

View File

@ -1215,8 +1215,11 @@ trait ValidatesAttributes
*
* @return null|\DateTime
*/
protected function getDateTimeWithOptionalFormat(string $format, string $value)
protected function getDateTimeWithOptionalFormat(string $format, ?string $value)
{
if (is_null($value)) {
return null;
}
if ($date = DateTime::createFromFormat('!' . $format, $value)) {
return $date;
}

View File

@ -4540,6 +4540,59 @@ class ValidationValidatorTest extends TestCase
];
}
public function testValidateAfter()
{
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator(
$trans,
[
'end_time' => '2020-04-09 19:09:05',
],
[
'start_time' => 'date_format:Y-m-d H:i:s|after:2020-04-09 16:09:05',
'end_time' => 'date_format:Y-m-d H:i:s|after:start_time',
]
);
$this->assertFalse($v->passes());
$v = new Validator(
$trans,
[
'start_time' => '2020-04-09 17:09:05',
'end_time' => '2020-04-09 19:09:05',
],
[
'start_time' => 'date_format:Y-m-d H:i:s|after:2020-04-09 18:09:05',
'end_time' => 'date_format:Y-m-d H:i:s|after:start_time',
]
);
$this->assertFalse($v->passes());
$v = new Validator(
$trans,
[],
[
'start_time' => 'date_format:Y-m-d H:i:s|after:2020-04-09 16:09:05',
'end_time' => 'date_format:Y-m-d H:i:s|after:start_time',
]
);
$this->assertTrue($v->passes());
$v = new Validator(
$trans,
[
'start_time' => '2020-04-09 17:09:05',
'end_time' => '2020-04-09 19:09:05',
],
[
'start_time' => 'date_format:Y-m-d H:i:s|after:2020-04-09 16:09:05',
'end_time' => 'date_format:Y-m-d H:i:s|after:start_time',
]
);
$this->assertTrue($v->passes());
}
public function getIlluminateArrayTranslator()
{
return new Translator(