Skip to content

Commit

Permalink
Merge pull request #13 from langleyfoxall/update-apiresponse
Browse files Browse the repository at this point in the history
Update ApiResponse
  • Loading branch information
jaredkove authored Aug 29, 2018
2 parents 5ea582b + aba26d9 commit 995f0c8
Showing 1 changed file with 43 additions and 7 deletions.
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 ]);
}
}

0 comments on commit 995f0c8

Please sign in to comment.