@@ -22,14 +22,20 @@ final class RequestMatcherPlugin implements Plugin
22
22
private $ requestMatcher ;
23
23
24
24
/**
25
- * @var Plugin
25
+ * @var null| Plugin
26
26
*/
27
- private $ delegatedPlugin ;
27
+ private $ successPlugin ;
28
28
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 )
30
35
{
31
36
$ this ->requestMatcher = $ requestMatcher ;
32
- $ this ->delegatedPlugin = $ delegatedPlugin ;
37
+ $ this ->successPlugin = $ delegateOnMatch ;
38
+ $ this ->failurePlugin = $ delegateOnNoMatch ;
33
39
}
34
40
35
41
/**
@@ -38,7 +44,11 @@ public function __construct(RequestMatcher $requestMatcher, Plugin $delegatedPlu
38
44
public function handleRequest (RequestInterface $ request , callable $ next , callable $ first ): Promise
39
45
{
40
46
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 );
42
52
}
43
53
44
54
return $ next ($ request );
0 commit comments