|
14 | 14 |
|
15 | 15 | // MARK: - RouterController
|
16 | 16 |
|
17 |
| -/// A type that represents part of your app's middleware and routes where their ``MiddlewareController/Input`` is |
18 |
| -/// ``Request`` and ``MiddlewareController/Output`` is ``Response``. |
19 |
| -/// |
| 17 | +/// A type that represents part of your app's middleware and routes |
| 18 | +/// |
20 | 19 | /// You create custom controllers by declaring types that conform to the `RouterController`
|
21 | 20 | /// protocol. Implement the required ``RouterController/body-swift.property`` computed
|
22 | 21 | /// property to provide the content for your custom controller.
|
|
31 | 30 | ///
|
32 | 31 | /// Assemble the controller's body by combining one or more of the built-in controllers or middleware.
|
33 | 32 | /// provided by Hummingbird, plus other custom controllers that you define, into a hierarchy of controllers.
|
34 |
| -public protocol RouterController<Context>: MiddlewareController where Body: RouterMiddleware<Context> { |
| 33 | +public protocol RouterController<Context> { |
35 | 34 | associatedtype Context
|
| 35 | + associatedtype Body: RouterMiddleware<Context> |
| 36 | + @MiddlewareFixedTypeBuilder<Request, Response, Context> var body: Body { get } |
| 37 | +} |
| 38 | + |
| 39 | + |
| 40 | +// MARK: MiddlewareFixedTypeBuilder + RouterController Builders |
| 41 | + |
| 42 | +extension MiddlewareFixedTypeBuilder { |
| 43 | + public static func buildExpression<C0: RouterController>(_ c0: C0) -> C0.Body where C0.Body.Input == Input, C0.Body.Output == Output, C0.Body.Context == Context { |
| 44 | + return c0.body |
| 45 | + } |
| 46 | + |
| 47 | + public static func buildBlock<C0: RouterController>(_ c0: C0) -> C0.Body { |
| 48 | + return c0.body |
| 49 | + } |
| 50 | + |
| 51 | + public static func buildPartialBlock<C0: RouterController>(first: C0) -> C0.Body { |
| 52 | + first.body |
| 53 | + } |
| 54 | + |
| 55 | + public static func buildPartialBlock<M0: MiddlewareProtocol, C0: RouterController>( |
| 56 | + accumulated m0: M0, |
| 57 | + next c0: C0 |
| 58 | + ) -> _Middleware2<M0, C0.Body> where M0.Input == C0.Body.Input, M0.Output == C0.Body.Output, M0.Context == C0.Body.Context { |
| 59 | + _Middleware2(m0, c0.body) |
| 60 | + } |
36 | 61 | }
|
0 commit comments