Skip to content

Commit

Permalink
Merge branch 'master' into 3.1-merge
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/service-governance-nacos/src/ClientFactory.php
  • Loading branch information
limingxinleo committed Jul 21, 2023
2 parents 3a0e3a2 + 30b170b commit 109c111
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions composer.json
Expand Up @@ -21,6 +21,9 @@
"php": ">=8.1",
"hyperf/contract": "~3.1.0"
},
"suggest": {
"ext-igbinary": "Required to use IgbinarySerializerPacker."
},
"autoload": {
"psr-4": {
"Hyperf\\Codec\\": "src/"
Expand Down
27 changes: 27 additions & 0 deletions src/Packer/IgbinarySerializerPacker.php
@@ -0,0 +1,27 @@
<?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 Hyperf\Codec\Packer;

use Hyperf\Contract\PackerInterface;

class IgbinarySerializerPacker implements PackerInterface
{
public function pack($data): string
{
return igbinary_serialize($data);
}

public function unpack(string $data)
{
return igbinary_unserialize($data);
}
}
38 changes: 38 additions & 0 deletions tests/Packer/IgbinarySerializerPackerTest.php
@@ -0,0 +1,38 @@
<?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\Codec\Packer;

use Exception;
use Hyperf\Codec\Packer\IgbinarySerializerPacker;
use PHPUnit\Framework\TestCase;

/**
* @internal
* @coversNothing
*/
class IgbinarySerializerPackerTest extends TestCase
{
public function testIgbinarySerializeAndUnserialize()
{
$packer = new IgbinarySerializerPacker();
$this->assertSame(igbinary_serialize(['id' => 1]), $packer->pack(['id' => 1]));
$this->assertSame(igbinary_serialize(123123), $packer->pack(123123));
$this->assertSame(['id' => 1], $packer->unpack(igbinary_serialize(['id' => 1])));
}

public function testIgbinaryUnserializeFailed()
{
$packer = new IgbinarySerializerPacker();
$this->expectException(Exception::class);
$packer->unpack('invalid binary string');
}
}

0 comments on commit 109c111

Please sign in to comment.