MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
class.phpwsdlformatter.php
Ir para a documentação deste ficheiro.
1
<?php
2
if
(basename($_SERVER[
'SCRIPT_FILENAME'
])==basename(__FILE__))
3
exit;
19
class
PhpWsdlFormatter
20
{
26
protected
$_parser
=
null
;
27
33
protected
$_input
=
null
;
34
40
protected
$_output
=
null
;
41
47
protected
$_offset
= 0;
48
54
protected
$_depth
= 0;
55
61
protected
$_empty
=
false
;
62
68
protected
$_buffer
=
""
;
69
100
protected
$_options
= array(
101
"bufferSize"
=> 4096,
102
"paddingString"
=>
" "
,
103
"paddingMultiplier"
=> 4,
104
"formatCData"
=>
true
,
105
"multipleLineCData"
=>
true
,
106
"wordwrapCData"
=> 75,
107
"inputEOL"
=>
"\n"
,
108
"outputEOL"
=>
"\n"
109
);
110
118
public
function
__construct
($input, $output, Array $options = array())
119
{
120
$this->_input = $input;
121
$this->_output = $output;
122
$this->_options = array_merge($this->_options, $options);
123
124
$this->_parser = xml_parser_create();
125
126
xml_set_object($this->_parser, $this);
127
128
xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING,
false
);
129
xml_parser_set_option($this->_parser, XML_OPTION_SKIP_WHITE, 0);
130
131
xml_set_element_handler($this->_parser,
"_cbElementStart"
,
"_cbElementEnd"
);
132
xml_set_character_data_handler($this->_parser,
"_cbCharacterData"
);
133
}
134
141
protected
function
_getPaddingStr
()
142
{
143
return
str_repeat($this->_options[
"paddingString"
], $this->_depth * $this->_options[
"paddingMultiplier"
]);
144
}
145
154
protected
function
_cbElementStart
($parser, $name, Array $attributes)
155
{
156
$idx = xml_get_current_byte_index($this->_parser);
157
158
$this->_empty = $this->_buffer[$idx -
$this->_offset
] ==
'/'
;
159
160
$attrs =
""
;
161
foreach
($attributes as $key => $val) {
162
$attrs .=
" "
. $key .
"=\""
. $val .
"\""
;
163
}
164
165
fwrite($this->_output, $this->
_getPaddingStr
() .
"<"
. $name . $attrs . ($this->_empty ?
' />'
:
'>'
) .
"\n"
);
166
167
if
(!$this->_empty) ++
$this->_depth
;
168
}
169
177
protected
function
_cbElementEnd
($parser, $name)
178
{
179
if
(!$this->_empty) {
180
--
$this->_depth
;
181
182
fwrite($this->_output, $this->
_getPaddingStr
() .
"</"
. $name .
">"
.
"\n"
);
183
}
else
{
184
$this->_empty =
false
;
185
}
186
}
187
195
protected
function
_cbCharacterData
($parser, $data)
196
{
197
if
(!$this->_options[
"formatCData"
]) {
198
return
;
199
}
200
201
$data = trim($data);
202
203
if
(strlen($data)) {
204
$pad = $this->
_getPaddingStr
();
205
206
if
($this->_options[
"multipleLineCData"
]) {
207
208
// remove all tabs
209
$data = str_replace(
"\t"
,
""
, $data);
210
211
// append each line with a padding string
212
$data = implode($this->_options[
"inputEOL"
] . $pad, explode($this->_options[
"inputEOL"
], $data));
213
}
214
215
if
($this->_options[
"wordwrapCData"
]) {
216
$data = wordwrap($data, $this->_options[
"wordwrapCData"
], $this->_options[
"outputEOL"
] . $pad,
false
);
217
}
218
219
fwrite($this->_output, $pad . $data .
"\n"
);
220
}
221
}
222
230
public
function
format
()
231
{
232
while
($this->_buffer = fread($this->_input, $this->_options[
"bufferSize"
])) {
233
if
(!xml_parse($this->_parser, $this->_buffer, feof($this->_input))) {
234
throw
new
Exception(sprintf(
"XML error: %s at line %d"
,
235
xml_error_string(xml_get_error_code($this->_parser)),
236
xml_get_current_line_number($this->_parser)));
237
return
;
238
}
239
240
$this->_offset += strlen($this->_buffer);
241
}
242
243
xml_parser_free($this->_parser);
244
}
245
}
PhpWsdlFormatter
Definição
class.phpwsdlformatter.php:20
PhpWsdlFormatter\$_options
$_options
Definição
class.phpwsdlformatter.php:100
PhpWsdlFormatter\_cbElementStart
_cbElementStart($parser, $name, Array $attributes)
Definição
class.phpwsdlformatter.php:154
PhpWsdlFormatter\_cbCharacterData
_cbCharacterData($parser, $data)
Definição
class.phpwsdlformatter.php:195
PhpWsdlFormatter\_getPaddingStr
_getPaddingStr()
Definição
class.phpwsdlformatter.php:141
PhpWsdlFormatter\$_depth
$_depth
Definição
class.phpwsdlformatter.php:54
PhpWsdlFormatter\_cbElementEnd
_cbElementEnd($parser, $name)
Definição
class.phpwsdlformatter.php:177
PhpWsdlFormatter\$_buffer
$_buffer
Definição
class.phpwsdlformatter.php:68
PhpWsdlFormatter\$_parser
$_parser
Definição
class.phpwsdlformatter.php:26
PhpWsdlFormatter\$_output
$_output
Definição
class.phpwsdlformatter.php:40
PhpWsdlFormatter\__construct
__construct($input, $output, Array $options=array())
Definição
class.phpwsdlformatter.php:118
PhpWsdlFormatter\$_offset
$_offset
Definição
class.phpwsdlformatter.php:47
PhpWsdlFormatter\$_input
$_input
Definição
class.phpwsdlformatter.php:33
PhpWsdlFormatter\$_empty
$_empty
Definição
class.phpwsdlformatter.php:61
PhpWsdlFormatter\format
format()
Definição
class.phpwsdlformatter.php:230
classes
contrib
phpWsdl
class.phpwsdlformatter.php
Gerado por
1.10.0