1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Tarantool Client package. |
5
|
|
|
* |
6
|
|
|
* (c) Eugene Leonovich <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Tarantool\Client\Packer; |
15
|
|
|
|
16
|
|
|
use Tarantool\Client\Keys; |
17
|
|
|
use Tarantool\Client\Request\Request; |
18
|
|
|
use Tarantool\Client\Response; |
19
|
|
|
|
20
|
|
|
final class PeclPacker implements Packer |
21
|
|
|
{ |
22
|
|
|
private $phpOnly; |
23
|
|
|
private $packer; |
24
|
|
|
|
25
|
138 |
|
public function __construct(bool $phpOnly = true) |
26
|
|
|
{ |
27
|
138 |
|
$this->phpOnly = $phpOnly; |
28
|
138 |
|
$this->packer = new \MessagePack($phpOnly); |
29
|
138 |
|
} |
30
|
|
|
|
31
|
114 |
|
public function pack(Request $request, int $sync) : string |
32
|
|
|
{ |
33
|
|
|
// @see https://github.com/msgpack/msgpack-php/issues/45 |
34
|
114 |
|
$packet = \pack('C*', 0x82, Keys::CODE, $request->getType(), Keys::SYNC). |
35
|
114 |
|
$this->packer->pack($sync). |
36
|
114 |
|
$this->packer->pack($request->getBody()); |
37
|
|
|
|
38
|
114 |
|
return PacketLength::pack(\strlen($packet)).$packet; |
39
|
|
|
} |
40
|
|
|
|
41
|
99 |
|
public function unpack(string $data) : Response |
42
|
|
|
{ |
43
|
|
|
// @see https://github.com/msgpack/msgpack-php/issues/139 |
44
|
|
|
// $unpacker = clone $this->unpacker; |
45
|
99 |
|
$unpacker = new \MessagePackUnpacker($this->phpOnly); |
|
|
|
|
46
|
99 |
|
$unpacker->feed($data); |
47
|
|
|
|
48
|
99 |
|
if (!$unpacker->execute()) { |
49
|
2 |
|
throw new \UnexpectedValueException('Unable to unpack response header.'); |
50
|
|
|
} |
51
|
|
|
|
52
|
97 |
|
return new Response($unpacker->data(), |
53
|
|
|
static function () use ($unpacker) { |
54
|
92 |
|
if (!$unpacker->execute()) { |
55
|
1 |
|
throw new \UnexpectedValueException('Unable to unpack response body.'); |
56
|
|
|
} |
57
|
|
|
|
58
|
91 |
|
$body = $unpacker->data(); |
59
|
|
|
|
60
|
|
|
// with PHP_ONLY = true an empty array |
61
|
|
|
// will be unpacked to stdClass |
62
|
91 |
|
return $body instanceof \stdClass |
63
|
|
|
? (array) $body |
64
|
91 |
|
: $body; |
65
|
97 |
|
} |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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