| Total Complexity | 7 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 16 | class ContextPacking implements Layered |
||
| 17 | { |
||
| 18 | public const HTTP_HEADER = 'X-Trans-CTX'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var array |
||
| 22 | */ |
||
| 23 | protected $keys = []; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param string ...$allowed |
||
| 27 | */ |
||
| 28 | public function keys(string ...$allowed) : void |
||
| 31 | } |
||
| 32 | |||
| 33 | public function inbound($request, Context $ctx) |
||
| 34 | { |
||
| 35 | /** |
||
| 36 | * @var Request $request |
||
| 37 | */ |
||
| 38 | |||
| 39 | $attachments = []; |
||
| 40 | |||
| 41 | foreach ($this->keys as $key) { |
||
| 42 | $ctx->has($key) && $attachments[$key] = $ctx->get($key); |
||
| 43 | } |
||
| 44 | |||
| 45 | if ($attachments) { |
||
| 46 | $dat = base64_encode(json_encode($attachments, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); |
||
| 47 | $request->opsExtra('h-headers', static function (&$headers) use ($dat) { |
||
| 48 | $headers[self::HTTP_HEADER] = $dat; |
||
| 49 | }); |
||
| 50 | } |
||
| 51 | |||
| 52 | return $request; |
||
| 53 | } |
||
| 54 | |||
| 55 | public function outbound($response, Context $ctx) |
||
| 56 | { |
||
| 57 | return $response; |
||
| 58 | } |
||
| 59 | |||
| 60 | public function exception(Throwable $e, Context $ctx) |
||
| 63 | } |
||
| 64 | } |
||
| 65 |