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

Revision 5509, 8.5 KB checked in by gustavo, 12 years ago (diff)

Ticket #2488 - Adicionar cabecalho de licenca em arquivos que nao o possuem

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