|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the KleijnWeb\PhpApi\Descriptions package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace KleijnWeb\PhpApi\Middleware; |
|
10
|
|
|
|
|
11
|
|
|
use KleijnWeb\PhpApi\Descriptions\Description\Description; |
|
12
|
|
|
use KleijnWeb\PhpApi\Descriptions\Description\Operation; |
|
13
|
|
|
use KleijnWeb\PhpApi\Descriptions\Description\Path; |
|
14
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
15
|
|
|
|
|
16
|
|
|
class Meta |
|
17
|
|
|
{ |
|
18
|
|
|
const NAME = 'php-api.attribute'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var Description |
|
22
|
|
|
*/ |
|
23
|
|
|
private $description; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var Operation |
|
27
|
|
|
*/ |
|
28
|
|
|
private $operation; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var Path |
|
32
|
|
|
*/ |
|
33
|
|
|
private $path; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param Description $description |
|
37
|
|
|
* @param Operation $operation |
|
38
|
|
|
* @param Path $path |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(Description $description, Operation $operation, Path $path) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->description = $description; |
|
43
|
|
|
$this->operation = $operation; |
|
44
|
|
|
$this->path = $path; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param ServerRequestInterface $request |
|
49
|
|
|
* @return Meta |
|
50
|
|
|
*/ |
|
51
|
|
|
public static function getFromRequest(ServerRequestInterface $request): Meta |
|
52
|
|
|
{ |
|
53
|
|
|
return $request->getAttribute(self::NAME); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param ServerRequestInterface $request |
|
58
|
|
|
* @param Description $description |
|
59
|
|
|
* @param Operation $operation |
|
60
|
|
|
* @param Path $path |
|
61
|
|
|
* @return ServerRequestInterface |
|
62
|
|
|
*/ |
|
63
|
|
|
public static function requestWith( |
|
64
|
|
|
ServerRequestInterface $request, |
|
65
|
|
|
Description $description, |
|
66
|
|
|
Operation $operation, |
|
67
|
|
|
Path $path |
|
68
|
|
|
): ServerRequestInterface |
|
69
|
|
|
{ |
|
70
|
|
|
return $request->withAttribute(self::NAME, new self($description, $operation, $path)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return Description |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getDescription(): Description |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->description; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return Operation |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getOperation(): Operation |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->operation; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return Path |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getPath(): Path |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->path; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|