Skip to content

Commit da5f833

Browse files
committed
Adding docs
1 parent 762ac45 commit da5f833

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

docs/index.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,49 @@
1-
# Dispatcher
1+
# Documentation
22

33
## Dispatcher Middleware
44

5+
The middleware inspects the requests using the extractor and if the result of the extraction was something else than `null`, it will pass the result on to the dispatcher. The dispatcher will try to dispatch it and implements the actual dispatching logic.
6+
7+
```php
8+
new DispatcherMiddleware(
9+
new RequestAttributeExtractor(),
10+
new Dispatcher($psrContainer)
11+
);
12+
```
13+
14+
### Passing the handler through
15+
16+
If you want to pass a route object or anything else from a middleware running before the dispatcher, you'll need to put the data into a request attribute.
17+
18+
The RequestAttributeExtractor will check by default for a `handler` attribute in the request object.
19+
20+
So for example in your routing middleware, if the router resolves to a route object, then pass it along:
21+
22+
```
23+
$request = $request->withAttribute('handler', $route);
24+
```
25+
526
## Handler Extractors
627

728
They will extract a handler from the request object.
829

930
To implement your own extractor you'll have to implement the [HandlerExtractorInterface](../src/Infrastructure/Http/Dispatcher/HandlerExtractorInterface.php).
1031

11-
This library comes with a simple [RequestAttributeExtractor](../src/Infrastructure/Http/Dispatcher/RequestAttributeExtractor.php) that will check the request for an attribute, if it is not present NULL will be returned.
32+
This library comes with a simple [RequestAttributeExtractor](../src/Infrastructure/Http/Dispatcher/RequestAttributeExtractor.php) that will check the request for an attribute, if it is not present `null` will be returned.
1233

1334
## Dispatchers
35+
36+
Dispatchers take the handler and try to execute it depending what it is. The library comes with a dispatcher that will resolve `callable` and `string` handlers. The string must be of the format `<prefix>.<controller-or-handler>@<action>`.
37+
38+
* `<prefix>` is optional but useful for plugins or extensions that reside in another namespace.
39+
* `<controller-or-handler>` is the actual class.
40+
* `<action>` is the method to call on the class. It is optional.
41+
42+
You can change the separators via setter methods on the dispatcher object.
43+
If you want to implement your own dispatcher you'll have to implement the [DispatcherInterface](../src/Infrastructure/Http/Dispatcher/DispatcherInterface.php).
44+
45+
The dispatcher that comes with the library uses a PSR container to resolve the actual controller or request handler class.
46+
47+
```php
48+
new Dispatcher($psrContainer)
49+
```

0 commit comments

Comments
 (0)