1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Minotaur |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
7
|
|
|
* use this file except in compliance with the License. You may obtain a copy of |
8
|
|
|
* the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
14
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
15
|
|
|
* License for the specific language governing permissions and limitations under |
16
|
|
|
* the License. |
17
|
|
|
* |
18
|
|
|
* @copyright 2015-2017 Appertly |
19
|
|
|
* @license Apache-2.0 |
20
|
|
|
*/ |
21
|
|
|
namespace Minotaur\Route; |
22
|
|
|
|
23
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request; |
24
|
|
|
use Psr\Http\Message\ResponseInterface as Response; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Collects any Route plugins and runs them, returning the response. |
28
|
|
|
*/ |
29
|
|
|
class Runner |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var \Relay\Relay The nested Runner |
33
|
|
|
*/ |
34
|
|
|
private $runner; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Creates a new Runner. |
38
|
|
|
* |
39
|
|
|
* @param $c - The container |
40
|
|
|
*/ |
41
|
1 |
|
public function __construct(\Caridea\Container\Container $c) |
42
|
|
|
{ |
43
|
1 |
|
$plugins = $c->getByType(Plugin::class); |
44
|
1 |
|
usort($plugins, function ($a, $b) { |
45
|
1 |
|
return $b->getPriority() <=> $a->getPriority(); |
46
|
1 |
|
}); |
47
|
1 |
|
$relayBuilder = new \Relay\RelayBuilder(); |
48
|
1 |
|
$this->runner = $relayBuilder->newInstance($plugins); |
49
|
1 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Middleware request–response handling. |
53
|
|
|
* |
54
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request The server request |
55
|
|
|
* @param \Psr\Http\Message\ResponseInterface $response The response |
56
|
|
|
* @return \Psr\Http\Message\ResponseInterface The response |
57
|
|
|
*/ |
58
|
1 |
|
public function run(Request $request, Response $response): Response |
59
|
|
|
{ |
60
|
1 |
|
$relay = $this->runner; |
61
|
1 |
|
return $relay($request, $response); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|