-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPaths.php
More file actions
75 lines (57 loc) 路 1.46 KB
/
Copy pathPaths.php
File metadata and controls
75 lines (57 loc) 路 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php declare(strict_types = 1);
namespace Contributte\OpenApi\Schema;
class Paths
{
/** @var PathItem[]|Reference[] */
private array $paths = [];
private ?VendorExtensions $vendorExtensions = null;
/**
* @param mixed[] $data
*/
public static function fromArray(array $data): Paths
{
$paths = new Paths();
foreach ($data as $path => $pathItemData) {
if (str_starts_with((string) $path, 'x-')) {
continue;
}
if (isset($pathItemData['$ref'])) {
$paths->setPathItem($path, Reference::fromArray($pathItemData));
} else {
$paths->setPathItem($path, PathItem::fromArray($pathItemData));
}
}
$paths->setVendorExtensions(VendorExtensions::fromArray($data));
return $paths;
}
/**
* @return mixed[]
*/
public function toArray(): array
{
$data = [];
foreach ($this->paths as $key => $pathItem) {
$data[$key] = $pathItem->toArray();
}
if ($this->vendorExtensions !== null) {
$data = array_merge($data, $this->vendorExtensions->toArray());
}
return $data;
}
public function setPathItem(string $path, PathItem|Reference $pathItem): void
{
$this->paths[$path] = $pathItem;
}
public function getPath(string $path): PathItem|Reference|null
{
return $this->paths[$path] ?? null;
}
public function getVendorExtensions(): ?VendorExtensions
{
return $this->vendorExtensions;
}
public function setVendorExtensions(?VendorExtensions $vendorExtensions): void
{
$this->vendorExtensions = $vendorExtensions;
}
}