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

Revision 5934, 5.7 KB checked in by marcosw, 12 years ago (diff)

Ticket #2398 - Compatibilizacao com PHP-5.3 em alguns módulos do expresso

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