Skip to content

Commit c7c8154

Browse files
committed
Update comments and doc blocks
1 parent 6553bf7 commit c7c8154

File tree

11 files changed

+134
-15
lines changed

11 files changed

+134
-15
lines changed

src/WaterPipe/HTTP/Header.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,35 @@ abstract class Header implements \ArrayAccess, \SeekableIterator, \JsonSerializa
4444
*/
4545
private $_position = 0;
4646

47+
/**
48+
* Create or change the value of an HTTP header field.
49+
*
50+
* @param string $name The name of the header field
51+
* @param string $value The value of the header field
52+
*/
4753
public function setField(string $name, string $value)
4854
{
4955
$this->_fields[strtolower($name)] = $value;
5056
}
5157

58+
/**
59+
* Returns the value of an HTTP heade field.
60+
*
61+
* @param string $name The name of the header field
62+
*
63+
* @return string The value of the header field.
64+
*/
5265
public function getField(string $name): string
5366
{
5467
$name = strtolower($name);
5568
return array_key_exists($name, $this->_fields) ? $this->_fields[$name] : "";
5669
}
5770

71+
/**
72+
* Returns the set of headers in the HTTP format.
73+
*
74+
* @return array
75+
*/
5876
public function toArray(): array
5977
{
6078
$raw = array();
@@ -71,7 +89,7 @@ public function toArray(): array
7189
* @param mixed $offset <p>
7290
* An offset to check for.
7391
* </p>
74-
* @return boolean true on success or false on failure.
92+
* @return bool true on success or false on failure.
7593
* </p>
7694
* <p>
7795
* The return value will be casted to boolean if non-boolean was returned.
@@ -173,7 +191,7 @@ public function key()
173191
/**
174192
* Checks if current position is valid
175193
* @link http://php.net/manual/en/iterator.valid.php
176-
* @return boolean The return value will be casted to boolean and then evaluated.
194+
* @return bool The return value will be casted to boolean and then evaluated.
177195
* Returns true on success or false on failure.
178196
* @since 5.0.0
179197
*/
@@ -243,4 +261,4 @@ public function jsonSerialize()
243261
{
244262
return json_encode($this->_fields);
245263
}
246-
}
264+
}

src/WaterPipe/HTTP/Request/Request.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public function __construct()
8484
}
8585

8686
/**
87+
* Returns the request method.
88+
*
8789
* @return int
8890
*/
8991
public function getMethod(): int
@@ -92,6 +94,8 @@ public function getMethod(): int
9294
}
9395

9496
/**
97+
* Sets the request method.
98+
*
9599
* @param int $type
96100
*/
97101
public function setMethod(int $type): void
@@ -100,6 +104,8 @@ public function setMethod(int $type): void
100104
}
101105

102106
/**
107+
* Returns the set of request parameters from query string.
108+
*
103109
* @return RequestData|null
104110
*/
105111
public function getParams(): ?RequestData
@@ -108,6 +114,8 @@ public function getParams(): ?RequestData
108114
}
109115

110116
/**
117+
* Sets the request parameters.
118+
*
111119
* @param RequestData $params
112120
*/
113121
public function setParams(RequestData $params): void
@@ -116,6 +124,8 @@ public function setParams(RequestData $params): void
116124
}
117125

118126
/**
127+
* Returns the request body.
128+
*
119129
* @return RequestData
120130
*/
121131
public function getBody(): RequestData
@@ -124,6 +134,8 @@ public function getBody(): RequestData
124134
}
125135

126136
/**
137+
* Sets the request body.
138+
*
127139
* @param RequestData $body
128140
*/
129141
public function setBody(RequestData $body): void
@@ -132,6 +144,8 @@ public function setBody(RequestData $body): void
132144
}
133145

134146
/**
147+
* Returns the set of cookies attached to the request.
148+
*
135149
* @return RequestData
136150
*/
137151
public function getCookies(): RequestData
@@ -140,6 +154,8 @@ public function getCookies(): RequestData
140154
}
141155

142156
/**
157+
* Sets the cookies attached to the request.
158+
*
143159
* @param RequestData $cookies
144160
*/
145161
public function setCookies(RequestData $cookies): void
@@ -148,6 +164,8 @@ public function setCookies(RequestData $cookies): void
148164
}
149165

150166
/**
167+
* Returns the request headers.
168+
*
151169
* @return RequestHeader
152170
*/
153171
public function getHeader(): RequestHeader
@@ -156,6 +174,8 @@ public function getHeader(): RequestHeader
156174
}
157175

158176
/**
177+
* Set the request headers.
178+
*
159179
* @param RequestHeader $header
160180
*/
161181
public function setHeader(RequestHeader $header): void
@@ -257,4 +277,4 @@ public static function &capture(): Request
257277
{
258278
return Router::getInstance()->build()->getRequest();
259279
}
260-
}
280+
}

src/WaterPipe/HTTP/Request/RequestMethod.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
/**
3636
* Class RequestMethod
37+
*
3738
* @package WaterPipe
3839
* @category Enumerations
3940
*/

src/WaterPipe/HTTP/Request/RequestUri.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public static function makeUri(...$parts)
226226
* @param mixed $offset <p>
227227
* An offset to check for.
228228
* </p>
229-
* @return boolean true on success or false on failure.
229+
* @return bool true on success or false on failure.
230230
* </p>
231231
* <p>
232232
* The return value will be casted to boolean if non-boolean was returned.

