PHP Class Larabros\Elogram\Http\Response

Show file Open project: larabros/elogram Class Usage Examples

Protected Properties

Property Type Description
$data array
$meta array
$pagination array
$raw array

Public Methods

Method Description
__construct ( array $meta = [], array $data = [], array $pagination = [] ) Creates a new instance of :php:class:Response.
__toString ( ) : string Returns the JSON-encoded raw response.
createFromJson ( array $response ) : static Creates a new instance of :php:class:Response from a JSON-decoded response body.
get ( ) : array | Collection Gets the response body. If the response contains multiple records, a Collection is returned.
getRaw ( string | null $key = null ) : array Gets the JSON-decoded raw response.
hasPages ( ) : boolean If the response has a pagination field with a next_url key, then returns true, otherwise false.
merge ( Response $response ) : Response Merges the contents of this response with $response and returns a new :php:class:Response instance.
nextUrl ( ) : string | null Returns the next URL, if available, otherwise null.

Protected Methods

Method Description
isCollection ( array | Collection $data ) : boolean Tests the current response data to see if one or more records were returned.
isRecord ( array | Collection $data ) : boolean Tests the current response data to see if a single record was returned.

Method Details

__construct() public method

Creates a new instance of :php:class:Response.
public __construct ( array $meta = [], array $data = [], array $pagination = [] )
$meta array
$data array
$pagination array

__toString() public method

Returns the JSON-encoded raw response.
public __toString ( ) : string
return string

createFromJson() public static method

Creates a new instance of :php:class:Response from a JSON-decoded response body.
public static createFromJson ( array $response ) : static
$response array
return static

get() public method

Gets the response body. If the response contains multiple records, a Collection is returned.
public get ( ) : array | Collection
return array | Illuminate\Support\Collection

getRaw() public method

Gets the JSON-decoded raw response.
public getRaw ( string | null $key = null ) : array
$key string | null
return array

hasPages() public method

If the response has a pagination field with a next_url key, then returns true, otherwise false.
public hasPages ( ) : boolean
return boolean

isCollection() protected method

Tests the current response data to see if one or more records were returned.
protected isCollection ( array | Collection $data ) : boolean
$data array | Illuminate\Support\Collection
return boolean

isRecord() protected method

Tests the current response data to see if a single record was returned.
protected isRecord ( array | Collection $data ) : boolean
$data array | Illuminate\Support\Collection
return boolean

merge() public method

Merges the contents of this response with $response and returns a new :php:class:Response instance.
public merge ( Response $response ) : Response
$response Response
return Response

nextUrl() public method

Returns the next URL, if available, otherwise null.
public nextUrl ( ) : string | null
return string | null

Property Details

$data protected property

protected array $data
return array

$meta protected property

protected array $meta
return array

$pagination protected property

protected array $pagination
return array

$raw protected property

protected array $raw
return array