Skip to content

Instantly share code, notes, and snippets.

@tony-landis
Created December 3, 2008 07:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tony-landis/31456 to your computer and use it in GitHub Desktop.
Save tony-landis/31456 to your computer and use it in GitHub Desktop.
Smarty Soap Plugin (PHP)
<?php
/**
* Smarty {soap} plugin
*
* Type: function<br>
* Name: soap<br>
* Purpose: post http data and display results from soap webservice
* Params: url, post(true/false - passes along orig params), assign,
* Usage: {soap assign=soapResponse
* endpoint=http://www.site.com/search.soap
* call=resource..search
* var=(string)Text <- Format for setting
params
* debug=true|false }
*/
function smarty_function_soap($params, &$smarty)
{
global $_REQUEST;
if(empty($params['endpoint']) || empty($params['assign']) ||
empty($params['call'])) return false;
// use global include path for nusoap
require_once "includes/class/nusoap/nusoap.php";
// set params
$skip = array('endpoint', 'assign', 'call');
$soapParam=array();
foreach($params as $key=>$param) {
if(!in_array($key, $skip)) {
if
(preg_match('/\\((string|int|integer|bool|boolean|float|decimal|date)\\)(.+)/',
$param, $rs)) {
array_push($soapParam, new soapval($key,
"xsd:{$rs[1]}", "{$rs[2]}"));
}
}
}
// send request
$client = new soapclientw($params['endpoint']);
$response = $client->call($params['call'], $soapParam);
if(!empty($params['debug'])) {
echo "<pre>";
print_r($response);
print_r($client);
echo "</pre>";
}
$smarty->assign($params['assign'], $response);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment