Skip to content

Commit 3832eef

Browse files
author
Nils Hörrmann
committed
Merge pull request #23 from symphonycms/integration
Release Version 2.1.0
2 parents 0e844ff + 0e81568 commit 3832eef

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
11
# Remote Datasource
22

3-
The Remote Datasource allows you to consume XML or JSON sources in Symphony. This extension aims to build upon the Dynamic XML datasource functionality provided in Symphony to allow better cache control, the automatic discovery of namespaces and more flexibility.
3+
#### Version 2.0
4+
5+
The Remote Datasource allows you to consume XML, JSON, CSV and TXT sources in Symphony. This extension aims to build upon the Dynamic XML datasource functionality provided in Symphony to allow better cache control, the automatic discovery of namespaces and more flexibility.
46

57
## Installation
68

79
1. Install this extension by copying `/remote_datasource` folder to your `/extensions` folder. Then navigate to the System > Extensions page in the Symphony backend page, select the Remote Datasource extension and then apply the "Enable/Install".
810

9-
2. Create a new Remote Datasource via the Datasource Editor, choosing Remote Datasource from the Source dropdown (it's under __From extensions)
11+
2. Create a new Remote Datasource via the Datasource Editor, choosing Remote Datasource from the Source dropdown (it's under __From extensions)
12+
13+
## API
14+
15+
If you need to add custom php code in your Data Source, there is two methods that you can override in your DataSource sub-class:
16+
17+
````php
18+
/**
19+
* This methods allows custom remote data source to set other
20+
* properties on the HTTP gateway, like Authentication or other
21+
* parameters. This method is call just before the `exec` method.
22+
*
23+
* @param Gateway $gateway
24+
* the Gateway object that will be use for the current HTTP request
25+
* passed by reference
26+
*/
27+
public static function prepareGateway(&$gateway) {}
28+
29+
/**
30+
* This methods allows custom remote data source to read the returned
31+
* data before it becomes only available in the XML.
32+
*
33+
* @since Remote Datasource 2.0
34+
* @param string $data
35+
* the parsed xml string data returned by the Gateway by reference
36+
*/
37+
public function exposeData(&$data) {}
38+
````

data-sources/datasource.remote.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static function isValidURL($url, $timeout = 6, $format = 'xml', $fetch_UR
132132
$gateway->setopt('HTTPHEADER', array('Accept: text/csv, */*'));
133133
}
134134

135-
static::prepareGateway($gateway);
135+
self::prepareGateway($gateway);
136136

137137
$data = $gateway->exec();
138138
$info = $gateway->getInfoLast();
@@ -319,7 +319,7 @@ public static function buildEditor(XMLElement $wrapper, array &$errors = array()
319319
$label = Widget::Label(__('Timeout'));
320320
$label->setAttribute('class', 'column');
321321

322-
$help = new XMLElement('i', __('in minutes'));
322+
$help = new XMLElement('i', __('in seconds'));
323323
$label->appendChild($help);
324324

325325
$timeout_time = isset($settings[self::getClass()]['timeout'])
@@ -366,7 +366,8 @@ public static function buildEditor(XMLElement $wrapper, array &$errors = array()
366366
Widget::Select('fields[' . self::getClass() . '][format]', array(
367367
array('xml', $settings[self::getClass()]['format'] == 'xml', 'XML'),
368368
array('json', $settings[self::getClass()]['format'] == 'json', 'JSON'),
369-
array('csv', $settings[self::getClass()]['format'] == 'csv', 'CSV')
369+
array('csv', $settings[self::getClass()]['format'] == 'csv', 'CSV'),
370+
array('txt', $settings[self::getClass()]['format'] == 'txt', 'TEXT')
370371
), array(
371372
'class' => 'picker'
372373
))
@@ -662,7 +663,7 @@ public function execute(array &$param_pool = null)
662663
$ch->setopt('HTTPHEADER', array('Accept: text/csv, */*'));
663664
}
664665

665-
$this->prepareGateway($ch);
666+
self::prepareGateway($ch);
666667

667668
$data = $ch->exec();
668669
$info = $ch->getInfoLast();
@@ -721,8 +722,13 @@ public function execute(array &$param_pool = null)
721722
array('message' => $ex->getMessage())
722723
);
723724
}
724-
} elseif (!General::validateXML($data, $errors, false, new XsltProcess)) {
725-
725+
} elseif ($this->dsParamFORMAT == 'txt') {
726+
$txtElement = new XMLElement('entry');
727+
$txtElement->setValue(General::wrapInCDATA($data));
728+
$data = $txtElement->generate();
729+
$txtElement = null;
730+
}
731+
else if (!General::validateXML($data, $errors, false, new XsltProcess)) {
726732
// If the XML doesn't validate..
727733
$writeToCache = false;
728734
}

extension.meta.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<extension id="remote_datasource" status="released" xmlns="http://getsymphony.com/schemas/extension/1.0">
33
<name>Remote Datasource</name>
4-
<description>A datasource that consumes XML, JSON or CSV content.</description>
4+
<description>A datasource that consumes XML, JSON, CSV or TEXT content.</description>
55
<repo type="github">https://github.com/symphonycms/remote_datasource</repo>
6+
<url type="issues">https://github.com/symphonycms/remote_datasource/issues</url>
67
<authors>
78
<author>
89
<name github="symphonycms" symphony="team">Symphony Team</name>
910
</author>
1011
</authors>
1112
<releases>
13+
<release version="2.1.0" date="2014-06-25" min="2.4">
14+
- Add support for text format (a copy of the html response body)
15+
- Add some documentation
16+
</release>
1217
<release version="2.0.1" date="2014-06-24" min="2.4">
1318
- Clean-up
1419
</release>

0 commit comments

Comments
 (0)