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:
Ingo Schommer 2009-09-21 09:55:43 +00:00
parent 74b2307ca8
commit 2cb99122d3
2 changed files with 72 additions and 14 deletions

View File

@ -1,15 +1,24 @@
<?php <?php
/** /**
* Soap server class. * Soap server class which auto-generates a WSDL
* See {@link SOAPModelAccess} for an auto-generated * file to initialize PHPs integrated {@link SoapServer} class.
* SOAP API for your models. *
* See {@link SOAPModelAccess} for an auto-generated SOAP API for your models.
* *
* @todo Improve documentation * @todo Improve documentation
* @package sapphire * @package sapphire
* @subpackage integration * @subpackage integration
*/ */
class SapphireSoapServer extends Controller { class SapphireSoapServer extends Controller {
/**
* @var array Map of method name to arguments.
*/
static $methods = array(); static $methods = array();
/**
* @var array
*/
static $xsd_types = array( static $xsd_types = array(
'int' => 'xsd:int', 'int' => 'xsd:int',
'boolean' => 'xsd:boolean', 'boolean' => 'xsd:boolean',
@ -19,15 +28,25 @@ class SapphireSoapServer extends Controller {
function wsdl() { function wsdl() {
ContentNegotiator::disable(); ContentNegotiator::disable();
header("Content-type: text/xml"); $this->getResponse()->addHeader("Content-Type", "text/xml");
return array(); return array();
} }
/**
* @return string
*/
function getWSDLURL() { function getWSDLURL() {
return Director::absoluteBaseURLWithAuth() . $this->Link() . "wsdl"; return Director::absoluteBaseURLWithAuth() . $this->Link() . "wsdl";
} }
/**
* @return DataObjectSet Collection of ArrayData elements describing
* the method (keys: 'Name', 'Arguments', 'ReturnType')
*/
function Methods() { function Methods() {
$methods = array();
foreach($this->stat('methods') as $methodName => $arguments) { foreach($this->stat('methods') as $methodName => $arguments) {
$returnType = $arguments['_returns']; $returnType = $arguments['_returns'];
unset($arguments['_returns']); unset($arguments['_returns']);
@ -49,9 +68,17 @@ class SapphireSoapServer extends Controller {
return new DataObjectSet($methods); return new DataObjectSet($methods);
} }
/**
* @return string
*/
function TargetNamespace() { function TargetNamespace() {
return Director::absoluteBaseURL(); return Director::absoluteBaseURL();
} }
/**
* @return string
*/
function ServiceURL() { function ServiceURL() {
return Director::absoluteBaseURLWithAuth() . $this->class . '/'; return Director::absoluteBaseURLWithAuth() . $this->class . '/';
} }

View 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);
}
}