1<?php
2
3// SOAP test client
4
5
6exit();
7
8
9
10function getLastRequestFormated($cli) {
11	$dom = new DomDocument;
12	$dom->loadXML($cli->__getLastRequest());
13	$dom->formatOutput = true;
14	$dom = $dom->saveXML();
15	$dom = preg_replace_callback('`(<\??[^\s>]*)([^>]*)(\??>)`', 'tag', $dom);
16	return $dom;
17}
18
19function tag($m) {
20	$m = $m[0];
21	if(preg_match('`<\[CDATA\[([^]]|\][^]]|\]\][^>])*\]\]>`i', $m)) return '<span style="color:purple">'.htmlentities($m).'</span>';
22	$start = preg_replace('`^(<\??[^\s>=]*).*`', '\1', $m);
23	$end = preg_replace('`[^?>]`', '', substr($m, -2));
24	$mid = trim(substr($m, strlen($start), -1 * strlen($end)));
25	if(preg_match_all('`([^=]+)=([^\s]*|"[^"]*")\s*`', $mid, $m)) {
26		$mid = '';
27		for($i=0; $i<count($m[0]); $i++) $mid .= ' <span style="color:green">'.htmlentities($m[1][$i]).'</span>=<span style="color:orange">'.htmlentities($m[2][$i]).'</span>';
28	}
29	return '<span style="color:blue">'.htmlentities($start).$mid.htmlentities($end).'</span>';
30}
31
32ini_set('soap.wsdl_cache_enabled', '0');
33
34//header('Content-Type: text/plain; charset=UTF-8');
35try {
36	$cli = new SoapClient('url_to_farm.wsdl_file', array('trace' => 1, 'soap_version'  => SOAP_1_1));
37
38	if(isset($_GET['a'])) {
39		print_r($cli->authenticateRemoteAppAndRun('remoteapp', 'pwd', 'animalExists', array('name' => $_GET['a'])));
40	}elseif(isset($_GET['d'])) {
41		print_r($cli->authenticateRemoteAppAndRun('remoteapp', 'pwd', 'animalDelete', array('name' => $_GET['d'])));
42	}elseif(isset($_GET['new'])) {
43		print_r($cli->authenticateRemoteAppAndRun('remoteapp', 'pwd', 'animalCreate', array('name' => $_GET['new'])));
44	}
45
46	if(isset($_GET['a']) || isset($_GET['d']) || isset($_GET['new'])) echo '<pre>'.getLastRequestFormated($cli).'</pre>';
47
48	foreach($cli->authenticateRemoteAppAndRun('remoteapp', 'pwd', 'animalsList') as $w) echo '<a href="'.$w['url'].'">'.$w['name'].'</a> <a href="?a='.$w['name'].'">check</a> <a href="?d='.$w['name'].'">del</a><br />';
49	//print_r($cli->authenticateRemoteAppAndRun('remoteapp', 'pwd', 'animalsList'));
50	echo '<a href="?new=foo'.time().'">NEW</a><br />';
51
52	echo '<pre>'.getLastRequestFormated($cli).'</pre>';
53}catch(SoapFault $f) {
54	die('SOAP::Client fault : '.$f->getMessage());
55}
56?>
57