@@ -11,127 +11,127 @@ |
||
11 | 11 | |
12 | 12 | class Responses implements Arrayable, \Iterator |
13 | 13 | { |
14 | - use ExtensionPart; |
|
15 | - |
|
16 | - /** @var Map */ |
|
17 | - private $responses; |
|
18 | - |
|
19 | - public function __construct($contents = []) |
|
20 | - { |
|
21 | - $this->parse($contents === null ? [] : $contents); |
|
22 | - } |
|
23 | - |
|
24 | - private function parse($contents) |
|
25 | - { |
|
26 | - $data = CollectionUtils::toMap($contents); |
|
27 | - |
|
28 | - // responses |
|
29 | - $this->responses = new Map(); |
|
30 | - foreach ($data as $r => $response) { |
|
31 | - if (!Text::create($r)->startsWith('x-')) { |
|
32 | - $this->responses->set($r, new Response($r, $response)); |
|
33 | - } |
|
34 | - } |
|
35 | - |
|
36 | - // extensions |
|
37 | - $this->parseExtensions($data); |
|
38 | - } |
|
39 | - |
|
40 | - public function toArray() |
|
41 | - { |
|
42 | - $responses = clone $this->responses; |
|
43 | - $responses->setAll($this->getExtensions()); |
|
44 | - |
|
45 | - return $responses->toArray(); |
|
46 | - } |
|
47 | - |
|
48 | - public function size() |
|
49 | - { |
|
50 | - return $this->responses->size(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Returns whether the given response exists. |
|
55 | - * |
|
56 | - * @param string $code |
|
57 | - * |
|
58 | - * @return bool |
|
59 | - */ |
|
60 | - public function has($code) |
|
61 | - { |
|
62 | - return $this->responses->has($code); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Returns whether the given response exists. |
|
67 | - * |
|
68 | - * @param Response $response |
|
69 | - * |
|
70 | - * @return bool |
|
71 | - */ |
|
72 | - public function contains(Response $response) |
|
73 | - { |
|
74 | - return $this->responses->contains($response); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Returns the reponse info for the given code. |
|
79 | - * |
|
80 | - * @param string $code |
|
81 | - * |
|
82 | - * @return Response |
|
83 | - */ |
|
84 | - public function get($code) |
|
85 | - { |
|
86 | - if (!$this->responses->has($code)) { |
|
87 | - $this->responses->set($code, new Response($code)); |
|
88 | - } |
|
89 | - |
|
90 | - return $this->responses->get($code); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Sets the response. |
|
95 | - * |
|
96 | - * @param Response $code |
|
97 | - */ |
|
98 | - public function add(Response $response) |
|
99 | - { |
|
100 | - $this->responses->set($response->getCode(), $response); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Removes the given repsonse. |
|
105 | - * |
|
106 | - * @param string $code |
|
107 | - */ |
|
108 | - public function remove($code) |
|
109 | - { |
|
110 | - $this->responses->remove($code); |
|
111 | - } |
|
112 | - |
|
113 | - public function current() |
|
114 | - { |
|
115 | - return $this->responses->current(); |
|
116 | - } |
|
117 | - |
|
118 | - public function key() |
|
119 | - { |
|
120 | - return $this->responses->key(); |
|
121 | - } |
|
122 | - |
|
123 | - public function next() |
|
124 | - { |
|
125 | - return $this->responses->next(); |
|
126 | - } |
|
127 | - |
|
128 | - public function rewind() |
|
129 | - { |
|
130 | - return $this->responses->rewind(); |
|
131 | - } |
|
132 | - |
|
133 | - public function valid() |
|
134 | - { |
|
135 | - return $this->responses->valid(); |
|
136 | - } |
|
14 | + use ExtensionPart; |
|
15 | + |
|
16 | + /** @var Map */ |
|
17 | + private $responses; |
|
18 | + |
|
19 | + public function __construct($contents = []) |
|
20 | + { |
|
21 | + $this->parse($contents === null ? [] : $contents); |
|
22 | + } |
|
23 | + |
|
24 | + private function parse($contents) |
|
25 | + { |
|
26 | + $data = CollectionUtils::toMap($contents); |
|
27 | + |
|
28 | + // responses |
|
29 | + $this->responses = new Map(); |
|
30 | + foreach ($data as $r => $response) { |
|
31 | + if (!Text::create($r)->startsWith('x-')) { |
|
32 | + $this->responses->set($r, new Response($r, $response)); |
|
33 | + } |
|
34 | + } |
|
35 | + |
|
36 | + // extensions |
|
37 | + $this->parseExtensions($data); |
|
38 | + } |
|
39 | + |
|
40 | + public function toArray() |
|
41 | + { |
|
42 | + $responses = clone $this->responses; |
|
43 | + $responses->setAll($this->getExtensions()); |
|
44 | + |
|
45 | + return $responses->toArray(); |
|
46 | + } |
|
47 | + |
|
48 | + public function size() |
|
49 | + { |
|
50 | + return $this->responses->size(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Returns whether the given response exists. |
|
55 | + * |
|
56 | + * @param string $code |
|
57 | + * |
|
58 | + * @return bool |
|
59 | + */ |
|
60 | + public function has($code) |
|
61 | + { |
|
62 | + return $this->responses->has($code); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Returns whether the given response exists. |
|
67 | + * |
|
68 | + * @param Response $response |
|
69 | + * |
|
70 | + * @return bool |
|
71 | + */ |
|
72 | + public function contains(Response $response) |
|
73 | + { |
|
74 | + return $this->responses->contains($response); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Returns the reponse info for the given code. |
|
79 | + * |
|
80 | + * @param string $code |
|
81 | + * |
|
82 | + * @return Response |
|
83 | + */ |
|
84 | + public function get($code) |
|
85 | + { |
|
86 | + if (!$this->responses->has($code)) { |
|
87 | + $this->responses->set($code, new Response($code)); |
|
88 | + } |
|
89 | + |
|
90 | + return $this->responses->get($code); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Sets the response. |
|
95 | + * |
|
96 | + * @param Response $code |
|
97 | + */ |
|
98 | + public function add(Response $response) |
|
99 | + { |
|
100 | + $this->responses->set($response->getCode(), $response); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Removes the given repsonse. |
|
105 | + * |
|
106 | + * @param string $code |
|
107 | + */ |
|
108 | + public function remove($code) |
|
109 | + { |
|
110 | + $this->responses->remove($code); |
|
111 | + } |
|
112 | + |
|
113 | + public function current() |
|
114 | + { |
|
115 | + return $this->responses->current(); |
|
116 | + } |
|
117 | + |
|
118 | + public function key() |
|
119 | + { |
|
120 | + return $this->responses->key(); |
|
121 | + } |
|
122 | + |
|
123 | + public function next() |
|
124 | + { |
|
125 | + return $this->responses->next(); |
|
126 | + } |
|
127 | + |
|
128 | + public function rewind() |
|
129 | + { |
|
130 | + return $this->responses->rewind(); |
|
131 | + } |
|
132 | + |
|
133 | + public function valid() |
|
134 | + { |
|
135 | + return $this->responses->valid(); |
|
136 | + } |
|
137 | 137 | } |
@@ -10,148 +10,148 @@ |
||
10 | 10 | |
11 | 11 | class Parameters implements Arrayable, \Iterator |
12 | 12 | { |
13 | - use RefPart; |
|
14 | - |
|
15 | - /** @var ArrayList */ |
|
16 | - private $parameters; |
|
17 | - |
|
18 | - public function __construct($contents = []) |
|
19 | - { |
|
20 | - $this->parse($contents === null ? [] : $contents); |
|
21 | - } |
|
22 | - |
|
23 | - private function parse($contents) |
|
24 | - { |
|
25 | - $data = CollectionUtils::toMap($contents); |
|
26 | - |
|
27 | - $this->parameters = new ArrayList(); |
|
28 | - $this->parseRef($data); |
|
29 | - |
|
30 | - if (!$this->hasRef()) { |
|
31 | - foreach ($data as $param) { |
|
32 | - $this->parameters->add(new Parameter($param)); |
|
33 | - } |
|
34 | - } |
|
35 | - } |
|
36 | - |
|
37 | - public function toArray() |
|
38 | - { |
|
39 | - if ($this->hasRef()) { |
|
40 | - return ['$ref' => $this->getRef()]; |
|
41 | - } |
|
42 | - |
|
43 | - return $this->parameters->toArray(); |
|
44 | - } |
|
45 | - |
|
46 | - public function size() |
|
47 | - { |
|
48 | - return $this->parameters->size(); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Searches whether a parameter with the given name exists. |
|
53 | - * |
|
54 | - * @param string $name |
|
55 | - * |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public function searchByName($name) |
|
59 | - { |
|
60 | - return $this->parameters->search($name, function (Parameter $param, $name) { |
|
61 | - return $param->getName() == $name; |
|
62 | - }); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Returns parameter with the given name if it exists. |
|
67 | - * |
|
68 | - * @param string $name |
|
69 | - * |
|
70 | - * @return Parameter|void |
|
71 | - */ |
|
72 | - public function findByName($name) |
|
73 | - { |
|
74 | - foreach ($this->parameters as $param) { |
|
75 | - if ($param->getName() == $name) { |
|
76 | - return $param; |
|
77 | - } |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Searches for the parameter with the given name. Creates a parameter with the given name |
|
83 | - * if none exists. |
|
84 | - * |
|
85 | - * @param string $name |
|
86 | - * |
|
87 | - * @return Parameter |
|
88 | - */ |
|
89 | - public function getByName($name) |
|
90 | - { |
|
91 | - $param = $this->findByName($name); |
|
92 | - if (empty($param)) { |
|
93 | - $param = new Parameter(); |
|
94 | - $param->setName($name); |
|
95 | - $this->parameters->add($param); |
|
96 | - } |
|
97 | - |
|
98 | - return $param; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Adds a parameter. |
|
103 | - * |
|
104 | - * @param Parameter $param |
|
105 | - */ |
|
106 | - public function add(Parameter $param) |
|
107 | - { |
|
108 | - $this->parameters->add($param); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Removes a parameter. |
|
113 | - * |
|
114 | - * @param Parameter $param |
|
115 | - */ |
|
116 | - public function remove(Parameter $param) |
|
117 | - { |
|
118 | - $this->parameters->remove($param); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Returns whether a given parameter exists. |
|
123 | - * |
|
124 | - * @param Parameter $param |
|
125 | - * |
|
126 | - * @return bool |
|
127 | - */ |
|
128 | - public function contains(Parameter $param) |
|
129 | - { |
|
130 | - return $this->parameters->contains($param); |
|
131 | - } |
|
132 | - |
|
133 | - public function current() |
|
134 | - { |
|
135 | - return $this->parameters->current(); |
|
136 | - } |
|
137 | - |
|
138 | - public function key() |
|
139 | - { |
|
140 | - return $this->parameters->key(); |
|
141 | - } |
|
142 | - |
|
143 | - public function next() |
|
144 | - { |
|
145 | - return $this->parameters->next(); |
|
146 | - } |
|
147 | - |
|
148 | - public function rewind() |
|
149 | - { |
|
150 | - return $this->parameters->rewind(); |
|
151 | - } |
|
152 | - |
|
153 | - public function valid() |
|
154 | - { |
|
155 | - return $this->parameters->valid(); |
|
156 | - } |
|
13 | + use RefPart; |
|
14 | + |
|
15 | + /** @var ArrayList */ |
|
16 | + private $parameters; |
|
17 | + |
|
18 | + public function __construct($contents = []) |
|
19 | + { |
|
20 | + $this->parse($contents === null ? [] : $contents); |
|
21 | + } |
|
22 | + |
|
23 | + private function parse($contents) |
|
24 | + { |
|
25 | + $data = CollectionUtils::toMap($contents); |
|
26 | + |
|
27 | + $this->parameters = new ArrayList(); |
|
28 | + $this->parseRef($data); |
|
29 | + |
|
30 | + if (!$this->hasRef()) { |
|
31 | + foreach ($data as $param) { |
|
32 | + $this->parameters->add(new Parameter($param)); |
|
33 | + } |
|
34 | + } |
|
35 | + } |
|
36 | + |
|
37 | + public function toArray() |
|
38 | + { |
|
39 | + if ($this->hasRef()) { |
|
40 | + return ['$ref' => $this->getRef()]; |
|
41 | + } |
|
42 | + |
|
43 | + return $this->parameters->toArray(); |
|
44 | + } |
|
45 | + |
|
46 | + public function size() |
|
47 | + { |
|
48 | + return $this->parameters->size(); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Searches whether a parameter with the given name exists. |
|
53 | + * |
|
54 | + * @param string $name |
|
55 | + * |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public function searchByName($name) |
|
59 | + { |
|
60 | + return $this->parameters->search($name, function (Parameter $param, $name) { |
|
61 | + return $param->getName() == $name; |
|
62 | + }); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Returns parameter with the given name if it exists. |
|
67 | + * |
|
68 | + * @param string $name |
|
69 | + * |
|
70 | + * @return Parameter|void |
|
71 | + */ |
|
72 | + public function findByName($name) |
|
73 | + { |
|
74 | + foreach ($this->parameters as $param) { |
|
75 | + if ($param->getName() == $name) { |
|
76 | + return $param; |
|
77 | + } |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Searches for the parameter with the given name. Creates a parameter with the given name |
|
83 | + * if none exists. |
|
84 | + * |
|
85 | + * @param string $name |
|
86 | + * |
|
87 | + * @return Parameter |
|
88 | + */ |
|
89 | + public function getByName($name) |
|
90 | + { |
|
91 | + $param = $this->findByName($name); |
|
92 | + if (empty($param)) { |
|
93 | + $param = new Parameter(); |
|
94 | + $param->setName($name); |
|
95 | + $this->parameters->add($param); |
|
96 | + } |
|
97 | + |
|
98 | + return $param; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Adds a parameter. |
|
103 | + * |
|
104 | + * @param Parameter $param |
|
105 | + */ |
|
106 | + public function add(Parameter $param) |
|
107 | + { |
|
108 | + $this->parameters->add($param); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Removes a parameter. |
|
113 | + * |
|
114 | + * @param Parameter $param |
|
115 | + */ |
|
116 | + public function remove(Parameter $param) |
|
117 | + { |
|
118 | + $this->parameters->remove($param); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Returns whether a given parameter exists. |
|
123 | + * |
|
124 | + * @param Parameter $param |
|
125 | + * |
|
126 | + * @return bool |
|
127 | + */ |
|
128 | + public function contains(Parameter $param) |
|
129 | + { |
|
130 | + return $this->parameters->contains($param); |
|
131 | + } |
|
132 | + |
|
133 | + public function current() |
|
134 | + { |
|
135 | + return $this->parameters->current(); |
|
136 | + } |
|
137 | + |
|
138 | + public function key() |
|
139 | + { |
|
140 | + return $this->parameters->key(); |
|
141 | + } |
|
142 | + |
|
143 | + public function next() |
|
144 | + { |
|
145 | + return $this->parameters->next(); |
|
146 | + } |
|
147 | + |
|
148 | + public function rewind() |
|
149 | + { |
|
150 | + return $this->parameters->rewind(); |
|
151 | + } |
|
152 | + |
|
153 | + public function valid() |
|
154 | + { |
|
155 | + return $this->parameters->valid(); |
|
156 | + } |
|
157 | 157 | } |
@@ -9,113 +9,113 @@ |
||
9 | 9 | |
10 | 10 | class Headers implements Arrayable, \Iterator |
11 | 11 | { |
12 | - /** @var Map */ |
|
13 | - private $headers; |
|
14 | - |
|
15 | - public function __construct($contents = []) |
|
16 | - { |
|
17 | - $this->parse($contents === null ? [] : $contents); |
|
18 | - } |
|
19 | - |
|
20 | - private function parse($contents) |
|
21 | - { |
|
22 | - $data = CollectionUtils::toMap($contents); |
|
23 | - |
|
24 | - // headers |
|
25 | - $this->headers = new Map(); |
|
26 | - foreach ($data as $h => $props) { |
|
27 | - $this->headers->set($h, new Header($h, $props)); |
|
28 | - } |
|
29 | - } |
|
30 | - |
|
31 | - public function toArray() |
|
32 | - { |
|
33 | - return $this->headers->toArray(); |
|
34 | - } |
|
35 | - |
|
36 | - public function size() |
|
37 | - { |
|
38 | - return $this->headers->size(); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Returns whether a header with the given name exists. |
|
43 | - * |
|
44 | - * @param string $header |
|
45 | - * |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - public function has($header) |
|
49 | - { |
|
50 | - return $this->headers->has($header); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Returns whether the given header exists. |
|
55 | - * |
|
56 | - * @param Header $header |
|
57 | - * |
|
58 | - * @return bool |
|
59 | - */ |
|
60 | - public function contains(Header $header) |
|
61 | - { |
|
62 | - return $this->headers->contains($header); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Returns the header info for the given code. |
|
67 | - * |
|
68 | - * @param string $header |
|
69 | - * |
|
70 | - * @return Header |
|
71 | - */ |
|
72 | - public function get($header) |
|
73 | - { |
|
74 | - return $this->headers->get($header); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Sets the header. |
|
79 | - * |
|
80 | - * @param Header $header |
|
81 | - */ |
|
82 | - public function add(Header $header) |
|
83 | - { |
|
84 | - $this->headers->set($header->getHeader(), $header); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Removes the given header. |
|
89 | - * |
|
90 | - * @param string $header |
|
91 | - */ |
|
92 | - public function remove($header) |
|
93 | - { |
|
94 | - $this->headers->remove($header); |
|
95 | - } |
|
96 | - |
|
97 | - public function current() |
|
98 | - { |
|
99 | - return $this->headers->current(); |
|
100 | - } |
|
101 | - |
|
102 | - public function key() |
|
103 | - { |
|
104 | - return $this->headers->key(); |
|
105 | - } |
|
106 | - |
|
107 | - public function next() |
|
108 | - { |
|
109 | - return $this->headers->next(); |
|
110 | - } |
|
111 | - |
|
112 | - public function rewind() |
|
113 | - { |
|
114 | - return $this->headers->rewind(); |
|
115 | - } |
|
116 | - |
|
117 | - public function valid() |
|
118 | - { |
|
119 | - return $this->headers->valid(); |
|
120 | - } |
|
12 | + /** @var Map */ |
|
13 | + private $headers; |
|
14 | + |
|
15 | + public function __construct($contents = []) |
|
16 | + { |
|
17 | + $this->parse($contents === null ? [] : $contents); |
|
18 | + } |
|
19 | + |
|
20 | + private function parse($contents) |
|
21 | + { |
|
22 | + $data = CollectionUtils::toMap($contents); |
|
23 | + |
|
24 | + // headers |
|
25 | + $this->headers = new Map(); |
|
26 | + foreach ($data as $h => $props) { |
|
27 | + $this->headers->set($h, new Header($h, $props)); |
|
28 | + } |
|
29 | + } |
|
30 | + |
|
31 | + public function toArray() |
|
32 | + { |
|
33 | + return $this->headers->toArray(); |
|
34 | + } |
|
35 | + |
|
36 | + public function size() |
|
37 | + { |
|
38 | + return $this->headers->size(); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Returns whether a header with the given name exists. |
|
43 | + * |
|
44 | + * @param string $header |
|
45 | + * |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + public function has($header) |
|
49 | + { |
|
50 | + return $this->headers->has($header); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Returns whether the given header exists. |
|
55 | + * |
|
56 | + * @param Header $header |
|
57 | + * |
|
58 | + * @return bool |
|
59 | + */ |
|
60 | + public function contains(Header $header) |
|
61 | + { |
|
62 | + return $this->headers->contains($header); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Returns the header info for the given code. |
|
67 | + * |
|
68 | + * @param string $header |
|
69 | + * |
|
70 | + * @return Header |
|
71 | + */ |
|
72 | + public function get($header) |
|
73 | + { |
|
74 | + return $this->headers->get($header); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Sets the header. |
|
79 | + * |
|
80 | + * @param Header $header |
|
81 | + */ |
|
82 | + public function add(Header $header) |
|
83 | + { |
|
84 | + $this->headers->set($header->getHeader(), $header); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Removes the given header. |
|
89 | + * |
|
90 | + * @param string $header |
|
91 | + */ |
|
92 | + public function remove($header) |
|
93 | + { |
|
94 | + $this->headers->remove($header); |
|
95 | + } |
|
96 | + |
|
97 | + public function current() |
|
98 | + { |
|
99 | + return $this->headers->current(); |
|
100 | + } |
|
101 | + |
|
102 | + public function key() |
|
103 | + { |
|
104 | + return $this->headers->key(); |
|
105 | + } |
|
106 | + |
|
107 | + public function next() |
|
108 | + { |
|
109 | + return $this->headers->next(); |
|
110 | + } |
|
111 | + |
|
112 | + public function rewind() |
|
113 | + { |
|
114 | + return $this->headers->rewind(); |
|
115 | + } |
|
116 | + |
|
117 | + public function valid() |
|
118 | + { |
|
119 | + return $this->headers->valid(); |
|
120 | + } |
|
121 | 121 | } |
@@ -11,132 +11,132 @@ |
||
11 | 11 | |
12 | 12 | class Paths implements Arrayable, \Iterator |
13 | 13 | { |
14 | - use ExtensionPart; |
|
15 | - |
|
16 | - /** @var Map */ |
|
17 | - private $paths; |
|
18 | - |
|
19 | - public function __construct($contents = []) |
|
20 | - { |
|
21 | - $this->parse($contents === null ? [] : $contents); |
|
22 | - } |
|
23 | - |
|
24 | - private function parse($contents) |
|
25 | - { |
|
26 | - $data = CollectionUtils::toMap($contents); |
|
27 | - |
|
28 | - // paths |
|
29 | - $this->paths = new Map(); |
|
30 | - foreach ($data as $p => $path) { |
|
31 | - if (!Text::create($p)->startsWith('x-')) { |
|
32 | - $this->paths->set($p, new Path($p, $path)); |
|
33 | - } |
|
34 | - } |
|
35 | - |
|
36 | - // extensions |
|
37 | - $this->parseExtensions($data); |
|
38 | - } |
|
39 | - |
|
40 | - public function toArray() |
|
41 | - { |
|
42 | - $paths = clone $this->paths; |
|
14 | + use ExtensionPart; |
|
15 | + |
|
16 | + /** @var Map */ |
|
17 | + private $paths; |
|
18 | + |
|
19 | + public function __construct($contents = []) |
|
20 | + { |
|
21 | + $this->parse($contents === null ? [] : $contents); |
|
22 | + } |
|
23 | + |
|
24 | + private function parse($contents) |
|
25 | + { |
|
26 | + $data = CollectionUtils::toMap($contents); |
|
27 | + |
|
28 | + // paths |
|
29 | + $this->paths = new Map(); |
|
30 | + foreach ($data as $p => $path) { |
|
31 | + if (!Text::create($p)->startsWith('x-')) { |
|
32 | + $this->paths->set($p, new Path($p, $path)); |
|
33 | + } |
|
34 | + } |
|
35 | + |
|
36 | + // extensions |
|
37 | + $this->parseExtensions($data); |
|
38 | + } |
|
39 | + |
|
40 | + public function toArray() |
|
41 | + { |
|
42 | + $paths = clone $this->paths; |
|
43 | 43 | // $paths->setAll($this->getExtensions()); |
44 | - return $paths->toArray(); |
|
45 | - } |
|
46 | - |
|
47 | - public function size() |
|
48 | - { |
|
49 | - return $this->paths->size(); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Returns whether a path with the given name exists. |
|
54 | - * |
|
55 | - * @param string $path |
|
56 | - * |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - public function has($path) |
|
60 | - { |
|
61 | - return $this->paths->has($path); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Returns whether the given path exists. |
|
66 | - * |
|
67 | - * @param Path $path |
|
68 | - * |
|
69 | - * @return bool |
|
70 | - */ |
|
71 | - public function contains(Path $path) |
|
72 | - { |
|
73 | - return $this->paths->contains($path); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Returns the path info for the given path. |
|
78 | - * |
|
79 | - * @param string $path |
|
80 | - * |
|
81 | - * @return Path |
|
82 | - */ |
|
83 | - public function get($path) |
|
84 | - { |
|
85 | - if (!$this->paths->has($path)) { |
|
86 | - $this->paths->set($path, new Path($path)); |
|
87 | - } |
|
88 | - |
|
89 | - return $this->paths->get($path); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Sets the path. |
|
94 | - * |
|
95 | - * @param Path $path |
|
96 | - * |
|
97 | - * @return $this |
|
98 | - */ |
|
99 | - public function add(Path $path) |
|
100 | - { |
|
101 | - $this->paths->set($path->getPath(), $path); |
|
102 | - |
|
103 | - return $this; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Removes the given path. |
|
108 | - * |
|
109 | - * @param string $path |
|
110 | - */ |
|
111 | - public function remove($path) |
|
112 | - { |
|
113 | - $this->paths->remove($path); |
|
114 | - |
|
115 | - return $this; |
|
116 | - } |
|
117 | - |
|
118 | - public function current() |
|
119 | - { |
|
120 | - return $this->paths->current(); |
|
121 | - } |
|
122 | - |
|
123 | - public function key() |
|
124 | - { |
|
125 | - return $this->paths->key(); |
|
126 | - } |
|
127 | - |
|
128 | - public function next() |
|
129 | - { |
|
130 | - return $this->paths->next(); |
|
131 | - } |
|
132 | - |
|
133 | - public function rewind() |
|
134 | - { |
|
135 | - return $this->paths->rewind(); |
|
136 | - } |
|
137 | - |
|
138 | - public function valid() |
|
139 | - { |
|
140 | - return $this->paths->valid(); |
|
141 | - } |
|
44 | + return $paths->toArray(); |
|
45 | + } |
|
46 | + |
|
47 | + public function size() |
|
48 | + { |
|
49 | + return $this->paths->size(); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Returns whether a path with the given name exists. |
|
54 | + * |
|
55 | + * @param string $path |
|
56 | + * |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + public function has($path) |
|
60 | + { |
|
61 | + return $this->paths->has($path); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Returns whether the given path exists. |
|
66 | + * |
|
67 | + * @param Path $path |
|
68 | + * |
|
69 | + * @return bool |
|
70 | + */ |
|
71 | + public function contains(Path $path) |
|
72 | + { |
|
73 | + return $this->paths->contains($path); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Returns the path info for the given path. |
|
78 | + * |
|
79 | + * @param string $path |
|
80 | + * |
|
81 | + * @return Path |
|
82 | + */ |
|
83 | + public function get($path) |
|
84 | + { |
|
85 | + if (!$this->paths->has($path)) { |
|
86 | + $this->paths->set($path, new Path($path)); |
|
87 | + } |
|
88 | + |
|
89 | + return $this->paths->get($path); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Sets the path. |
|
94 | + * |
|
95 | + * @param Path $path |
|
96 | + * |
|
97 | + * @return $this |
|
98 | + */ |
|
99 | + public function add(Path $path) |
|
100 | + { |
|
101 | + $this->paths->set($path->getPath(), $path); |
|
102 | + |
|
103 | + return $this; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Removes the given path. |
|
108 | + * |
|
109 | + * @param string $path |
|
110 | + */ |
|
111 | + public function remove($path) |
|
112 | + { |
|
113 | + $this->paths->remove($path); |
|
114 | + |
|
115 | + return $this; |
|
116 | + } |
|
117 | + |
|
118 | + public function current() |
|
119 | + { |
|
120 | + return $this->paths->current(); |
|
121 | + } |
|
122 | + |
|
123 | + public function key() |
|
124 | + { |
|
125 | + return $this->paths->key(); |
|
126 | + } |
|
127 | + |
|
128 | + public function next() |
|
129 | + { |
|
130 | + return $this->paths->next(); |
|
131 | + } |
|
132 | + |
|
133 | + public function rewind() |
|
134 | + { |
|
135 | + return $this->paths->rewind(); |
|
136 | + } |
|
137 | + |
|
138 | + public function valid() |
|
139 | + { |
|
140 | + return $this->paths->valid(); |
|
141 | + } |
|
142 | 142 | } |
@@ -10,27 +10,27 @@ |
||
10 | 10 | |
11 | 11 | class ExternalDocs extends AbstractModel implements Arrayable |
12 | 12 | { |
13 | - use DescriptionPart; |
|
14 | - use UrlPart; |
|
15 | - use ExtensionPart; |
|
13 | + use DescriptionPart; |
|
14 | + use UrlPart; |
|
15 | + use ExtensionPart; |
|
16 | 16 | |
17 | - public function __construct($contents = []) |
|
18 | - { |
|
19 | - $this->parse($contents); |
|
20 | - } |
|
17 | + public function __construct($contents = []) |
|
18 | + { |
|
19 | + $this->parse($contents); |
|
20 | + } |
|
21 | 21 | |
22 | - private function parse($contents = []) |
|
23 | - { |
|
24 | - $data = CollectionUtils::toMap($contents); |
|
22 | + private function parse($contents = []) |
|
23 | + { |
|
24 | + $data = CollectionUtils::toMap($contents); |
|
25 | 25 | |
26 | - // parts |
|
27 | - $this->parseDescription($data); |
|
28 | - $this->parseUrl($data); |
|
29 | - $this->parseExtensions($data); |
|
30 | - } |
|
26 | + // parts |
|
27 | + $this->parseDescription($data); |
|
28 | + $this->parseUrl($data); |
|
29 | + $this->parseExtensions($data); |
|
30 | + } |
|
31 | 31 | |
32 | - public function toArray() |
|
33 | - { |
|
34 | - return $this->export('description', 'url'); |
|
35 | - } |
|
32 | + public function toArray() |
|
33 | + { |
|
34 | + return $this->export('description', 'url'); |
|
35 | + } |
|
36 | 36 | } |