Skip to content

Commit

Permalink
Merge pull request #3 from attogram/add-getpost
Browse files Browse the repository at this point in the history
v4.1.2 - add getPost
  • Loading branch information
attogram authored Feb 1, 2020
2 parents 0b74015 + 3888b29 commit 475f726
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,19 @@ if (!$control) {

`public function getGet(string $name = '')`

* Get a global _GET variable, or empty string if not found
* Get a global `_GET` variable, or empty string if not found

### getPost

`public function getPost(string $name = '')`

* Get a global `_POST` variable, or empty string if not found

### getServer

`public function getServer(string $name = '')`

* Get a global _SERVER variable, or empty string if not found
* Get a global `_SERVER` variable, or empty string if not found

### getHost

Expand Down
15 changes: 13 additions & 2 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
class Router
{
const VERSION = '4.1.1-pre.1';
const VERSION = '4.1.2';

private $control = null;
private $forceSlash = false;
Expand Down Expand Up @@ -253,14 +253,25 @@ public function getGet(string $name = '')
return $this->getGlobal('_GET', $name);
}

/**
* get a value from the global _POST array, or the whole _POST array
*
* @param string $name
* @return array|string
*/
public function getPost(string $name = '')
{
return $this->getGlobal('_POST', $name);
}

/**
* get a value from a global array, or the whole global array
*
* @param string $global
* @param string $name
* @return array|null|string
*/
private function getGlobal(string $global, string $name)
private function getGlobal(string $global, string $name = '')
{
if (!isset($GLOBALS[$global]) // Global does not exist
|| !is_array($GLOBALS[$global]) // Global is not an array
Expand Down

0 comments on commit 475f726

Please sign in to comment.