Version: current

     1 <?php
     2 /**
     3  * Soap server class which auto-generates a WSDL
     4  * file to initialize PHPs integrated {@link SoapServer} class.
     5  *
     6  * See {@link SOAPModelAccess} for an auto-generated SOAP API for your models.
     7  *
     8  * @todo Improve documentation
     9  * @package sapphire
    10  * @subpackage integration
    11  */
    12 class SapphireSoapServer extends Controller {
    13
    14     /**
    15      * @var array Map of method name to arguments.
    16      */
    17     static $methods = array();
    18
    19     /**
    20      * @var array
    21      */
    22     static $xsd_types = array(
    23         'int' => 'xsd:int',
    24         'boolean' => 'xsd:boolean',
    25         'string' => 'xsd:string',
    26         'binary' => 'xsd:base64Binary',
    27     );
    28
    29     function wsdl() {
    30         $this->getResponse()->addHeader("Content-Type", "text/xml");
    31
    32         return array();
    33     }
    34
    35     /**
    36      * @return string
    37      */
    38     function getWSDLURL() {
    39         return Director::absoluteBaseURLWithAuth() . $this->Link() . "wsdl";
    40     }
    41
    42     /**
    43      * @return DataObjectSet Collection of ArrayData elements describing
    44      *  the method (keys: 'Name', 'Arguments', 'ReturnType')
    45      */
    46     function Methods() {
    47         $methods = array();
    48
    49         foreach($this->stat('methods') as $methodName => $arguments) {
    50             $returnType = $arguments['_returns'];
    51             unset($arguments['_returns']);
    52
    53             $processedArguments = array();
    54             foreach($arguments as $argument => $type) {
    55                 $processedArguments[] = new ArrayData(array(
    56                     "Name" => $argument,
    57                     "Type" => self::$xsd_types[$type],
    58                 ));
    59
    60             }
    61             $methods[] = new ArrayData(array(
    62                 "Name" => $methodName,
    63                 "Arguments" => new DataObjectSet($processedArguments),
    64                 "ReturnType" => self::$xsd_types[$returnType],
    65             ));
    66         }
    67
    68         return new DataObjectSet($methods);
    69     }
    70
    71     /**
    72      * @return string
    73      */
    74     function TargetNamespace() {
    75         return Director::absoluteBaseURL();
    76     }
    77
    78     /**
    79      * @return string
    80      */
    81     function ServiceURL() {
    82         return Director::absoluteBaseURLWithAuth() . $this->class . '/';
    83     }
    84
    85     function index() {
    86         $wsdl = $this->getViewer('wsdl')->process($this);
    87         $wsdlFile = TEMP_FOLDER . '/sapphire-wsdl-' . $this->class;
    88         $fh = fopen($wsdlFile, 'w');
    89         fwrite($fh, $wsdl);
    90         fclose($fh);
    91
    92         $s = new SoapServer($wsdlFile, array('cache_wsdl' => WSDL_CACHE_NONE));
    93         $s->setClass($this->class);
    94         $s->handle();
    95     }
    96 }
    97
    98 ?>
    99

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -