Skip to content

Commit

Permalink
Fix for using multiple middlware in the same time (#7)
Browse files Browse the repository at this point in the history
fixing multiple middlewares on key: on_stats
  • Loading branch information
alexandrupetcu authored and mihaileu committed Dec 17, 2019
1 parent cd099db commit 662beeb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "emag-tech-labs/guzzle-middleware",
"description": "Guzzle middlewares",
"version": "0.2.7",
"version": "0.2.8",
"license": "GPL-3.0-only",
"authors": [
{
Expand Down
8 changes: 7 additions & 1 deletion src/GuzzleMiddleware/HttpCodeProfiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ public function __construct(StatsDataInterface $statsdService)
public function __invoke(callable $handler): callable
{
return function (RequestInterface $request, array $options) use ($handler) {
$options['on_stats'] = function (TransferStats $stats) {
$onStats = $options['on_stats'] ?? null;

$options['on_stats'] = function (TransferStats $stats) use ($onStats) {
if (is_callable($onStats)) {
$onStats($stats);
}

$this->startProfiling($stats);
};

Expand Down
8 changes: 7 additions & 1 deletion src/GuzzleMiddleware/TimingProfiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ public function __construct(StatsDataInterface $statsdService)
public function __invoke(callable $handler): callable
{
return function (RequestInterface $request, array $options) use ($handler) {
$options['on_stats'] = function (TransferStats $stats) {
$onStats = $options['on_stats'] ?? null;

$options['on_stats'] = function (TransferStats $stats) use ($onStats) {
if (is_callable($onStats)) {
$onStats($stats);
}

$this->startProfiling($stats);
};

Expand Down

0 comments on commit 662beeb

Please sign in to comment.