src/WaterPipe/HTTP/Response/ResponseStatus.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class ResponseStatus
151151
);
152152

153153
/**
154-
* @var integer
154+
* @var int
155155
*/
156156
private $_code;
157157

@@ -186,6 +186,8 @@ public function __toString()
186186
}
187187

188188
/**
189+
* Returns the response status code.
190+
*
189191
* @return int
190192
*/
191193
public function getCode(): int
@@ -194,6 +196,8 @@ public function getCode(): int
194196
}
195197

196198
/**
199+
* Returns the response status description.
200+
*
197201
* @return string
198202
*/
199203
public function getDescription(): string
@@ -202,13 +206,21 @@ public function getDescription(): string
202206
}
203207

204208
/**
209+
* Returns the list of registered status codes and descriptions
210+
*
205211
* @return array
206212
*/
207213
public static function getRegistry(): array
208214
{
209215
return self::$_registry;
210216
}
211217

218+
/**
219+
* Add a new response status code in the registry
220+
*
221+
* @param int $code The response status code
222+
* @param string $description The response status description
223+
*/
212224
public static function registerStatusCode(int $code, string $description)
213225
{
214226
self::$_registry[$code] = $description;

src/WaterPipe/Routing/Middleware/Middleware.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,17 @@
3737

3838
abstract class Middleware
3939
{
40+
/**
41+
* Executes an action just before the execution of the request.
42+
*
43+
* @param Request &$request The request wich will be executed.
44+
*/
4045
public abstract function beforeExecute(Request &$request);
4146

47+
/**
48+
* Executes an action just before send the response.
49+
*
50+
* @param Response &$response The response which will be sent.
51+
*/
4252
public abstract function beforeSend(Response &$response);
43-
}
53+
}

src/WaterPipe/Routing/Route.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,42 @@ public function __construct(string $uri)
6767
}
6868

6969
/**
70+
* Returns the URI handled by this route.
71+
*
7072
* @return string
7173
*/
7274
public function getUri(): string
7375
{
7476
return $this->_uri;
7577
}
7678

79+
/**
80+
* Execute an action when any kind of request method
81+
* is sent to this route.
82+
*/
7783
public abstract function request();
7884

85+
/**
86+
* Execute an action when a GET request method
87+
* is sent to this route.
88+
*/
7989
public abstract function get();
8090

91+
/**
92+
* Execute an action when a POST request method
93+
* is sent to this route.
94+
*/
8195
public abstract function post();
8296

97+
/**
98+
* Execute an action when a PUT request method
99+
* is sent to this route.
100+
*/
83101
public abstract function put();
84102

103+
/**
104+
* Execute an action when a DELETE request method
105+
* is sent to this route.
106+
*/
85107
public abstract function delete();
86-
}
108+
}

src/WaterPipe/Routing/RouteAction.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,8 @@ public function __construct()
5858
$this->_response = new Response();
5959
}
6060

61+
/**
62+
* Executes the action.
63+
*/
6164
public abstract function execute();
62-
}
65+
}

src/WaterPipe/Routing/Router.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,24 @@ class Router
5050
*/
5151
private $_request;
5252

53+
/**
54+
* @var bool
55+
*/
5356
private $_built = false;
5457

58+
/**
59+
* Router constructor
60+
*/
5561
private function __construct()
5662
{
5763
$this->_request = new Request();
5864
}
5965

66+
/**
67+
* Returns the unique instance of the Router.
68+
*
69+
* @return self
70+
*/
6071
public static function &getInstance()
6172
{
6273
static $instance;
@@ -66,6 +77,11 @@ public static function &getInstance()
6677
return $instance[0];
6778
}
6879

80+
/**
81+
* Builds the router and capture the request.
82+
*
83+
* @return self
84+
*/
6985
public function build(): self
7086
{
7187
if (!$this->_built) {
@@ -79,6 +95,9 @@ public function build(): self
7995
return $this;
8096
}
8197

98+
/**
99+
* Detects the current request method.
100+
*/
82101
private function _detectMethod()
83102
{
84103
if (isset($_SERVER["REQUEST_METHOD"])) {
@@ -108,6 +127,9 @@ private function _detectMethod()
108127
}
109128
}
110129

130+
/**
131+
* Detects the current request URI.
132+
*/
111133
private function _detectUri()
112134
{
113135
$config = WaterPipeConfig::get();
@@ -190,6 +212,9 @@ private function _detectUri()
190212
$this->_request->uri->setUri(str_replace(array('//', '../'), '/', trim($uri)));
191213
}
192214

215+
/**
216+
* Detects the current request headers.
217+
*/
193218
private function _detectHeaders()
194219
{
195220
if (is_array($headers = getallheaders())) {
@@ -204,6 +229,8 @@ private function _detectHeaders()
204229
}
205230

206231
/**
232+
* Checks if the router is built or not.
233+
*
207234
* @return bool
208235
*/
209236
public function isBuilt(): bool
@@ -212,10 +239,13 @@ public function isBuilt(): bool
212239
}
213240

214241
/**
242+
* Returns the captured request at the build time
243+
* of the router.
244+
*
215245
* @return Request
216246
*/
217247
public function &getRequest(): Request
218248
{
219249
return $this->_request;
220250
}
221-
}
251+
}

0 commit comments

Comments
 (0)