Skip to content

Commit 5c220bd

Browse files
committed
Add else option to the RequestMatcherPlugin
1 parent 32644df commit 5c220bd

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/Plugin/RequestMatcherPlugin.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ final class RequestMatcherPlugin implements Plugin
2222
private $requestMatcher;
2323

2424
/**
25-
* @var Plugin
25+
* @var null|Plugin
2626
*/
27-
private $delegatedPlugin;
27+
private $successPlugin;
2828

29-
public function __construct(RequestMatcher $requestMatcher, Plugin $delegatedPlugin)
29+
/**
30+
* @var null|Plugin
31+
*/
32+
private $failurePlugin;
33+
34+
public function __construct(RequestMatcher $requestMatcher, ?Plugin $delegateOnMatch, Plugin $delegateOnNoMatch = null)
3035
{
3136
$this->requestMatcher = $requestMatcher;
32-
$this->delegatedPlugin = $delegatedPlugin;
37+
$this->successPlugin = $delegateOnMatch;
38+
$this->failurePlugin = $delegateOnNoMatch;
3339
}
3440

3541
/**
@@ -38,7 +44,11 @@ public function __construct(RequestMatcher $requestMatcher, Plugin $delegatedPlu
3844
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
3945
{
4046
if ($this->requestMatcher->matches($request)) {
41-
return $this->delegatedPlugin->handleRequest($request, $next, $first);
47+
if (null !== $this->successPlugin) {
48+
return $this->successPlugin->handleRequest($request, $next, $first);
49+
}
50+
} elseif (null !== $this->failurePlugin) {
51+
return $this->failurePlugin->handleRequest($request, $next, $first);
4252
}
4353

4454
return $next($request);

0 commit comments

Comments
 (0)