Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ServerRequest: introduce trait, cover more tests
- Loading branch information
Showing
3 changed files
with
65 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Contributte\Psr7\Extra; | ||
|
||
use Contributte\Psr7\Exception\Logical\InvalidStateException; | ||
|
||
trait ExtraServerRequestTrait | ||
{ | ||
|
||
use ExtraRequestTrait; | ||
|
||
/** | ||
* QUERY PARAM ************************************************************* | ||
*/ | ||
|
||
/** | ||
* @param string $name | ||
* | ||
* @return bool | ||
*/ | ||
public function hasQueryParam($name) | ||
{ | ||
return array_key_exists($name, $this->getQueryParams()); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param mixed $default | ||
* @return mixed | ||
*/ | ||
public function getQueryParam($name, $default = NULL) | ||
{ | ||
if (!$this->hasQueryParam($name)) { | ||
if (func_num_args() < 2) { | ||
throw new InvalidStateException(sprintf('No query parameter "%s" found', $name)); | ||
} | ||
|
||
return $default; | ||
} | ||
|
||
return $this->getQueryParams()[$name]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters