ApiOpenStudio PHPDoc

Xml extends OutputResponse
in package
Uses ConvertToXmlTrait, DetectTypeTrait

Class Xml

Outputs the results as XML.

Table of Contents

$id  : mixed
Processor ID.
$status  : mixed
The HTTP output status.
$data  : DataContainer
The output data.
$details  : array<string|int, mixed>
{@inheritDoc}
$header  : string
Content-type header value.
$logger  : MonologWrapper
Logger object.
$meta  : array<string|int, mixed>
Metadata for the processor.
$request  : Request
All the request details.
__construct()  : mixed
details()  : array<string|int, mixed>
Return details for processor.
detectType()  : string
Detect the type of data that is input .
fromArrayToXml()  : string|null
Convert array to XML string.
fromBooleanToXml()  : string
Convert boolean to XML string.
fromFileToXml()  : string
Convert file to XML string.
fromFloatToXml()  : string
Convert float to XML string.
fromHtmlToXml()  : string
Convert an HTML string to XML string.
fromImageToXml()  : string
Convert an image string to XML string.
fromIntegerToXml()  : string
Convert integer to XML string.
fromJsonToXml()  : string
Convert JSON string to XML string.
fromTextToXml()  : string
Convert text to XML string.
fromUndefinedToXml()  : string
Convert undefined to XML.
fromXmlToXml()  : string
Convert XML string to XML 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.
setHeader()  : void
Set the response headers.
setResponseCode()  : void
Set the HTML response code.
val()  : mixed|DataContainer
Process a variable into a final result for the processor.
array2xml()  : string
Recursive method to convert an array into XML format.
castData()  : void
Cast the data to XML.
getBaseXmlWrapper()  : SimpleXMLElement
Get the base SimpleXMLElement wrapper for XML for converting non XML inputs to XML output.
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.

$status

The HTTP output status.

public mixed $status

The output status.

$details

{@inheritDoc}

protected array<string|int, mixed> $details = [ 'name' => 'Xml', 'machineName' => 'xml', // phpcs:ignore 'description' => 'Output the results of the resource in XML format in the response. This does not need to be added to the resource - it will be automatically detected by the Accept header.', 'menu' => 'Output', 'input' => [], ]

Details of the processor.

$header

Content-type header value.

protected string $header = 'Content-Type:application/xml'

The string to contain the content type header value.

$meta

Metadata for the processor.

protected array<string|int, mixed> $meta

$request

All the request details.

protected Request $request

Request.

Methods

__construct()

public __construct(array<string|int, mixed> &$meta, Request &$request[, MonologWrapper|null $logger = null ]) : mixed
Parameters
$meta : array<string|int, mixed>

Metadata for the processor.

$request : Request

The full request object.

$logger : MonologWrapper|null = null

The logger.

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.

fromArrayToXml()

Convert array to XML string.

public fromArrayToXml(array<string|int, mixed>|null $array) : string|null
Parameters
$array : array<string|int, mixed>|null
Tags
throws
ApiException
Return values
string|null

fromBooleanToXml()

Convert boolean to XML string.

public fromBooleanToXml(bool|null $boolean) : string
Parameters
$boolean : bool|null
Return values
string

fromFileToXml()

Convert file to XML string.

public fromFileToXml( $file) : string
Parameters
$file :
Return values
string

fromFloatToXml()

Convert float to XML string.

public fromFloatToXml(float|null $float) : string
Parameters
$float : float|null
Return values
string

fromHtmlToXml()

Convert an HTML string to XML string.

public fromHtmlToXml(string|null $html) : string
Parameters
$html : string|null
Return values
string

fromImageToXml()

Convert an image string to XML string.

public fromImageToXml( $image) : string
Parameters
$image :
Return values
string

fromIntegerToXml()

Convert integer to XML string.

public fromIntegerToXml(int|float|null $integer) : string
Parameters
$integer : int|float|null
Return values
string

fromJsonToXml()

Convert JSON string to XML string.

public fromJsonToXml(string|null $json) : string
Parameters
$json : string|null
Return values
string

fromTextToXml()

Convert text to XML string.

public fromTextToXml(string|null $text) : string
Parameters
$text : string|null
Return values
string

fromUndefinedToXml()

Convert undefined to XML.

public fromUndefinedToXml( $data) : string
Parameters
$data :
Return values
string

fromXmlToXml()

Convert XML string to XML string.

public fromXmlToXml(string|null $xml) : string
Parameters
$xml : string|null
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
throws
ApiException
Return values
mixed

setHeader()

Set the response headers.

public setHeader() : void
Return values
void

setResponseCode()

Set the HTML response code.

public setResponseCode() : void
Return values
void

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
throws
ApiException

Invalid key or data.

Return values
mixed|DataContainer

array2xml()

Recursive method to convert an array into XML format.

protected array2xml(array<string|int, mixed> $array, SimpleXMLElement $xml) : string
Parameters
$array : array<string|int, mixed>

Input array.

$xml : SimpleXMLElement

A SimpleXMLElement element.

Return values
string

A populated SimpleXMLElement.

castData()

Cast the data to XML.

protected castData() : void
Tags
throws
ApiException

Throw an exception if unable to convert the data.

Return values
void

getBaseXmlWrapper()

Get the base SimpleXMLElement wrapper for XML for converting non XML inputs to XML output.

protected getBaseXmlWrapper([string $baseTag = 'apiOpenStudioWrapper' ]) : SimpleXMLElement
Parameters
$baseTag : string = 'apiOpenStudioWrapper'
Tags
throws
ApiException
Return values
SimpleXMLElement

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
throws
ApiException

Invalid data type.

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.

Tags
throws
ApiException

Invalid value.

Return values
void

Search results