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

Revision 2, 5.0 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*/
17
18        /*  changelog:
19        2001-07-04
20        - abstract type system to support either 1999 or 2001 schema (arg, typing still needs much
21        solidification.)
22        - implemented proxy support, based on sample code from miles lott <milos@speakeasy.net>
23        - much general cleanup of code & cleaned out what was left of original xml-rpc/gigaideas code
24        - implemented a transport argument into send() that allows you to specify different transports
25        (assuming you have implemented the function, and added it to the conditional statement in send()
26        - abstracted the determination of charset in Content-type header
27        2001-07-5
28        - fixed more weird type/namespace issues
29        */
30
31        // $path can be a complete endpoint url, with the other parameters left blank:
32        // $soap_client = new soap_client("http://path/to/soap/server");
33
34
35        // soap message class
36        class soapmsg
37        {
38                // params is an array of soapval objects
39                function soapmsg($method,$params,$method_namespace='http://testuri.org',$new_namespaces=False)
40                {
41                        // globalize method namespace
42                        $GLOBALS['methodNamespace'] = $method_namespace;
43                        $namespaces = $GLOBALS['namespaces'];
44
45                        // make method struct
46                        $this->value = CreateObject('phpgwapi.soapval',$method,"struct",$params,$method_namespace);
47                        if(is_array($new_namespaces))
48                        {
49                                $i = count($namespaces);
50                                @reset($new_namespaces);
51                                while(list($null,$v) = @each($new_namespaces))
52                                /* foreach($new_namespaces as $v) */
53                                {
54                                        $namespaces[$v] = 'ns' . $i++;
55                                }
56                                $this->namespaces = $namespaces;
57                        }
58                        $this->payload = '';
59                        $this->debug_flag = True;
60                        $this->debug_str = "entering soapmsg() with soapval ".$this->value->name."\n";
61                }
62
63                function make_envelope($payload)
64                {
65                        $namespaces = $GLOBALS['namespaces'];
66                        @reset($namespaces);
67                        while(list($k,$v) = @each($namespaces))
68                        /* foreach($namespaces as $k => $v) */
69                        {
70                                $ns_string .= " xmlns:$v=\"$k\"";
71                        }
72                        return "<SOAP-ENV:Envelope $ns_string SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
73                                . $payload . "</SOAP-ENV:Envelope>\n";
74                }
75
76                function make_body($payload)
77                {
78                        return "<SOAP-ENV:Body>\n" . $payload . "</SOAP-ENV:Body>\n";
79                }
80
81                function createPayload()
82                {
83                        $value = $this->value;
84                        $payload = $this->make_envelope($this->make_body($value->serialize()));
85                        $this->debug($value->debug_str);
86                        $payload = "<?xml version=\"1.0\"?>\n".$payload;
87                        if($this->debug_flag)
88                        {
89                                $payload .= $this->serializeDebug();
90                        }
91                        $this->payload = str_replace("\n","\r\n", $payload);
92                }
93
94                function serialize()
95                {
96                        if($this->payload == '')
97                        {
98                                $this->createPayload();
99                                return $this->payload;
100                        }
101                        else
102                        {
103                                return $this->payload;
104                        }
105                }
106
107                // returns a soapval object
108                function parseResponse($data)
109                {
110                        $this->debug("Entering parseResponse()");
111                        //$this->debug(" w/ data $data");
112                        // strip headers here
113                        //$clean_data = ereg_replace("\r\n","\n", $data);
114                        if(ereg("^.*\r\n\r\n<",$data))
115                        {
116                                $this->debug("found proper seperation of headers and document");
117                                $this->debug("getting rid of headers, stringlen: ".strlen($data));
118                                $clean_data = ereg_replace("^.*\r\n\r\n<","<", $data);
119                                $this->debug("cleaned data, stringlen: ".strlen($clean_data));
120                        }
121                        else
122                        {
123                                // return fault
124                                return CreateObject('phpgwapi.soapval',
125                                        'fault',
126                                        'SOAPStruct',
127                                        Array(
128                                                CreateObject('phpgwapi.soapval','faultcode','string','SOAP-MSG'),
129                                                CreateObject('phpgwapi.soapval','faultstring','string','HTTP Error'),
130                                                CreateObject('phpgwapi.soapval','faultdetail','string','HTTP headers were not immediately followed by \'\r\n\r\n\'')
131                                        )
132                                );
133                        }
134        /*
135                        // if response is a proper http response, and is not a 200
136                        if(ereg("^HTTP",$clean_data) && !ereg("200$", $clean_data))
137                        {
138                                // get error data
139                                $errstr = substr($clean_data, 0, strpos($clean_data, "\n")-1);
140                                // return fault
141                                return CreateObject('phpgwapi.soapval',
142                                        "fault",
143                                        "SOAPStruct",
144                                        array(
145                                                CreateObject('phpgwapi.soapval',"faultcode","string","SOAP-MSG"),
146                                                CreateObject('phpgwapi.soapval',"faultstring","string","HTTP error")
147                                        )
148                                );
149                        }
150        */
151                        $this->debug("about to create parser instance w/ data: $clean_data");
152                        // parse response
153                        $response = CreateObject('phpgwapi.soap_parser',$clean_data);
154                        // return array of parameters
155                        $ret = $response->get_response();
156                        $this->debug($response->debug_str);
157                        return $ret;
158                }
159
160                // dbg
161                function debug($string)
162                {
163                        if($this->debug_flag)
164                        {
165                                $this->debug_str .= "$string\n";
166                        }
167                }
168
169                // preps debug data for encoding into soapmsg
170                function serializeDebug()
171                {
172                        if($this->debug_flag)
173                        {
174                                return "<!-- DEBUG INFO:\n".$this->debug_str."-->\n";
175                        }
176                        else
177                        {
178                                return '';
179                        }
180                }
181        }
182?>
Note: See TracBrowser for help on using the repository browser.