JsonVisitor
extends AbstractRequestVisitor
in package
Visitor used to apply a parameter to an array that will be serialized as a top level key-value pair in a JSON body
Table of Contents
Properties
- $data : SplObjectStorage
- $jsonContentType : bool
Methods
- __construct() : mixed
- after() : mixed
- Called after visiting all parameters
- setContentTypeHeader() : self
- Set the Content-Type header to add to the request if JSON is added to the body. This visitor does not add a Content-Type header unless you specify one here.
- visit() : mixed
- Called once for each parameter being visited that matches the location type
- prepareValue() : array<string|int, mixed>|mixed
- Prepare (filter and set desired name for request item) the value for request.
- resolveRecursively() : array<string|int, mixed>
- Map nested parameters into the location_key based parameters
Properties
$data
protected
SplObjectStorage
$data
Data object for persisting JSON data
$jsonContentType
protected
bool
$jsonContentType
= 'application/json'
Whether or not to add a Content-Type header when JSON is found
Methods
__construct()
public
__construct() : mixed
after()
Called after visiting all parameters
public
after(CommandInterface $command, RequestInterface $request) : mixed
Parameters
- $command : CommandInterface
-
Command being visited
- $request : RequestInterface
-
Request being visited
setContentTypeHeader()
Set the Content-Type header to add to the request if JSON is added to the body. This visitor does not add a Content-Type header unless you specify one here.
public
setContentTypeHeader([string $header = 'application/json' ]) : self
Parameters
- $header : string = 'application/json'
-
Header to set when JSON is added (e.g. application/json)
Return values
selfvisit()
Called once for each parameter being visited that matches the location type
public
visit(CommandInterface $command, RequestInterface $request, Parameter $param, mixed $value) : mixed
Parameters
- $command : CommandInterface
-
Command being visited
- $request : RequestInterface
-
Request being visited
- $param : Parameter
-
Parameter being visited
- $value : mixed
-
Value to set
prepareValue()
Prepare (filter and set desired name for request item) the value for request.
protected
prepareValue(mixed $value, Parameter $param) : array<string|int, mixed>|mixed
Parameters
- $value : mixed
- $param : Parameter
Return values
array<string|int, mixed>|mixedresolveRecursively()
Map nested parameters into the location_key based parameters
protected
resolveRecursively(array<string|int, mixed> $value, Parameter $param) : array<string|int, mixed>
Parameters
- $value : array<string|int, mixed>
-
Value to map
- $param : Parameter
-
Parameter that holds information about the current key
Return values
array<string|int, mixed> —Returns the mapped array