2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
2009-09-21 11:55:43 +02:00
|
|
|
* Soap server class which auto-generates a WSDL
|
|
|
|
* file to initialize PHPs integrated {@link SoapServer} class.
|
|
|
|
*
|
|
|
|
* See {@link SOAPModelAccess} for an auto-generated SOAP API for your models.
|
2009-03-14 20:09:00 +01:00
|
|
|
*
|
2008-03-03 00:24:10 +01:00
|
|
|
* @todo Improve documentation
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-02-25 03:10:37 +01:00
|
|
|
* @subpackage integration
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class SapphireSoapServer extends Controller {
|
2009-09-21 11:55:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array Map of method name to arguments.
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
static $methods = array();
|
2009-09-21 11:55:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
static $xsd_types = array(
|
|
|
|
'int' => 'xsd:int',
|
2008-08-11 05:03:52 +02:00
|
|
|
'boolean' => 'xsd:boolean',
|
2007-07-19 12:40:28 +02:00
|
|
|
'string' => 'xsd:string',
|
|
|
|
'binary' => 'xsd:base64Binary',
|
|
|
|
);
|
|
|
|
|
2011-02-13 23:14:51 +01:00
|
|
|
static $allowed_actions = array(
|
|
|
|
'index',
|
|
|
|
'wsdl'
|
|
|
|
);
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function wsdl() {
|
2009-09-21 11:55:43 +02:00
|
|
|
$this->getResponse()->addHeader("Content-Type", "text/xml");
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2009-09-21 11:55:43 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
function getWSDLURL() {
|
2008-08-11 05:03:52 +02:00
|
|
|
return Director::absoluteBaseURLWithAuth() . $this->Link() . "wsdl";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2009-09-21 11:55:43 +02:00
|
|
|
/**
|
2011-10-26 08:09:04 +02:00
|
|
|
* @return SS_List Collection of ArrayData elements describing
|
2009-09-21 11:55:43 +02:00
|
|
|
* the method (keys: 'Name', 'Arguments', 'ReturnType')
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
function Methods() {
|
2009-09-21 11:55:43 +02:00
|
|
|
$methods = array();
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach($this->stat('methods') as $methodName => $arguments) {
|
|
|
|
$returnType = $arguments['_returns'];
|
|
|
|
unset($arguments['_returns']);
|
|
|
|
|
|
|
|
$processedArguments = array();
|
|
|
|
foreach($arguments as $argument => $type) {
|
|
|
|
$processedArguments[] = new ArrayData(array(
|
|
|
|
"Name" => $argument,
|
|
|
|
"Type" => self::$xsd_types[$type],
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
$methods[] = new ArrayData(array(
|
|
|
|
"Name" => $methodName,
|
2011-05-05 12:40:24 +02:00
|
|
|
"Arguments" => new ArrayList($processedArguments),
|
2007-07-19 12:40:28 +02:00
|
|
|
"ReturnType" => self::$xsd_types[$returnType],
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-05-05 12:40:24 +02:00
|
|
|
return new ArrayList($methods);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2009-09-21 11:55:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
function TargetNamespace() {
|
|
|
|
return Director::absoluteBaseURL();
|
|
|
|
}
|
2009-09-21 11:55:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
function ServiceURL() {
|
|
|
|
return Director::absoluteBaseURLWithAuth() . $this->class . '/';
|
|
|
|
}
|
|
|
|
|
2009-09-21 11:55:43 +02:00
|
|
|
function index() {
|
|
|
|
$wsdl = $this->getViewer('wsdl')->process($this);
|
|
|
|
$wsdlFile = TEMP_FOLDER . '/sapphire-wsdl-' . $this->class;
|
|
|
|
$fh = fopen($wsdlFile, 'w');
|
|
|
|
fwrite($fh, $wsdl);
|
|
|
|
fclose($fh);
|
2009-03-04 04:44:11 +01:00
|
|
|
|
2009-09-21 11:55:43 +02:00
|
|
|
$s = new SoapServer($wsdlFile, array('cache_wsdl' => WSDL_CACHE_NONE));
|
|
|
|
$s->setClass($this->class);
|
|
|
|
$s->handle();
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2012-02-12 21:22:11 +01:00
|
|
|
|