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

Update ApiResponse #13

Merged
merged 1 commit into from
Aug 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 43 additions & 7 deletions src/LangleyFoxall/Helpers/ApiResponse.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace LangleyFoxall\Helpers;

class ApiResponse
class ApiResponse implements \ArrayAccess
{
/** @var int $status */
protected $status;
Expand All @@ -21,11 +21,11 @@ class ApiResponse
/**
* ApiResponse constructor.
*
* @param bool $success
* @param bool $success
* @param array|null|string $error
* @param array|null $data
* @param array|null $meta
* @param int $status
* @param array|null $data
* @param array|null $meta
* @param int $status
*/
public function __construct(bool $success = true, $error = null, $data = null, $meta = null, int $status = 200)
{
Expand All @@ -39,7 +39,7 @@ public function __construct(bool $success = true, $error = null, $data = null, $
/**
* @param array|null $data
* @param array|null $meta
* @param int $status
* @param int $status
* @return ApiResponse
*/
public static function success($data = null, $meta = null, int $status = 200)
Expand All @@ -55,7 +55,7 @@ public static function success($data = null, $meta = null, int $status = 200)

/**
* @param mixed $error
* @param int $status
* @param int $status
* @return ApiResponse
*/
public static function error($error = null, int $status = 400)
Expand Down Expand Up @@ -110,4 +110,40 @@ public function json()
return response()->json(get_object_vars($this))
->setStatusCode($this->status);
}

/**
* @param string $offset
* @return bool
*/
public function offsetExists($offset)
{
return isset($this->data[ $offset ]);
}

/**
* @param string $offset
* @return mixed|null
*/
public function offsetGet($offset)
{
return isset($this->data[ $offset ])
? $this->data[ $offset ] : null;
}

/**
* @param string $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
{
$this->data[ $offset ] = $value;
}

/**
* @param string $offset
*/
public function offsetUnset($offset)
{
unset($this->data[ $offset ]);
}
}