mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 03:37:44 +08:00
Fixed bug that unable to serialize Channel
in Crontab
. (#5578)
This commit is contained in:
parent
df3c2eaff0
commit
f60b720e2b
@ -8,6 +8,10 @@
|
||||
|
||||
- [#5572](https://github.com/hyperf/hyperf/pull/5572) Update Http Server to use new WritableConnection implementation.
|
||||
|
||||
## Fixed
|
||||
|
||||
- [#5578](https://github.com/hyperf/hyperf/pull/5578) Fixed bug that unable to serialize `Channel` in `Crontab`.
|
||||
|
||||
# v3.0.13 - 2023-03-26
|
||||
|
||||
## Added
|
||||
|
@ -45,6 +45,39 @@ class Crontab
|
||||
$this->running = new Channel(1);
|
||||
}
|
||||
|
||||
public function __serialize(): array
|
||||
{
|
||||
return [
|
||||
"\x00*\x00name" => $this->name,
|
||||
"\x00*\x00type" => $this->type,
|
||||
"\x00*\x00rule" => $this->rule,
|
||||
"\x00*\x00singleton" => $this->singleton,
|
||||
"\x00*\x00mutexPool" => $this->mutexPool,
|
||||
"\x00*\x00mutexExpires" => $this->mutexExpires,
|
||||
"\x00*\x00onOneServer" => $this->onOneServer,
|
||||
"\x00*\x00callback" => $this->callback,
|
||||
"\x00*\x00memo" => $this->memo,
|
||||
"\x00*\x00executeTime" => $this->executeTime,
|
||||
"\x00*\x00enable" => $this->enable,
|
||||
];
|
||||
}
|
||||
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
$this->name = $data["\x00*\x00name"] ?? $this->name;
|
||||
$this->type = $data["\x00*\x00type"] ?? $this->type;
|
||||
$this->rule = $data["\x00*\x00rule"] ?? $this->rule;
|
||||
$this->singleton = $data["\x00*\x00singleton"] ?? $this->singleton;
|
||||
$this->mutexPool = $data["\x00*\x00mutexPool"] ?? $this->mutexPool;
|
||||
$this->mutexExpires = $data["\x00*\x00mutexExpires"] ?? $this->mutexExpires;
|
||||
$this->onOneServer = $data["\x00*\x00onOneServer"] ?? $this->onOneServer;
|
||||
$this->callback = $data["\x00*\x00callback"] ?? $this->callback;
|
||||
$this->memo = $data["\x00*\x00memo"] ?? $this->memo;
|
||||
$this->executeTime = $data["\x00*\x00executeTime"] ?? $this->executeTime;
|
||||
$this->enable = $data["\x00*\x00enable"] ?? $this->enable;
|
||||
$this->running = new Channel(1);
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
|
34
src/crontab/tests/CrontabTest.php
Normal file
34
src/crontab/tests/CrontabTest.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
namespace HyperfTest\Crontab;
|
||||
|
||||
use Hyperf\Crontab\Crontab;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class CrontabTest extends TestCase
|
||||
{
|
||||
public function testCrontab()
|
||||
{
|
||||
$crontab = clone ((new Crontab())->setName('test')->setRule('* * * * *')->setMemo('test')->setSingleton(true)->setMutexPool('default')->setOnOneServer(true)->setEnable(false));
|
||||
|
||||
$serialized = "O:22:\"Hyperf\\Crontab\\Crontab\":11:{s:7:\"\x00*\x00name\";s:4:\"test\";s:7:\"\x00*\x00type\";s:8:\"callback\";s:7:\"\x00*\x00rule\";s:9:\"* * * * *\";s:12:\"\x00*\x00singleton\";b:1;s:12:\"\x00*\x00mutexPool\";s:7:\"default\";s:15:\"\x00*\x00mutexExpires\";i:3600;s:14:\"\x00*\x00onOneServer\";b:1;s:11:\"\x00*\x00callback\";N;s:7:\"\x00*\x00memo\";s:4:\"test\";s:14:\"\x00*\x00executeTime\";N;s:9:\"\x00*\x00enable\";b:0;}";
|
||||
$this->assertEquals($serialized, serialize($crontab));
|
||||
|
||||
$unserializeCrontab = unserialize($serialized);
|
||||
|
||||
$this->assertEquals($crontab, $unserializeCrontab);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user