PHP Class Dingo\Api\Http\Response

Inheritance: extends Illuminate\Http\Response
Show file Open project: dingo/api Class Usage Examples

Public Properties

Property Type Description
$exception Exception The exception that triggered the error response.

Protected Properties

Property Type Description
$binding Dingo\Api\Transformer\Binding Transformer binding instance.
$events Illuminate\Events\Dispatcher Event dispatcher instance.
$formatters array Array of registered formatters.
$transformer Dingo\Api\Transformer\TransformerFactory Transformer factory instance.

Public Methods

Method Description
__construct ( mixed $content, integer $status = 200, array $headers = [], Dingo\Api\Transformer\Binding $binding = null ) : void Create a new response instance.
addFormatter ( string $key, Dingo\Api\Http\Response\Format\Format $formatter ) : void Add a response formatter.
addMeta ( string $key, mixed $value ) : Response Add a meta key and value pair.
cookie ( Cookie | mixed $cookie ) : Response Add a cookie to the response.
getFormatter ( string $format ) : Dingo\Api\Http\Response\Format\Format Get the formatter based on the requested format type.
getMeta ( ) : array Get the meta data for the response.
getTransformer ( ) : Dingo\Api\Transformer\Factory Get the transformer instance.
hasFormatter ( string $format ) : boolean Determine if a response formatter has been registered.
makeFromExisting ( Illuminate\Http\Response $old ) : Response Make an API response from an existing Illuminate response.
makeFromJson ( Illuminate\Http\JsonResponse $json ) : Response Make an API response from an existing JSON response.
meta ( string $key, mixed $value ) : Response Add a meta key and value pair.
morph ( string $format = 'json' ) : Response Morph the API response to the appropriate format.
setContent ( $content )
setEventDispatcher ( Illuminate\Events\Dispatcher $events ) : void Set the event dispatcher instance.
setFormatters ( array $formatters ) : void Set the response formatters.
setMeta ( array $meta ) : Response Set the meta data for the response.
setTransformer ( Dingo\Api\Transformer\Factory $transformer ) : void Set the transformer factory instance.
statusCode ( integer $statusCode ) : Response Set the response status code.
withHeader ( string $key, string $value, boolean $replace = true ) : Response Add a header to the response.

Protected Methods

Method Description
fireMorphedEvent ( ) : void Fire the morphed event.
fireMorphingEvent ( ) : void Fire the morphing event.

Method Details

__construct() public method

Create a new response instance.
public __construct ( mixed $content, integer $status = 200, array $headers = [], Dingo\Api\Transformer\Binding $binding = null ) : void
$content mixed
$status integer
$headers array
$binding Dingo\Api\Transformer\Binding
return void

addFormatter() public static method

Add a response formatter.
public static addFormatter ( string $key, Dingo\Api\Http\Response\Format\Format $formatter ) : void
$key string
$formatter Dingo\Api\Http\Response\Format\Format
return void

addMeta() public method

Add a meta key and value pair.
public addMeta ( string $key, mixed $value ) : Response
$key string
$value mixed
return Response

fireMorphedEvent() protected method

Fire the morphed event.
protected fireMorphedEvent ( ) : void
return void

fireMorphingEvent() protected method

Fire the morphing event.
protected fireMorphingEvent ( ) : void
return void

getFormatter() public static method

Get the formatter based on the requested format type.
public static getFormatter ( string $format ) : Dingo\Api\Http\Response\Format\Format
$format string
return Dingo\Api\Http\Response\Format\Format

getMeta() public method

Get the meta data for the response.
public getMeta ( ) : array
return array

getTransformer() public static method

Get the transformer instance.
public static getTransformer ( ) : Dingo\Api\Transformer\Factory
return Dingo\Api\Transformer\Factory

hasFormatter() public static method

Determine if a response formatter has been registered.
public static hasFormatter ( string $format ) : boolean
$format string
return boolean

makeFromExisting() public static method

Make an API response from an existing Illuminate response.
public static makeFromExisting ( Illuminate\Http\Response $old ) : Response
$old Illuminate\Http\Response
return Response

makeFromJson() public static method

Make an API response from an existing JSON response.
public static makeFromJson ( Illuminate\Http\JsonResponse $json ) : Response
$json Illuminate\Http\JsonResponse
return Response

meta() public method

Add a meta key and value pair.
public meta ( string $key, mixed $value ) : Response
$key string
$value mixed
return Response

morph() public method

Morph the API response to the appropriate format.
public morph ( string $format = 'json' ) : Response
$format string
return Response

setContent() public method

public setContent ( $content )

setEventDispatcher() public static method

Set the event dispatcher instance.
public static setEventDispatcher ( Illuminate\Events\Dispatcher $events ) : void
$events Illuminate\Events\Dispatcher
return void

setFormatters() public static method

Set the response formatters.
public static setFormatters ( array $formatters ) : void
$formatters array
return void

setMeta() public method

Set the meta data for the response.
public setMeta ( array $meta ) : Response
$meta array
return Response

setTransformer() public static method

Set the transformer factory instance.
public static setTransformer ( Dingo\Api\Transformer\Factory $transformer ) : void
$transformer Dingo\Api\Transformer\Factory
return void

statusCode() public method

Set the response status code.
public statusCode ( integer $statusCode ) : Response
$statusCode integer
return Response

withHeader() public method

Add a header to the response.
public withHeader ( string $key, string $value, boolean $replace = true ) : Response
$key string
$value string
$replace boolean
return Response

Property Details

$binding protected property

Transformer binding instance.
protected Binding,Dingo\Api\Transformer $binding
return Dingo\Api\Transformer\Binding

$events protected static property

Event dispatcher instance.
protected static Dispatcher,Illuminate\Events $events
return Illuminate\Events\Dispatcher

$exception public property

The exception that triggered the error response.
public Exception $exception
return Exception

$formatters protected static property

Array of registered formatters.
protected static array $formatters
return array

$transformer protected static property

Transformer factory instance.
protected static TransformerFactory,Dingo\Api\Transformer $transformer
return Dingo\Api\Transformer\TransformerFactory