JsonRemote
extends OutputRemote
in package
Uses
ConvertToJsonTrait, DetectTypeTrait
Class JsonRemote
Outputs the results as a JSON string to a remote location.
Table of Contents
- $id : mixed
- Processor ID.
- $data : DataContainer
- The output data.
- $details : array<string|int, mixed>
- {@inheritDoc}
- $logger : MonologWrapper
- Logger object.
- $meta : array<string|int, mixed>
- Metadata for the processor.
- $request : Request
- All the request details.
- $settings : Config
- Config object.
- $transport : mixed
- __construct() : mixed
- JsonRemote constructor.
- details() : array<string|int, mixed>
- Return details for processor.
- detectType() : string
- Detect the type of data that is input .
- fromArrayToJson() : string|null
- Convert array to JSON string.
- fromBooleanToJson() : bool|null
- Convert boolean to JSON string.
- fromFileToJson() : mixed
- Convert file to JSON string.
- fromFloatToJson() : float|string|null
- Convert float to JSON string.
- fromHtmlToJson() : string
- Convert an HTML string to JSON string.
- fromImageToJson() : string|null
- Convert an image string to JSON string.
- fromIntegerToJson() : int|string|null
- Convert integer to JSON string.
- fromJsonToJson() : mixed
- Convert JSON string to JSON string.
- fromTextToJson() : string|null
- Convert text to JSON string.
- fromUndefinedToJson() : null
- Convert undefined to JSON.
- fromXmlToJson() : string
- Convert XML string to JSON string.
- isArray() : bool
- Validate a variable is an array.
- isBool() : bool
- Validate a variable is boolean.
- isEmpty() : bool
- Validate a variable is empty.
- isFloat() : bool
- Validate a variable is float.
- isHtml() : bool
- Validate a variable is HTML.
- isInt() : bool
- Validate a variable is integer.
- isJson() : bool
- Validate a variable is JSON.
- isXml() : bool
- Validate a variable is XML.
- process() : mixed
- Main processor function.
- val() : mixed|DataContainer
- Process a variable into a final result for the processor.
- castData() : mixed
- Cast the data to JSON.
- isDataContainer() : bool
- Validate if a set of data is wrapped in a DataContainer object.
- validateAllowedTypes() : void
- Validate an input for allowed variable types
- validateAllowedValues() : void
- Validate an input for allowed values.
Properties
$id
Processor ID.
public
mixed
$id
= ''
Processor ID.
$data
The output data.
protected
DataContainer
$data
The output data.
$details
{@inheritDoc}
protected
array<string|int, mixed>
$details
= ['name' => 'Json remote', 'machineName' => 'json_remote', 'description' => 'Output in the results of the resource in JSON format to a remote server.', 'menu' => 'Output', 'input' => ['filename' => ['description' => 'The output filename.', 'cardinality' => [0, 1], 'literalAllowed' => true, 'limitProcessors' => [], 'limitTypes' => ['text'], 'limitValues' => [], 'default' => 'apiopenstudio.json'], 'transport' => ['description' => 'The Transport for uploading. example: ApiOpenStudio\Plugins\TransportS3.', 'cardinality' => [1, 1], 'literalAllowed' => true, 'limitProcessors' => [], 'limitTypes' => ['text'], 'limitValues' => [], 'default' => ''], 'parameters' => [
// phpcs:ignore
'description' => 'Name/Value pairs for parameters required by the uploader, e.g. username, password, etc.',
'cardinality' => [0, '*'],
'literalAllowed' => true,
'limitProcessors' => [],
'limitTypes' => [],
'limitValues' => [],
'default' => [],
]]]
Details of the processor.
$logger
Logger object.
protected
MonologWrapper
$logger
$meta
Metadata for the processor.
protected
array<string|int, mixed>
$meta
$request
All the request details.
protected
Request
$request
Request.
$settings
Config object.
protected
Config
$settings
$transport
protected
mixed
$transport
Transport class.
Methods
__construct()
JsonRemote constructor.
public
__construct(array<string|int, mixed> &$meta, Request &$request, MonologWrapper|null $logger, mixed $data) : mixed
Parameters
- $meta : array<string|int, mixed>
- $request : Request
- $logger : MonologWrapper|null
- $data : mixed
Return values
mixed —details()
Return details for processor.
public
details() : array<string|int, mixed>
Return values
array<string|int, mixed> —detectType()
Detect the type of data that is input .
public
detectType(mixed $data) : string
Parameters
- $data : mixed
-
Data to test.
Return values
string —The data type.
fromArrayToJson()
Convert array to JSON string.
public
fromArrayToJson(array<string|int, mixed>|null $array) : string|null
Parameters
- $array : array<string|int, mixed>|null
Return values
string|null —fromBooleanToJson()
Convert boolean to JSON string.
public
fromBooleanToJson(bool|null $boolean) : bool|null
Parameters
- $boolean : bool|null
Return values
bool|null —fromFileToJson()
Convert file to JSON string.
public
fromFileToJson( $file) : mixed
Parameters
Tags
Return values
mixed —fromFloatToJson()
Convert float to JSON string.
public
fromFloatToJson(float|string|null $float) : float|string|null
Parameters
- $float : float|string|null
Return values
float|string|null —fromHtmlToJson()
Convert an HTML string to JSON string.
public
fromHtmlToJson(string $html) : string
Parameters
- $html : string
Return values
string —fromImageToJson()
Convert an image string to JSON string.
public
fromImageToJson( $image) : string|null
Parameters
Return values
string|null —fromIntegerToJson()
Convert integer to JSON string.
public
fromIntegerToJson(int|string|null $integer) : int|string|null
Parameters
- $integer : int|string|null
Return values
int|string|null —fromJsonToJson()
Convert JSON string to JSON string.
public
fromJsonToJson( $json) : mixed
Parameters
Return values
mixed —fromTextToJson()
Convert text to JSON string.
public
fromTextToJson(string|null $text) : string|null
Parameters
- $text : string|null
Return values
string|null —fromUndefinedToJson()
Convert undefined to JSON.
public
fromUndefinedToJson( $data) : null
Parameters
Return values
null —fromXmlToJson()
Convert XML string to JSON string.
public
fromXmlToJson(string $xml) : string
Parameters
- $xml : string
Tags
Return values
string —isArray()
Validate a variable is an array.
public
isArray(mixed $var) : bool
Parameters
- $var : mixed
-
Variable to test.
Return values
bool —isBool()
Validate a variable is boolean.
public
isBool(mixed $var) : bool
Parameters
- $var : mixed
-
Variable to test.
Return values
bool —isEmpty()
Validate a variable is empty.
public
isEmpty(mixed $var) : bool
Parameters
- $var : mixed
-
Variable to test.
Return values
bool —isFloat()
Validate a variable is float.
public
isFloat(mixed $var) : bool
Parameters
- $var : mixed
-
Variable to test.
Return values
bool —isHtml()
Validate a variable is HTML.
public
isHtml(mixed $var) : bool
Parameters
- $var : mixed
-
Variable to test.
Return values
bool —isInt()
Validate a variable is integer.
public
isInt(mixed $var) : bool
Parameters
- $var : mixed
-
Variable to test.
Return values
bool —isJson()
Validate a variable is JSON.
public
isJson(mixed $var) : bool
Parameters
- $var : mixed
-
Variable to test.
Return values
bool —isXml()
Validate a variable is XML.
public
isXml(mixed $var) : bool
Parameters
- $var : mixed
-
Variable to test.
Return values
bool —process()
Main processor function.
public
process() : mixed
This is where the magic happens, and should be overridden by all derived classes.
Fetches and process the processor described in the metadata. It is also the 1st stop to recursive processing of processors, so the place validate user credentials.
Tags
Return values
mixed —val()
Process a variable into a final result for the processor.
public
val(string $key[, bool|null $rawData = false ]) : mixed|DataContainer
This method can be used to process a value in its meta to return a final result that it can use. If the object is a processor, then it will process that down to a final return value, or if the obj is a simple value, then it will return that. Anything else will return an error object.
Setting $realValue to true will force the value to be the actual value, rather than a potential dataContainer.
Parameters
- $key : string
-
The key for the input variable in the meta.
- $rawData : bool|null = false
-
Return the raw data or a DataContainer.
Tags
Return values
mixed|DataContainer —castData()
Cast the data to JSON.
protected
castData() : mixed
Tags
Return values
mixed —isDataContainer()
Validate if a set of data is wrapped in a DataContainer object.
protected
isDataContainer(mixed $data) : bool
Parameters
- $data : mixed
-
DataContainer or raw data.
Return values
bool —validateAllowedTypes()
Validate an input for allowed variable types
private
validateAllowedTypes(string $type, array<string|int, mixed> $limitTypes, int $min, string $key) : void
Parameters
- $type : string
-
Input value type.
- $limitTypes : array<string|int, mixed>
-
List of limit on variable types.
- $min : int
-
Minimum number of values.
- $key : string
-
The key of the input being validated.
Tags
Return values
void —validateAllowedValues()
Validate an input for allowed values.
private
validateAllowedValues(mixed $val, array<string|int, mixed> $limitValues, int $min, string $key) : void
Parameters
- $val : mixed
-
Input value.
- $limitValues : array<string|int, mixed>
-
List of allowed values.
- $min : int
-
Minimum number of values.
- $key : string
-
The key of the input being validated.