1
1
# Responders
2
2
3
- A responder takes a request and returns a response. It's a simple concept that can be implemented in many ways, of
4
- which this package only provides the foundation.
3
+ A responder takes a request and returns a response.
4
+ It is a simple concept that can be implemented in many ways,
5
+ of which this package only provides the foundation.
5
6
6
- This package only provides an implementation that delegates the response to a matching responder found by a provider.
7
+ This package only provides an implementation that delegates the response to a matching responder
8
+ found by a provider.
7
9
The package [ ICanBoogie/Routing] [ ] provides more exciting implementations.
8
10
9
11
``` php
@@ -22,10 +24,10 @@ $response = $responder->respond($request);
22
24
23
25
[ WithRecovery] [ ] decorates another responder to provide an exception recovery mechanism.
24
26
25
- The exception thrown by the responder is caught and a [ RecoverEvent] [ ] is emitted. Third parties can
26
- use that event to provide a response or replace the exception.
27
+ The exception thrown by the responder is caught, and a [ RecoverEvent] [ ] is emitted.
28
+ Third parties can use that event to provide a response or replace the exception.
27
29
28
- The following example demonstrate how to decorate a responder:
30
+ The following example demonstrates how to decorate a responder:
29
31
30
32
``` php
31
33
<?php
@@ -37,7 +39,7 @@ namespace ICanBoogie\HTTP;
37
39
$responder_with_recovery = new Responder\WithRecovery($responder);
38
40
```
39
41
40
- The following example demonstrate how to recover [ NotFound] [ ] exceptions:
42
+ The following example demonstrates how to recover [ NotFound] [ ] exceptions:
41
43
42
44
``` php
43
45
<?php
@@ -60,7 +62,7 @@ $events->attach(function (RecoverEvent $event, NotFound $target) {
60
62
$responder_with_recovery = new Responder\WithRecovery($responder);
61
63
```
62
64
63
- Alternatively you can provide another exception to throw instead:
65
+ Alternatively, you can provide another exception to throw instead:
64
66
65
67
``` php
66
68
<?php
@@ -81,17 +83,17 @@ $responder_with_recovery = new Responder\WithRecovery($responder);
81
83
```
82
84
83
85
84
- ## Events around respond
86
+ ## Events around respond()
85
87
86
- [ WithEvents ] [ ] decorates another responder to emit events around the ` respond() ` method.
88
+ [ WithEvent ] [ ] decorates another responder to emit events around the ` respond() ` method.
87
89
88
- - [ BeforeRespondEvent] [ ] is emitted before the ` respond() ` method. Listeners can use the event to
89
- alter the request or provide a response. If a response is provided the ` respond() ` method is * not *
90
- invoked.
91
- - [ RespondEvent] [ ] is emitted after the ` respond() ` method. Listeners can use the event to alter the
92
- response.
90
+ 1 . [ BeforeRespondEvent] [ ] is emitted before the ` respond() ` method.
91
+ Listeners can use the event to alter the request or provide a response.
92
+ If a response is provided the ` respond() ` method is NOT invoked.
93
+ 2 . [ RespondEvent] [ ] is emitted after the ` respond() ` method.
94
+ Listeners can use the event to alter the response.
93
95
94
- The following example demonstrate how to decorate a responder:
96
+ The following example demonstrates how to decorate a responder:
95
97
96
98
``` php
97
99
<?php
@@ -103,7 +105,7 @@ namespace ICanBoogie\HTTP;
103
105
$responder_with_events = new Responder\WithEvents($responder);
104
106
```
105
107
106
- The following example demonstrate how to attach listeners:
108
+ The following example demonstrates how to attach listeners:
107
109
108
110
``` php
109
111
<?php
@@ -128,3 +130,6 @@ $events->attach(function (RespondEvent $event) {
128
130
[ WithRecovery ] : ../lib/Responder/WithRecovery.php
129
131
[ RecoverEvent ] : ../lib/RecoverEvent.php
130
132
[ NotFound ] : ../lib/NotFound.php
133
+ [ WithEvent ] : ../lib/Responder/WithEvent
134
+ [ BeforeRespondEvent ] : ../lib/Responder/WithEvent/BeforeRespondEvent.php
135
+ [ RespondEvent ] : ../lib/Responder/WithEvent/RespondEvent.php
0 commit comments