PHP Classes
elePHPant
Icontem

File: readme

Recommend this page to a friend!
  Classes of Tom Schaefer  >  QTransfer  >  readme  >  Download  
File: readme
Role: Auxiliary data
Content type: text/plain
Description: readme
Class: QTransfer
Send HTTP requests and process XML responses
Author: By
Last change: add
Date: 9 years ago
Size: 2,878 bytes
 

Contents

Class file image Download
---------
QTransfer
---------

QTransfer is a collection of classes which can be used for exchanging
data in xml format between servers language independently.
You can use it i.e. for ASP or SAAS software application based on php.

The request scheme (xsd) can be delivered to a customer who gets an API
like interface for producing valid xml based requests.

The sample setup demonstrates how to
- setup xsd schemes,
- prepare request xml data streams which request specific application data
- validate incoming responses


Sample Setup Request XML:

	$request = new Transfer_XmlRequest("Test","Module","index");
	$request->setSchema("request");
	$request->render(); // renders the domdocument to string
	if($request->isValid()) {
		$requestXML = $request->getXml(); // pure XML
	} else {
		echo "invalid request";
		exit;
	}

Q:	What does this piece of code?
A:	It builds a xml and checks its integrity. This xml is laterly send to a server
	which processes the incoming xml structure.

	sample xml output:
	<?xml version="1.0" encoding="UTF-8"?>
		<transfer>
			<head>
				<context>Test</context>
				<module>Module</module>
				<action>index</action>
				<checksum>--40 chars long checksum string here--</checksum>
				<format>xml</format>
				<version>0.1.1</version>
			</head>
			<body>
			</body>
		</transfer>

Q: Why do I have to validate the request?
A: Suppose you want to deliver some data to a customer from your server. The customer
   only has to know how to send a xml stream to a specific adress and that he will receive
   a xmlml response. He must not know anything about server language etc.. He only
   has to know how to setup his request for being able to receive xml data.
   The validation of the xml, which is send by the customer, is helps to
   avoid failures. If a xml validation fails then he knows that something went
   wrong. The major advantage of such a validation is? A customer's server and the serving host
   must not be speak the same language. So it is language independent.
   You can write PHP and your customer writes JSP, does not matter.



Sample customer request sends the xml to the hosted service front-controller etc.:

	$c	= Transfer_Curl::getInstance()
		->doPostXML("http://www.query4u.de/test/index.php",$requestXML);


The variable $c gets the response xml. Now, the response can be validated
against a reponse schema which is parametrized like the request.

	$response = new Transfer_XmlResponse("Test","Module","index");
	$response->setSchema("response");
	$response->setOutput($c);
	$response->render();

	if($response->isValid()) {
		header("content-type: text/xml");
		echo $response->getXml();
	} else {
		echo "invalid response";
	}

Now you have the requested results in xml format which can be easily
processed by any system.