From e35c5f3f74707760e1ced52f8533121b8072feb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dezs=C5=91=20BICZ=C3=93?= Date: Thu, 3 May 2018 08:54:49 +0200 Subject: [PATCH] Only add path prefix if we did not yet add the prefix on this request --- CHANGELOG.md | 6 ++++++ src/Plugin/AddPathPlugin.php | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3031720..aa9039a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## 1.8 (unreleased) + +### Changed + +- AddPathPlugin no longer add prefix multiple times if a request is restarted - it now only adds the prefix if that request chain has not yet passed through the AddPathPlugin + ## 1.7.0 - 2017-11-30 ### Added diff --git a/src/Plugin/AddPathPlugin.php b/src/Plugin/AddPathPlugin.php index e24d61a..93ded1c 100644 --- a/src/Plugin/AddPathPlugin.php +++ b/src/Plugin/AddPathPlugin.php @@ -18,6 +18,13 @@ final class AddPathPlugin implements Plugin */ private $uri; + /** + * Stores identifiers of the already altered requests. + * + * @var array + */ + private $alteredRequests = []; + /** * @param UriInterface $uri */ @@ -39,9 +46,14 @@ public function __construct(UriInterface $uri) */ public function handleRequest(RequestInterface $request, callable $next, callable $first) { - $request = $request->withUri($request->getUri() - ->withPath($this->uri->getPath().$request->getUri()->getPath()) - ); + $identifier = spl_object_hash((object) $first); + + if (!array_key_exists($identifier, $this->alteredRequests)) { + $request = $request->withUri($request->getUri() + ->withPath($this->uri->getPath().$request->getUri()->getPath()) + ); + $this->alteredRequests[$identifier] = $identifier; + } return $next($request); }