JsonVisitor
extends AbstractResponseVisitor
in package
Location visitor used to marshal JSON response data into a formatted array.
Allows top level JSON parameters to be inserted into the result of a command. The top level attributes are grabbed from the response's JSON data using the name value by default. Filters can be applied to parameters as they are traversed. This allows data to be normalized before returning it to users (for example converting timestamps to DateTime objects).
Table of Contents
Methods
- after() : mixed
- Called after visiting all parameters
- before() : mixed
- Called before visiting all parameters. This can be used for seeding the result of a command with default data (e.g. populating with JSON data in the response then adding to the parsed data).
- visit() : mixed
- Called once for each parameter being visited that matches the location type
- recursiveProcess() : mixed
- Recursively process a parameter while applying filters
Methods
after()
Called after visiting all parameters
public
after(CommandInterface $command) : mixed
Parameters
- $command : CommandInterface
-
Command being visited
before()
Called before visiting all parameters. This can be used for seeding the result of a command with default data (e.g. populating with JSON data in the response then adding to the parsed data).
public
before(CommandInterface $command, array<string|int, mixed> &$result) : mixed
Parameters
- $command : CommandInterface
-
Command being visited
- $result : array<string|int, mixed>
-
Result value to update if needed (e.g. parsing XML or JSON)
visit()
Called once for each parameter being visited that matches the location type
public
visit(CommandInterface $command, Response $response, Parameter $param, mixed &$value[, mixed $context = null ]) : mixed
Parameters
- $command : CommandInterface
-
Command being visited
- $response : Response
-
Response being visited
- $param : Parameter
-
Parameter being visited
- $value : mixed
-
Result associative array value being updated by reference
- $context : mixed = null
-
Parsing context
recursiveProcess()
Recursively process a parameter while applying filters
protected
recursiveProcess(Parameter $param, mixed &$value) : mixed
Parameters
- $param : Parameter
-
API parameter being validated
- $value : mixed
-
Value to validate and process. The value may change during this process.