Total Complexity | 5 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
9 | class RequestTimeMiddleware |
||
10 | { |
||
11 | /** @var \EightPoints\Bundle\GuzzleBundle\DataCollector\HttpDataCollector */ |
||
12 | private $dataCollector; |
||
13 | |||
14 | /** |
||
15 | * @param \EightPoints\Bundle\GuzzleBundle\DataCollector\HttpDataCollector $dataCollector |
||
16 | */ |
||
17 | public function __construct(HttpDataCollector $dataCollector) |
||
18 | { |
||
19 | $this->dataCollector = $dataCollector; |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @param callable $handler |
||
24 | * |
||
25 | * @return \Closure |
||
26 | */ |
||
27 | public function __invoke(callable $handler) : \Closure |
||
28 | { |
||
29 | return function ( |
||
30 | RequestInterface $request, |
||
31 | array $options |
||
32 | ) use ($handler) { |
||
33 | $options['on_stats'] = $this->getOnStatsCallback(isset($options['on_stats']) ? $options['on_stats'] : null); |
||
34 | |||
35 | // Continue the handler chain. |
||
36 | return $handler($request, $options); |
||
37 | }; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Create callback for on_stats options. |
||
42 | * If request has on_stats option, it will be called inside of this callback. |
||
43 | * |
||
44 | * @param null|\Closure $initialOnStats |
||
45 | * |
||
46 | * @return \Closure |
||
47 | */ |
||
48 | protected function getOnStatsCallback(\Closure $initialOnStats = null) : \Closure |
||
56 | }; |
||
57 | } |
||
58 | } |
||
59 |