| @@ 86-115 (lines=30) @@ | ||
| 83 | * @param Request $request |
|
| 84 | * @return Request |
|
| 85 | */ |
|
| 86 | private function processInboundLayers(Request $request) |
|
| 87 | { |
|
| 88 | $result = $request; |
|
| 89 | ||
| 90 | // Pass through layers inwards |
|
| 91 | foreach ($this->layers as $priority => $layers) { |
|
| 92 | foreach ($layers as $layerName => $layer) { |
|
| 93 | ||
| 94 | if (!($layer instanceof InboundLayerInterface)) { |
|
| 95 | continue; |
|
| 96 | } |
|
| 97 | ||
| 98 | $result = $layer->in($result); |
|
| 99 | ||
| 100 | // If the layer produces a response, no more inbound layers may execute |
|
| 101 | if ($result instanceof Response) { |
|
| 102 | return $result; |
|
| 103 | } |
|
| 104 | ||
| 105 | if (!$result instanceof Request) { |
|
| 106 | throw new \RuntimeException( |
|
| 107 | 'Each inbound layer of the chain must produce a Request or Response type. ' . |
|
| 108 | 'The "' . $layerName . '" layer returned ' . gettype($request) . '.' |
|
| 109 | ); |
|
| 110 | } |
|
| 111 | } |
|
| 112 | } |
|
| 113 | ||
| 114 | return $result; |
|
| 115 | } |
|
| 116 | ||
| 117 | /** |
|
| 118 | * @param Response $response |
|
| @@ 121-144 (lines=24) @@ | ||
| 118 | * @param Response $response |
|
| 119 | * @return Response |
|
| 120 | */ |
|
| 121 | private function processOutboundLayers(Response $response) |
|
| 122 | { |
|
| 123 | $result = $response; |
|
| 124 | ||
| 125 | foreach ($this->layers as $priority => $layers) { |
|
| 126 | foreach ($layers as $layerName => $layer) { |
|
| 127 | ||
| 128 | if (!($layer instanceof OutboundLayerInterface)) { |
|
| 129 | continue; |
|
| 130 | } |
|
| 131 | ||
| 132 | $result = $layer->out($result); |
|
| 133 | ||
| 134 | if (!$result instanceof Response) { |
|
| 135 | throw new \RuntimeException( |
|
| 136 | 'Each outbound layer of the chain must produce a Response type. ' . |
|
| 137 | 'The "' . $layerName . '" layer returned ' . gettype($response) . '.' |
|
| 138 | ); |
|
| 139 | } |
|
| 140 | } |
|
| 141 | } |
|
| 142 | ||
| 143 | return $result; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * Get the layers currently added to this LayerChain, keyed by priority group. |
|