summaryrefslogtreecommitdiff
path: root/lib/prado/framework/3rdParty/WsdlGen/WsdlOperation.php
blob: 91adbda405003ce0fb9283755a0d274ac0a60615 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
 * WsdlOperation file.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the BSD License.
 *
 * Copyright(c) 2005 by Marcus Nyeholt. All rights reserved.
 *
 * To contact the author write to {@link mailto:tanus@users.sourceforge.net Marcus Nyeholt}
 * This file is part of the PRADO framework from {@link http://www.xisc.com}
 *
 * @author Marcus Nyeholt		<tanus@users.sourceforge.net>
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @package System.Web.Services.SOAP
 */

/**
 * Represents a WSDL Operation. This is exported for the portTypes and bindings
 * section of the soap service
 * @author 		Marcus Nyeholt		<tanus@users.sourceforge.net>
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @version 	$Revision$
 */
class WsdlOperation
{
	/**
	 * The name of the operation
	 */
	private $operationName;

	/**
	 * Documentation for the operation
	 */
	private $documentation;

	/**
	 * The input wsdl message
	 */
	private $inputMessage;

	/**
	 * The output wsdl message
	 */
	private $outputMessage;

	public function __construct($name, $doc='')
	{
		$this->operationName = $name;
		$this->documentation = $doc;
	}

	public function setInputMessage(WsdlMessage $msg)
	{
		$this->inputMessage = $msg;
	}

	public function setOutputMessage(WsdlMessage $msg)
	{
		$this->outputMessage = $msg;
	}

	/**
	 * Sets the message elements for this operation into the wsdl document
	 * @param 	DOMElement 		$wsdl		The parent domelement for the messages
	 * @param 	DomDocument		$dom		The dom document to create the messages as children of
	 */
	public function setMessageElements(DOMElement $wsdl, DOMDocument $dom)
	{

		$input = $this->inputMessage->getMessageElement($dom);
		$output = $this->outputMessage->getMessageElement($dom);

		$wsdl->appendChild($input);
		$wsdl->appendChild($output);
	}

	/**
	 * Get the port operations for this operation
	 * @param 	DomDocument		$dom		The dom document to create the messages as children of
	 * @return 	DomElement					The dom element representing this port.
	 */
	public function getPortOperation(DomDocument $dom)
	{
		$operation = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:operation');
		$operation->setAttribute('name', $this->operationName);

		$documentation = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:documentation', htmlentities($this->documentation));
		$input = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:input');
		$input->setAttribute('message', 'tns:'.$this->inputMessage->getName());
		$output = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:output');
		$output->setAttribute('message', 'tns:'.$this->outputMessage->getName());

		$operation->appendChild($documentation);
		$operation->appendChild($input);
		$operation->appendChild($output);

		return $operation;
	}

	/**
	 * Build the binding operations.
	 * TODO: Still quite incomplete with all the things being stuck in, I don't understand
	 * a lot of it, and it's mostly copied from the output of nusoap's wsdl output.
	 * @param 	DomDocument		$dom		The dom document to create the binding as children of
	 * @param 	string			$namespace	The namespace this binding is in.
	 * @return 	DomElement					The dom element representing this binding.
	 */
	public function getBindingOperation(DomDocument $dom, $namespace, $style='rpc')
	{
		$operation = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:operation');
		$operation->setAttribute('name', $this->operationName);

		$soapOperation = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/soap/', 'soap:operation');
		$method = $this->operationName;
		$soapOperation->setAttribute('soapAction', $namespace.'#'.$method);
		$soapOperation->setAttribute('style', $style);

		$input = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:input');
		$output = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:output');

		$soapBody = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/soap/', 'soap:body');
		$soapBody->setAttribute('use', 'encoded');
		$soapBody->setAttribute('namespace', $namespace);
		$soapBody->setAttribute('encodingStyle', 'http://schemas.xmlsoap.org/soap/encoding/');
		$input->appendChild($soapBody);
		$output->appendChild(clone $soapBody);

		$operation->appendChild($soapOperation);
		$operation->appendChild($input);
		$operation->appendChild($output);

		return $operation;
	}
}