mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Fixed content-type for SapphireSoapServer->wsdl() (#4570, thanks Cristian)
MINOR Added documentation for SapphireSoapServer git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@86876 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
74b2307ca8
commit
2cb99122d3
@ -1,15 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Soap server class.
|
||||
* See {@link SOAPModelAccess} for an auto-generated
|
||||
* SOAP API for your models.
|
||||
* 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.
|
||||
*
|
||||
* @todo Improve documentation
|
||||
* @package sapphire
|
||||
* @subpackage integration
|
||||
*/
|
||||
class SapphireSoapServer extends Controller {
|
||||
|
||||
/**
|
||||
* @var array Map of method name to arguments.
|
||||
*/
|
||||
static $methods = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
static $xsd_types = array(
|
||||
'int' => 'xsd:int',
|
||||
'boolean' => 'xsd:boolean',
|
||||
@ -19,15 +28,25 @@ class SapphireSoapServer extends Controller {
|
||||
|
||||
function wsdl() {
|
||||
ContentNegotiator::disable();
|
||||
header("Content-type: text/xml");
|
||||
$this->getResponse()->addHeader("Content-Type", "text/xml");
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function getWSDLURL() {
|
||||
return Director::absoluteBaseURLWithAuth() . $this->Link() . "wsdl";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DataObjectSet Collection of ArrayData elements describing
|
||||
* the method (keys: 'Name', 'Arguments', 'ReturnType')
|
||||
*/
|
||||
function Methods() {
|
||||
$methods = array();
|
||||
|
||||
foreach($this->stat('methods') as $methodName => $arguments) {
|
||||
$returnType = $arguments['_returns'];
|
||||
unset($arguments['_returns']);
|
||||
@ -49,24 +68,32 @@ class SapphireSoapServer extends Controller {
|
||||
|
||||
return new DataObjectSet($methods);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function TargetNamespace() {
|
||||
return Director::absoluteBaseURL();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function ServiceURL() {
|
||||
return Director::absoluteBaseURLWithAuth() . $this->class . '/';
|
||||
}
|
||||
|
||||
function index() {
|
||||
$wsdl = $this->getViewer('wsdl')->process($this);
|
||||
$wsdlFile = TEMP_FOLDER . '/sapphire-wsdl-' . $this->class;
|
||||
$fh = fopen($wsdlFile, 'w');
|
||||
fwrite($fh, $wsdl);
|
||||
fclose($fh);
|
||||
function index() {
|
||||
$wsdl = $this->getViewer('wsdl')->process($this);
|
||||
$wsdlFile = TEMP_FOLDER . '/sapphire-wsdl-' . $this->class;
|
||||
$fh = fopen($wsdlFile, 'w');
|
||||
fwrite($fh, $wsdl);
|
||||
fclose($fh);
|
||||
|
||||
$s = new SoapServer($wsdlFile, array('cache_wsdl' => WSDL_CACHE_NONE));
|
||||
$s->setClass($this->class);
|
||||
$s->handle();
|
||||
}
|
||||
$s = new SoapServer($wsdlFile, array('cache_wsdl' => WSDL_CACHE_NONE));
|
||||
$s->setClass($this->class);
|
||||
$s->handle();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
31
tests/api/SapphireSoapServerTest.php
Normal file
31
tests/api/SapphireSoapServerTest.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* @package sapphire
|
||||
* @subpackage tests
|
||||
*/
|
||||
class SapphireSoapServerTest extends FunctionalTest {
|
||||
|
||||
/**
|
||||
* @see http://open.silverstripe.com/ticket/4570
|
||||
*/
|
||||
function testWsdl() {
|
||||
$response = $this->get('SapphireSoapServerTest_MyServer/wsdl');
|
||||
|
||||
$this->assertEquals(
|
||||
$response->getHeader('Content-Type'),
|
||||
'text/xml',
|
||||
'wsdl request returns with correct XML content type'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package sapphire
|
||||
* @subpackage tests
|
||||
*/
|
||||
class SapphireSoapServerTest_MyServer extends SapphireSoapServer {
|
||||
|
||||
function Link($action = null) {
|
||||
return Controller::join_links('SapphireSoapServerTest_MyServer', $action);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user