1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Caridea |
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 2017-2018 LibreWorks contributors |
19
|
|
|
* @license Apache-2.0 |
20
|
|
|
*/ |
21
|
|
|
namespace Caridea\Dispatch\Middleware; |
22
|
|
|
|
23
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
24
|
|
|
use Psr\Http\Message\ResponseInterface; |
25
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
26
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Always returns an immutable ResponseInterface |
30
|
|
|
* |
31
|
|
|
* @copyright 2017-2018 LibreWorks contributors |
32
|
|
|
* @license Apache-2.0 |
33
|
|
|
*/ |
34
|
|
|
class Prototype implements MiddlewareInterface, RequestHandlerInterface |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @var \Psr\Http\Message\ResponseInterface |
38
|
|
|
*/ |
39
|
|
|
private $prototype; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Creates a new Prototype middleware |
43
|
|
|
* |
44
|
|
|
* @param \Psr\Http\Message\ResponseInterface $prototype The response prototype |
45
|
|
|
*/ |
46
|
1 |
|
public function __construct(ResponseInterface $prototype) |
47
|
|
|
{ |
48
|
1 |
|
$this->prototype = $prototype; |
49
|
1 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritDoc} |
53
|
|
|
*/ |
54
|
1 |
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
55
|
|
|
{ |
56
|
1 |
|
return $this->prototype; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritDoc} |
61
|
|
|
*/ |
62
|
1 |
|
public function handle(ServerRequestInterface $request): ResponseInterface |
63
|
|
|
{ |
64
|
1 |
|
return $this->prototype; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|