source: trunk/phpgwapi/inc/class.wsdl.inc.php @ 2

Revision 2, 7.8 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2/*
3
4        SOAPx4
5        by Dietrich Ayala (C) 2001 dietrich@ganx4.com
6
7        This project began based on code from the 2 projects below,
8        and still contains some original code. The licenses of both must be respected.
9
10        XML-RPC for PHP
11        originally by Edd Dumbill (C) 1999-2000
12
13        SOAP for PHP
14        by Victor Zou (C) 2000-2001 <victor@gigaideas.com.cn>
15
16        this is a class that loads a wsdl file and makes it's data available to an application
17        it should provide methods that allow both client and server usage of it
18
19        also should have methods for creating a wsdl file from scratch and
20        serializing wsdl into valid markup
21*/
22
23        class wsdl
24        {
25                // constructor
26                function wsdl($wsdl=False)
27                {       
28                        // define internal arrays of bindings, ports, operations, messages, etc.
29                        $this->complexTypes = array();
30                        $this->messages = array();
31                        $this->currentMessage;
32                        $this->portOperations = array();
33                        $this->currentOperation;
34                        $this->portTypes = array();
35                        $this->currentPortType;
36                        $this->bindings = array();
37                        $this->currentBinding;
38                        // debug switch
39                        $this->debug_flag = False;
40                        // parser vars
41                        $this->parser;
42                        $this->position;
43                        $this->depth;
44                        $this->depth_array = array();
45
46                        if($wsdl == "-1")
47                        {
48                                $wsdl=False;
49                        }
50                        // Check whether content has been read.
51                        if($wsdl)
52                        {
53                                $wsdl_string = join("",file($wsdl));
54                                // Create an XML parser.
55                                $this->parser = xml_parser_create();
56                                // Set the options for parsing the XML data.
57                                //xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
58                                xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
59                                // Set the object for the parser.
60                                xml_set_object($this->parser, &$this);
61                                // Set the element handlers for the parser.
62                                xml_set_element_handler($this->parser, 'start_element','end_element');
63                                xml_set_character_data_handler($this->parser,'character_data');
64                                //xml_set_default_handler($this->parser, 'default_handler');
65
66                                // Parse the XML file.
67                                if(!xml_parse($this->parser,$wsdl_string,True))
68                                {
69                                        // Display an error message.
70                                        $this->debug(sprintf('XML error on line %d: %s',
71                                                xml_get_current_line_number($this->parser),
72                                                xml_error_string(xml_get_error_code($this->parser))));
73                                        $this->fault = True;
74                                }
75                                xml_parser_free($this->parser);
76                        }
77                }
78
79                // start-element handler
80                function start_element($parser, $name, $attrs)
81                {
82                        // position in the total number of elements, starting from 0
83                        $pos = $this->position++;
84                        $depth = $this->depth++;
85                        // set self as current value for this depth
86                        $this->depth_array[$depth] = $pos;
87
88                        // find status, register data
89                        switch($this->status)
90                        {
91                                case 'types':
92                                switch($name)
93                                {
94                                        case 'schema':
95                                                $this->schema = True;
96                                                break;
97                                        case 'complexType':
98                                                $this->currentElement = $attrs['name'];
99                                                $this->schemaStatus = 'complexType';
100                                                break;
101                                        case 'element':
102                                                $this->complexTypes[$this->currentElement]['elements'][$attrs['name']] = $attrs;
103                                                break;
104                                        case 'complexContent':
105                                                break;
106                                        case 'restriction':
107                                                $this->complexTypes[$this->currentElement]['restrictionBase'] = $attrs['base'];
108                                                break;
109                                        case 'sequence':
110                                                $this->complexTypes[$this->currentElement]['order'] = 'sequence';
111                                                break;
112                                        case "all":
113                                                $this->complexTypes[$this->currentElement]['order'] = 'all';
114                                                break;
115                                        case 'attribute':
116                                                if($attrs['ref'])
117                                                {
118                                                        $this->complexTypes[$this->currentElement]['attrs'][$attrs['ref']] = $attrs;
119                                                }
120                                                elseif($attrs['name'])
121                                                {
122                                                        $this->complexTypes[$this->currentElement]['attrs'][$attrs['name']] = $attrs;
123                                                }
124                                                break;
125                                        }
126                                        break;
127                                case 'message':
128                                        if($name == 'part')
129                                        {
130                                                $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
131                                        }
132                                        break;
133                                case 'portType':
134                                        switch($name)
135                                        {
136                                                case 'operation':
137                                                        $this->currentOperation = $attrs['name'];
138                                                        $this->portTypes[$this->currentPortType][$attrs['name']] = $attrs['parameterOrder'];
139                                                break;
140                                                default:
141                                                        $this->portOperations[$this->currentOperation][$name]= $attrs;
142                                                        break;
143                                        }
144                                        break;
145                                case 'binding':
146                                        switch($name)
147                                        {
148                                                case 'soap:binding':
149                                                        $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding],$attrs);
150                                                        break;
151                                                case 'operation':
152                                                        $this->currentOperation = $attrs['name'];
153                                                        $this->bindings[$this->currentBinding]['operations'][$attrs['name']] = array();
154                                                        break;
155                                                case 'soap:operation':
156                                                        $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
157                                                        break;
158                                                case 'input':
159                                                        $this->opStatus = 'input';
160                                                case 'soap:body':
161                                                        $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
162                                                        break;
163                                                case 'output':
164                                                        $this->opStatus = 'output';
165                                                        break;
166                                        }
167                                        break;
168                                case 'service':
169                                        switch($name)
170                                        {
171                                                case 'port':
172                                                        $this->currentPort = $attrs['name'];
173                                                        $this->ports[$attrs['name']] = $attrs;
174                                                        break;
175                                                case 'soap:address':
176                                                        $this->ports[$this->currentPort]['location'] = $attrs['location'];
177                                                        break;
178                                        }
179                                        break;
180                        }
181                        // set status
182                        switch($name)
183                        {
184                                case 'types':
185                                        $this->status = 'types';
186                                        break;
187                                case 'message':
188                                        $this->status = 'message';
189                                        $this->messages[$attrs['name']] = array();
190                                        $this->currentMessage = $attrs['name'];
191                                        break;
192                                case 'portType':
193                                        $this->status = 'portType';
194                                        $this->portTypes[$attrs['name']] = array();
195                                        $this->currentPortType = $attrs['name'];
196                                        break;
197                                case 'binding':
198                                        $this->status = 'binding';
199                                        $this->currentBinding = $attrs['name'];
200                                        $this->bindings[$attrs['name']]['type'] = $attrs['type'];
201                                        break;
202                                case 'service':
203                                        $this->status = 'service';
204                                        break;
205                        }
206                        // get element prefix
207                        if(ereg(":",$name))
208                        {
209                                $prefix = substr($name,0,strpos($name,':'));
210                        }
211                }
212
213                function getEndpoint($portName)
214                {
215                        if($endpoint = $this->ports[$portName]['location'])
216                        {
217                                return $endpoint;
218                        }
219                        return False;
220                }
221
222                function getPortName($operation)
223                {
224                        @reset($this->ports);
225                        while(list($port,$portAttrs) = @each($this->ports));
226                        /* foreach($this->ports as $port => $portAttrs) */
227                        {
228                                $binding = substr($portAttrs['binding'],4);
229                                @reset($this->bindings[$binding]['operations']);
230                                while(list($op,$opAttrs) = @each($this->bindings[$binding]['operations']))
231                                /* foreach($this->bindings[$binding]["operations"] as $op => $opAttrs) */
232                                {
233                                        if($op == $operation)
234                                        {
235                                                return $port;
236                                        }
237                                }
238                        }
239                }
240
241                function getSoapAction($portName,$operation)
242                {
243                        if($binding = substr($this->ports[$portName]['binding'],4))
244                        {
245                                if($soapAction = $this->bindings[$binding]['operations'][$operation]['soapAction'])
246                                {
247                                        return $soapAction;
248                                }
249                                return False;
250                        }
251                        return False;
252                }
253
254                function getNamespace($portName,$operation)
255                {
256                        if($binding = substr($this->ports[$portName]['binding'],4))
257                        {
258                                //$this->debug("looking for namespace using binding '$binding', port '$portName', operation '$operation'");
259                                if($namespace = $this->bindings[$binding]['operations'][$operation]['input']['namespace'])
260                                {
261                                        return $namespace;
262                                }
263                                return False;
264                        }
265                        return False;
266                }
267
268                // end-element handler
269                function end_element($parser, $name)
270                {
271                        // position of current element is equal to the last value left in depth_array for my depth
272                        $pos = $this->depth_array[$this->depth];
273                        // bring depth down a notch
274                        $this->depth--;
275                }
276
277                // element content handler
278                function character_data($parser, $data)
279                {
280                        $pos = $this->depth_array[$this->depth];
281                        $this->message[$pos]['cdata'] .= $data;
282                }
283
284                function debug($string)
285                {
286                        if($this->debug_flag)
287                        {
288                                $this->debug_str .= "$string\n";
289                        }
290                }
291        }
292?>
Note: See TracBrowser for help on using the repository browser.