PHP Class Flugg\Responder\Http\ResponseBuilder

Author: Alexander Tømmerås ([email protected])
Inheritance: implements Illuminate\Contracts\Support\Arrayable, implements Illuminate\Contracts\Support\Jsonable, implements JsonSerializabl\JsonSerializable
ファイルを表示 Open project: flugger/laravel-responder Class Usage Examples

Protected Properties

Property Type Description
$includeStatusCode boolean Flag indicating if status code should be added to the serialized data.
$responseFactory Illuminate\Contracts\Routing\ResponseFactory | Laravel\Lumen\Http\ResponseFactory Response factory used to generate JSON responses.
$statusCode integer The HTTP status code for the response.

Public Methods

Method Description
__construct ( Illuminate\Contracts\Routing\ResponseFactory | ResponseFactory $responseFactory ) Constructor.
jsonSerialize ( ) : array Convert the object into something JSON serializable.
respond ( integer $statusCode = null, array $headers = [] ) : Illuminate\Http\JsonResponse Serialize the data and wrap it in a JSON response object.
setIncludeStatusCode ( boolean $includeStatusCode ) : ResponseBuilder Set a flag indicating if status code should be added to the response.
setStatus ( integer $statusCode ) : ResponseBuilder Set the HTTP status code for the response.
toArray ( ) : array Convert the response to an array.
toCollection ( ) : Collection Convert the response to an Illuminate collection.
toJson ( integer $options ) : string Convert the response to JSON.

Protected Methods

Method Description
includeStatusCode ( array $data ) : array Include a status code to the serialized data if enabled.

Method Details

__construct() public method

Constructor.
public __construct ( Illuminate\Contracts\Routing\ResponseFactory | ResponseFactory $responseFactory )
$responseFactory Illuminate\Contracts\Routing\ResponseFactory | Laravel\Lumen\Http\ResponseFactory

includeStatusCode() protected method

Include a status code to the serialized data if enabled.
protected includeStatusCode ( array $data ) : array
$data array
return array

jsonSerialize() public method

Convert the object into something JSON serializable.
public jsonSerialize ( ) : array
return array

respond() public method

Serialize the data and wrap it in a JSON response object.
public respond ( integer $statusCode = null, array $headers = [] ) : Illuminate\Http\JsonResponse
$statusCode integer
$headers array
return Illuminate\Http\JsonResponse

setIncludeStatusCode() public method

Set a flag indicating if status code should be added to the response.
public setIncludeStatusCode ( boolean $includeStatusCode ) : ResponseBuilder
$includeStatusCode boolean
return ResponseBuilder

setStatus() public method

Set the HTTP status code for the response.
public setStatus ( integer $statusCode ) : ResponseBuilder
$statusCode integer
return ResponseBuilder

toArray() abstract public method

Convert the response to an array.
abstract public toArray ( ) : array
return array

toCollection() public method

Convert the response to an Illuminate collection.
public toCollection ( ) : Collection
return Illuminate\Support\Collection

toJson() public method

Convert the response to JSON.
public toJson ( integer $options ) : string
$options integer
return string

Property Details

$includeStatusCode protected_oe property

Flag indicating if status code should be added to the serialized data.
protected bool $includeStatusCode
return boolean

$responseFactory protected_oe property

Response factory used to generate JSON responses.
protected ResponseFactory,Illuminate\Contracts\Routing|ResponseFactory,Laravel\Lumen\Http $responseFactory
return Illuminate\Contracts\Routing\ResponseFactory | Laravel\Lumen\Http\ResponseFactory

$statusCode protected_oe property

The HTTP status code for the response.
protected int $statusCode
return integer