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
|
|
|
namespace KleijnWeb\PhpApi\Middleware\Util; |
9
|
|
|
|
10
|
|
|
use KleijnWeb\PhpApi\Descriptions\Description\Description; |
11
|
|
|
use KleijnWeb\PhpApi\Descriptions\Description\Operation; |
12
|
|
|
use KleijnWeb\PhpApi\Descriptions\Description\Path; |
13
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
14
|
|
|
|
15
|
|
|
class Meta |
16
|
|
|
{ |
17
|
|
|
const NAME = 'php-api.attribute'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Description |
21
|
|
|
*/ |
22
|
|
|
private $description; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var Operation |
26
|
|
|
*/ |
27
|
|
|
private $operation; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Path |
31
|
|
|
*/ |
32
|
|
|
private $path; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param Description $description |
36
|
|
|
* @param Operation $operation |
37
|
|
|
* @param Path $path |
38
|
|
|
*/ |
39
|
|
|
public function __construct(Description $description, Operation $operation, Path $path) |
40
|
|
|
{ |
41
|
|
|
$this->description = $description; |
42
|
|
|
$this->operation = $operation; |
43
|
|
|
$this->path = $path; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param ServerRequestInterface $request |
48
|
|
|
* @return Meta |
49
|
|
|
*/ |
50
|
|
|
public static function getFromRequest(ServerRequestInterface $request): Meta |
51
|
|
|
{ |
52
|
|
|
return $request->getAttribute(self::NAME); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param ServerRequestInterface $request |
57
|
|
|
* @param Description $description |
58
|
|
|
* @param Operation $operation |
59
|
|
|
* @param Path $path |
60
|
|
|
* @return ServerRequestInterface |
61
|
|
|
*/ |
62
|
|
|
public static function requestWith( |
63
|
|
|
ServerRequestInterface $request, |
64
|
|
|
Description $description, |
65
|
|
|
Operation $operation, |
66
|
|
|
Path $path |
67
|
|
|
): ServerRequestInterface |
68
|
|
|
{ |
69
|
|
|
return $request->withAttribute(self::NAME, new self($description, $operation, $path)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return Description |
74
|
|
|
*/ |
75
|
|
|
public function getDescription(): Description |
76
|
|
|
{ |
77
|
|
|
return $this->description; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return Operation |
82
|
|
|
*/ |
83
|
|
|
public function getOperation(): Operation |
84
|
|
|
{ |
85
|
|
|
return $this->operation; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return Path |
90
|
|
|
*/ |
91
|
|
|
public function getPath(): Path |
92
|
|
|
{ |
93
|
|
|
return $this->path; |
94
|
|
|
} |
95
|
|
|
} |