Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Implement ArrayAccess on JsonResponse + TestResponse #30817

Merged
merged 9 commits into from
Dec 11, 2019
Prev Previous commit
Next Next commit
tweak logic
  • Loading branch information
taylorotwell committed Dec 11, 2019
commit 20a18db52b3a1e04647b316fdf5861e68654884a
15 changes: 13 additions & 2 deletions src/Illuminate/Http/JsonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class JsonResponse extends BaseJsonResponse
Macroable::__call as macroCall;
}

/**
* The formatted JSON decoded.
*
* @var mixed
*/
protected $decoded;

/**
* Constructor.
*
Expand Down Expand Up @@ -128,7 +135,9 @@ public function hasEncodingOption($option)
*/
public function offsetExists($offset)
{
return isset($this->original[$offset]);
$this->decoded = $this->decoded ?: json_decode($this->data, true);

return isset($this->decoded[$offset]);
}

/**
Expand All @@ -139,7 +148,9 @@ public function offsetExists($offset)
*/
public function offsetGet($offset)
{
return $this->original[$offset];
$this->decoded = $this->decoded ?: json_decode($this->data, true);

return $this->decoded[$offset];
}

/**
Expand Down