| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPIDE\App\Kernel; |
| 4 |
|
| 5 |
use Symfony\Component\HttpFoundation\Request as SymfonyRequest; |
| 6 |
|
| 7 |
class Request extends SymfonyRequest |
| 8 |
{ |
| 9 |
public function input($key, $default = null) |
| 10 |
{ |
| 11 |
// first try GET, then POST |
| 12 |
$value = $this->get($key, $this->query->get($key)); |
| 13 |
|
| 14 |
// then look into JSON content, fallback to default |
| 15 |
if ($value === null) { |
| 16 |
$content = json_decode((string) $this->getContent()); |
| 17 |
$value = isset($content->{$key}) ? $content->{$key} : $default; |
| 18 |
} |
| 19 |
|
| 20 |
return $value; |
| 21 |
} |
| 22 |
|
| 23 |
public function all(): array |
| 24 |
{ |
| 25 |
$params = []; |
| 26 |
|
| 27 |
// first look into JSON content |
| 28 |
$content = json_decode((string) $this->getContent()); |
| 29 |
if (! empty($content)) { |
| 30 |
foreach ($content as $key => $param) { |
| 31 |
$params[$key] = $param; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
// then try (and override) with POST |
| 36 |
foreach ($this->request as $key => $param) { |
| 37 |
$params[$key] = $param; |
| 38 |
} |
| 39 |
|
| 40 |
// finally try (and override) with GET |
| 41 |
foreach ($this->query as $key => $param) { |
| 42 |
$params[$key] = $param; |
| 43 |
} |
| 44 |
|
| 45 |
return $params; |
| 46 |
} |
| 47 |
} |
| 48 |
|