1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Tarantool Client package. |
7
|
|
|
* |
8
|
|
|
* (c) Eugene Leonovich <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Tarantool\Client\Packer; |
15
|
|
|
|
16
|
|
|
use Tarantool\Client\Exception\UnpackingFailed; |
17
|
|
|
use Tarantool\Client\IProto; |
18
|
|
|
use Tarantool\Client\Request\Request; |
19
|
|
|
use Tarantool\Client\Response; |
20
|
|
|
|
21
|
|
|
final class PeclPacker implements Packer |
22
|
|
|
{ |
23
|
|
|
private $packer; |
24
|
|
|
private $unpacker; |
25
|
|
|
|
26
|
131 |
|
public function __construct(bool $phpOnly = true) |
27
|
|
|
{ |
28
|
131 |
|
$this->packer = new \MessagePack($phpOnly); |
29
|
131 |
|
$this->unpacker = new \MessagePackUnpacker($phpOnly); |
|
|
|
|
30
|
131 |
|
} |
31
|
|
|
|
32
|
106 |
|
public function pack(Request $request, ?int $sync = null) : string |
33
|
|
|
{ |
34
|
|
|
// @see https://github.com/msgpack/msgpack-php/issues/45 |
35
|
106 |
|
$content = \pack('C*', 0x82, IProto::CODE, $request->getType(), IProto::SYNC). |
36
|
106 |
|
$this->packer->pack($sync ?: 0). |
37
|
106 |
|
$this->packer->pack($request->getBody()); |
38
|
|
|
|
39
|
106 |
|
return PackUtils::packLength(\strlen($content)).$content; |
40
|
|
|
} |
41
|
|
|
|
42
|
105 |
|
public function unpack(string $data) : Response |
43
|
|
|
{ |
44
|
105 |
|
$this->unpacker->feed($data); |
45
|
|
|
|
46
|
105 |
|
if (!$this->unpacker->execute()) { |
47
|
|
|
throw UnpackingFailed::invalidResponse(); |
48
|
|
|
} |
49
|
|
|
|
50
|
105 |
|
$header = $this->unpacker->data(); |
51
|
105 |
|
if (!\is_array($header)) { |
52
|
2 |
|
throw UnpackingFailed::invalidResponse(); |
53
|
|
|
} |
54
|
|
|
|
55
|
103 |
|
if (!$this->unpacker->execute()) { |
56
|
|
|
throw UnpackingFailed::invalidResponse(); |
57
|
|
|
} |
58
|
|
|
|
59
|
103 |
|
$body = $this->unpacker->data(); |
60
|
103 |
|
if (\is_array($body)) { |
61
|
101 |
|
return new Response($header, $body); |
62
|
|
|
} |
63
|
3 |
|
if ($body instanceof \stdClass) { |
64
|
3 |
|
return new Response($header, (array) $body); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
throw UnpackingFailed::invalidResponse(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths