Skip to content

Commit 662beeb

Browse files
alexandrupetcumihaileu
authored andcommitted
Fix for using multiple middlware in the same time (#7)
fixing multiple middlewares on key: on_stats
1 parent cd099db commit 662beeb

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "emag-tech-labs/guzzle-middleware",
33
"description": "Guzzle middlewares",
4-
"version": "0.2.7",
4+
"version": "0.2.8",
55
"license": "GPL-3.0-only",
66
"authors": [
77
{

src/GuzzleMiddleware/HttpCodeProfiler.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ public function __construct(StatsDataInterface $statsdService)
2626
public function __invoke(callable $handler): callable
2727
{
2828
return function (RequestInterface $request, array $options) use ($handler) {
29-
$options['on_stats'] = function (TransferStats $stats) {
29+
$onStats = $options['on_stats'] ?? null;
30+
31+
$options['on_stats'] = function (TransferStats $stats) use ($onStats) {
32+
if (is_callable($onStats)) {
33+
$onStats($stats);
34+
}
35+
3036
$this->startProfiling($stats);
3137
};
3238

src/GuzzleMiddleware/TimingProfiler.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ public function __construct(StatsDataInterface $statsdService)
2525
public function __invoke(callable $handler): callable
2626
{
2727
return function (RequestInterface $request, array $options) use ($handler) {
28-
$options['on_stats'] = function (TransferStats $stats) {
28+
$onStats = $options['on_stats'] ?? null;
29+
30+
$options['on_stats'] = function (TransferStats $stats) use ($onStats) {
31+
if (is_callable($onStats)) {
32+
$onStats($stats);
33+
}
34+
2935
$this->startProfiling($stats);
3036
};
3137

0 commit comments

Comments
 (0)