class RestfulFormatterHalXml in RESTful 7
@file Contains RestfulFormatterHalJson.
Hierarchy
- class \RestfulPluginBase implements RestfulPluginInterface
- class \RestfulFormatterBase implements RestfulFormatterInterface
- class \RestfulFormatterHalJson implements RestfulFormatterInterface
- class \RestfulFormatterHalXml implements RestfulFormatterInterface
- class \RestfulFormatterHalJson implements RestfulFormatterInterface
- class \RestfulFormatterBase implements RestfulFormatterInterface
Expanded class hierarchy of RestfulFormatterHalXml
1 string reference to 'RestfulFormatterHalXml'
- hal_xml.inc in modules/
restful_example/ plugins/ formatter/ hal_xml.inc
File
- modules/
restful_example/ plugins/ formatter/ RestfulFormatterHalXml.class.php, line 8 - Contains RestfulFormatterHalJson.
View source
class RestfulFormatterHalXml extends \RestfulFormatterHalJson implements \RestfulFormatterInterface {
/**
* Content Type
*
* @var string
*/
protected $contentType = 'application/xml; charset=utf-8';
/**
* {@inheritdoc}
*/
public function render(array $structured_data) {
return $this
->arrayToXML($structured_data, new SimpleXMLElement('<api/>'))
->asXML();
}
/**
* Converts the input array into an XML formatted string.
*
* @param array $data
* The input array.
* @param SimpleXMLElement $xml
* The object that will perform the conversion.
*
* @return SimpleXMLElement
*/
protected function arrayToXML(array $data, SimpleXMLElement $xml) {
foreach ($data as $key => $value) {
if (is_array($value)) {
if (!is_numeric($key)) {
$subnode = $xml
->addChild("{$key}");
$this
->arrayToXML($value, $subnode);
}
else {
$subnode = $xml
->addChild("item{$key}");
$this
->arrayToXML($value, $subnode);
}
}
else {
$xml
->addChild("{$key}", htmlspecialchars("{$value}"));
}
}
return $xml;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RestfulFormatterBase:: |
protected | property | The entity handler containing more info about the request. | |
RestfulFormatterBase:: |
public | function |
Formats the un-structured data into the output format. Overrides RestfulFormatterInterface:: |
|
RestfulFormatterBase:: |
public | function |
Generic constructor. Overrides RestfulPluginBase:: |
|
RestfulFormatterHalJson:: |
protected | function | Add HATEOAS links to list of item. | |
RestfulFormatterHalJson:: |
protected | function | Add Hateoas to a single row. | |
RestfulFormatterHalJson:: |
public | function |
Returns the content type for the selected output format. Overrides RestfulFormatterBase:: |
|
RestfulFormatterHalJson:: |
protected | function | Checks if the current plugin has a defined curie. | |
RestfulFormatterHalJson:: |
protected | function | Move the fields referencing other resources to the _embed key. | |
RestfulFormatterHalJson:: |
public | function |
Massages the raw data to create a structured array to pass to the renderer. Overrides RestfulFormatterInterface:: |
|
RestfulFormatterHalJson:: |
public | function | Massage the data of a single row. | |
RestfulFormatterHalJson:: |
protected | function | Prefix a property name with the curie, if present. | |
RestfulFormatterHalXml:: |
protected | property |
Content Type Overrides RestfulFormatterHalJson:: |
|
RestfulFormatterHalXml:: |
protected | function | Converts the input array into an XML formatted string. | |
RestfulFormatterHalXml:: |
public | function |
Renders an array in the selected format. Overrides RestfulFormatterHalJson:: |
|
RestfulPluginBase:: |
protected | property | The plugin definition array. | |
RestfulPluginBase:: |
public | function |
Gets information about the restful plugin. Overrides RestfulPluginInterface:: |
|
RestfulPluginBase:: |
public | function |
Gets information about the restful plugin key. Overrides RestfulPluginInterface:: |
|
RestfulPluginBase:: |
public | function |
Sets information about the restful plugin. Overrides RestfulPluginInterface:: |
|
RestfulPluginBase:: |
public | function |
Gets information about the restful plugin key. Overrides RestfulPluginInterface:: |