note 128060 added to soapclient.gettypes
| From: | SergeLiatko at main dot php dot net | Date: | Wed, 28 Dec 2022 14:29:31 +0000 |
| Subject: | note 128060 added to soapclient.gettypes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220015@lists.php.net to get a copy of this message | ||
Found a nice way to parse the types into an easy to read array:
<?PHP
/**
* @param \SoapClient $soap
*
* @return array The WSDL types data as an array.
*/
function read_wsdl_types( SoapClient $soap ): array {
$wsdl_types = $soap->__getTypes();
$lookup = array();
$regexes = array(
'atomic' => '/^(\w+)\s(\w+)$/mi',
'list' => '/^(\w+)\s(\w+)[ {]+(\w+)[ }]+$/mi',
'struct' => '/(\w+)\s(\w+)[\s{]?(\w+)*[\s;}]?/mi',
);
foreach ( array_reverse( $wsdl_types ) as $wsdl_type ) {
$matches = array();
foreach ( $regexes as $type => $regex ) {
if ( preg_match_all( $regex, $wsdl_type, $matches ) ) {
break;
}
}
if ( !empty( $matches[1] ) && !empty( $matches[2] ) ) {
switch ( $type ) {
case 'atomic':
$name = array_shift( $matches[2] );
$data_type = array_shift( $matches[1] );
$lookup[ $name ] = array(
'name' => $name,
'type' => $type,
'data_type' => $data_type,
'items' => array(),
);
break;
case 'list':
$name = array_shift( $matches[2] );
$type = array_shift( $matches[1] );
$items = array_shift( $matches[3] );
$lookup[ $name ] = array(
'name' => $name,
'type' => $type,
'data_type' => $items,
'items' => array(
array(
'name' => '',
'data_type' => $items,
),
),
);
break;
case 'struct':
$name = array_shift( $matches[2] );
$type = array_shift( $matches[1] );
$items = array();
foreach ( $matches[2] as $key => $item_name ) {
$data_type = $matches[1][ $key ];
if (
( false !== strpos( $data_type, 'anonymous' ) )
&& isset( $lookup[ $data_type ]['data_type'] )
) {
$data_type = $lookup[ $data_type ]['data_type'];
}
$items[ $key ] = array(
'name' => $item_name,
'data_type' => $data_type,
);
}
$lookup[ $name ] = array(
'name' => $name,
'type' => $type,
'data_type' => $name,
'items' => $items,
);
break;
}
}
}
return array_reverse( $lookup );
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.158.213 (proxied: 83.138.234.23)
----
Manual Page -- https://php.net/manual/en/soapclient.gettypes.php
Edit -- https://main.php.net/note/edit/128060
Del: integrated -- https://main.php.net/note/delete/128060/integrated
Del: useless -- https://main.php.net/note/delete/128060/useless
Del: bad code -- https://main.php.net/note/delete/128060/bad+code
Del: spam -- https://main.php.net/note/delete/128060/spam
Del: non-english -- https://main.php.net/note/delete/128060/non-english
Del: in docs -- https://main.php.net/note/delete/128060/in+docs
Del: other reasons-- https://main.php.net/note/delete/128060
Reject -- https://main.php.net/note/reject/128060
Search -- https://main.php.net/manage/user-notes.php