Total Complexity | 5 |
Total Lines | 72 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
12 | final class Pipeline |
||
13 | { |
||
14 | /** @var callable */ |
||
15 | private $middleware; |
||
16 | |||
17 | /** @var ServerRequestInterface|null */ |
||
18 | private $request; |
||
19 | |||
20 | /** |
||
21 | * Constructs an instance of Pipeline. Takes the middleware that enables Shoot's functionality. Middleware is |
||
22 | * executed in the same order as given. |
||
23 | * |
||
24 | * @param MiddlewareInterface[] $middleware |
||
25 | */ |
||
26 | 20 | public function __construct(array $middleware = []) |
|
27 | { |
||
28 | 20 | $this->middleware = $this->chainMiddleware($middleware); |
|
29 | 20 | } |
|
30 | |||
31 | /** |
||
32 | * Sets the HTTP request context while executing the given callback. Any templates should be rendered within this |
||
33 | * callback. Returns the result returned by the callback (if any). |
||
34 | * |
||
35 | * @param ServerRequestInterface $request |
||
36 | * @param callable $callback |
||
37 | * |
||
38 | * @return mixed |
||
39 | */ |
||
40 | 17 | public function withRequest(ServerRequestInterface $request, callable $callback) |
|
41 | { |
||
42 | try { |
||
43 | 17 | $this->request = $request; |
|
44 | |||
45 | 17 | return $callback(); |
|
46 | } finally { |
||
47 | 17 | $this->request = null; |
|
48 | } |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param View $view |
||
53 | * |
||
54 | * @return void |
||
55 | * |
||
56 | * @internal |
||
57 | */ |
||
58 | 17 | public function process(View $view): void |
|
65 | 14 | } |
|
66 | |||
67 | /** |
||
68 | * @param MiddlewareInterface[] $middleware |
||
69 | * |
||
70 | * @return callable |
||
71 | */ |
||
72 | 20 | private function chainMiddleware(array $middleware): callable |
|
84 | 20 | }); |
|
85 | } |
||
87 |