summaryrefslogtreecommitdiff
path: root/framework/Web/Services/TSoapService.php
blob: a2db2e274eccb00c7e1677322e0329ac9fa4c1d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
 * TSoapService class file
 *
 * @author Knut Urdalen <knut.urdalen@gmail.com>
 * @link http://www.pradosoft.com
 * @copyright Copyright &copy; 2006 PradoSoft
 * @license http://www.pradosoft.com/license/
 * @package System.Web.Services
 */

//Prado::using('System.Web.Services.TWebService');

require_once dirname(__FILE__).'/../../3rdParty/WsdlGen/WsdlGenerator.php';

/**
 * TSoapService class
 *
 * TSoapService provides
 *
 * @author Knut Urdalen <knut.urdalen@gmail.com>
 * @package System.Web.Services
 * @since 3.1
 */
class TSoapService extends TService {

  private $_class;

  private $_server; // reference to the SOAP server

  /**
   * Constructor.
   * Sets default service ID to 'soap'.
   */
  public function __construct() {
    $this->setID('soap');
  }

  /**
   * Initializes the service.
   * This method is required by IService interface and is invoked by application.
   * @param TXmlElement service configuration
   */
  public function init($config) {
    // nothing to do here
  }

  /**
   * Runs the service.
   * 
   * This will serve a WSDL-file of the Soap server if 'wsdl' is provided as a key in
   * the URL, else if will serve the Soap server.
   */
  public function run() {
    Prado::trace("Running SOAP service",'System.Web.Services.TSoapService');

    $this->setSoapServer($this->getRequest()->getServiceParameter());
    Prado::using($this->getSoapServer()); // Load class

    // TODO: Fix protocol and host
    $uri = 'http://'.$_SERVER['HTTP_HOST'].$this->getRequest()->getRequestUri();

    //print_r($this->getRequest());
    if($this->getRequest()->itemAt('wsdl') !== null) { // Show WSDL-file
      // TODO: Check WSDL cache
      // Solution: Use Application Mode 'Debug' = no caching, 'Performance' = use cachez
      $uri = str_replace('&wsdl', '', $uri); // throw away the 'wsdl' key (this is a bit dirty)
      $uri = str_replace('wsdl', '', $uri); // throw away the 'wsdl' key (this is a bit dirty)
      $wsdl = WsdlGenerator::generate($this->_class, $uri);
      $this->getResponse()->setContentType('text/xml');
      $this->getResponse()->write($wsdl);
    } else { // Provide service
      // TODO: use TSoapServer
      $this->_server = new SoapServer($uri.'&wsdl');
      $this->_server->setClass($this->getSoapServer());
      $this->_server->handle();
    }
  }

  /**
   * @return TSoapServer
   */
  public function getSoapServer() {
    return $this->_class;
  }

  /**
   * @param TSoapServer $class
   */
  public function setSoapServer($class) {
    // TODO: ensure $class instanceof TSoapServer
    $this->_class = $class;
  }

  public function getPersistence() {

  }
  
}

?>