bytic /
http
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Nip\Http\Request\Traits; |
||||
| 4 | |||||
| 5 | use Symfony\Component\HttpFoundation\ParameterBag; |
||||
| 6 | |||||
| 7 | /** |
||||
| 8 | * Trait HasJsonParameterBag |
||||
| 9 | * @package Nip\Http\Request\Traits |
||||
| 10 | */ |
||||
| 11 | trait HasJsonParameterBag |
||||
| 12 | { |
||||
| 13 | |||||
| 14 | /** |
||||
| 15 | * The decoded JSON content for the request. |
||||
| 16 | * |
||||
| 17 | * @var \Symfony\Component\HttpFoundation\ParameterBag|null |
||||
| 18 | */ |
||||
| 19 | protected $json; |
||||
| 20 | |||||
| 21 | /** |
||||
| 22 | * Get the JSON payload for the request. |
||||
| 23 | * |
||||
| 24 | * @param string|null $key |
||||
| 25 | * @param mixed $default |
||||
| 26 | * @return \Symfony\Component\HttpFoundation\ParameterBag|mixed |
||||
| 27 | */ |
||||
| 28 | public function json($key = null, $default = null) |
||||
| 29 | { |
||||
| 30 | if (!isset($this->json)) { |
||||
| 31 | $this->json = new ParameterBag((array)json_decode($this->getContent(), true)); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 32 | } |
||||
| 33 | |||||
| 34 | if (is_null($key)) { |
||||
| 35 | return $this->json; |
||||
| 36 | } |
||||
| 37 | |||||
| 38 | return data_get($this->json->all(), $key, $default); |
||||
|
0 ignored issues
–
show
The method
all() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 39 | } |
||||
| 40 | } |
||||
| 41 |