Skip to content

Commit

Permalink
Merge pull request #22 from DeuxHuitHuit/text
Browse files Browse the repository at this point in the history
Multiple small fixes
  • Loading branch information
Nils Hörrmann committed Jun 25, 2014
2 parents 479732a + 15b00cf commit 0e81568
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
# Remote Datasource

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.
#### Version 2.0

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.

## Installation

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".

2. Create a new Remote Datasource via the Datasource Editor, choosing Remote Datasource from the Source dropdown (it's under __From extensions)
2. Create a new Remote Datasource via the Datasource Editor, choosing Remote Datasource from the Source dropdown (it's under __From extensions)

## API

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:

````php
/**
* This methods allows custom remote data source to set other
* properties on the HTTP gateway, like Authentication or other
* parameters. This method is call just before the `exec` method.
*
* @param Gateway $gateway
* the Gateway object that will be use for the current HTTP request
* passed by reference
*/
public static function prepareGateway(&$gateway) {}

/**
* This methods allows custom remote data source to read the returned
* data before it becomes only available in the XML.
*
* @since Remote Datasource 2.0
* @param string $data
* the parsed xml string data returned by the Gateway by reference
*/
public function exposeData(&$data) {}
````
16 changes: 11 additions & 5 deletions data-sources/datasource.remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static function isValidURL($url, $timeout = 6, $format = 'xml', $fetch_UR
$gateway->setopt('HTTPHEADER', array('Accept: text/csv, */*'));
}

static::prepareGateway($gateway);
self::prepareGateway($gateway);

$data = $gateway->exec();
$info = $gateway->getInfoLast();
Expand Down Expand Up @@ -366,7 +366,8 @@ public static function buildEditor(XMLElement $wrapper, array &$errors = array()
Widget::Select('fields[' . self::getClass() . '][format]', array(
array('xml', $settings[self::getClass()]['format'] == 'xml', 'XML'),
array('json', $settings[self::getClass()]['format'] == 'json', 'JSON'),
array('csv', $settings[self::getClass()]['format'] == 'csv', 'CSV')
array('csv', $settings[self::getClass()]['format'] == 'csv', 'CSV'),
array('txt', $settings[self::getClass()]['format'] == 'txt', 'TEXT')
), array(
'class' => 'picker'
))
Expand Down Expand Up @@ -662,7 +663,7 @@ public function execute(array &$param_pool = null)
$ch->setopt('HTTPHEADER', array('Accept: text/csv, */*'));
}

$this->prepareGateway($ch);
self::prepareGateway($ch);

$data = $ch->exec();
$info = $ch->getInfoLast();
Expand Down Expand Up @@ -721,8 +722,13 @@ public function execute(array &$param_pool = null)
array('message' => $ex->getMessage())
);
}
} elseif (!General::validateXML($data, $errors, false, new XsltProcess)) {

} elseif ($this->dsParamFORMAT == 'txt') {
$txtElement = new XMLElement('entry');
$txtElement->setValue(General::wrapInCDATA($data));
$data = $txtElement->generate();
$txtElement = null;
}
else if (!General::validateXML($data, $errors, false, new XsltProcess)) {
// If the XML doesn't validate..
$writeToCache = false;
}
Expand Down
7 changes: 6 additions & 1 deletion extension.meta.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension id="remote_datasource" status="released" xmlns="http://getsymphony.com/schemas/extension/1.0">
<name>Remote Datasource</name>
<description>A datasource that consumes XML, JSON or CSV content.</description>
<description>A datasource that consumes XML, JSON, CSV or TEXT content.</description>
<repo type="github">https://github.com/symphonycms/remote_datasource</repo>
<url type="issues">https://github.com/symphonycms/remote_datasource/issues</url>
<authors>
<author>
<name github="symphonycms" symphony="team">Symphony Team</name>
</author>
</authors>
<releases>
<release version="2.1.0" date="2014-06-25" min="2.4">
- Add support for text format (a copy of the html response body)
- Add some documentation
</release>
<release version="2.0.1" date="2014-06-24" min="2.4">
- Clean-up
</release>
Expand Down

0 comments on commit 0e81568

Please sign in to comment.