Skip to content

Commit 4cfd0ab

Browse files
authored
Merge pull request #9 from vbcodeplicity/feature/add-array-strict-type
- return null on the wrong type - added Request::getArray
2 parents aeb93b1 + f557d06 commit 4cfd0ab

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/Request/Request.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,19 +272,29 @@ public function unsetParam($key)
272272

273273
/**
274274
* @param string $key
275-
* @return int
275+
* @return int|null
276276
*/
277277
public function getInt($key)
278278
{
279-
return filter_var($this->getParam($key), FILTER_VALIDATE_INT);
279+
return filter_var($this->getParam($key), FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
280280
}
281281

282282
/**
283283
* @param string $key
284-
* @return bool
284+
* @return bool|null
285285
*/
286286
public function getBoolean($key)
287287
{
288-
return filter_var($this->getParam($key), FILTER_VALIDATE_BOOLEAN);
288+
return filter_var($this->getParam($key), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
289+
}
290+
291+
/**
292+
* @param string $key
293+
* @return array|null
294+
*/
295+
public function getArray($key)
296+
{
297+
$param = $this->getParam($key);
298+
return $param ? (array) $param : null;
289299
}
290300
}

0 commit comments

Comments
 (0)