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); }