note 128061 added to soapclient.gettypes

From: Date: Wed, 28 Dec 2022 17:40:10 +0000
Subject: note 128061 added to soapclient.gettypes
Groups: php.notes 
Request: Send a blank email to php-notes+get-220016@lists.php.net to get a copy of this message
Here is the fixed version of my previous code (@moderators , please delete my previous note ) Returns a more comprehensive array of SOAP Client types as an 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 ) { $items[ $key ] = array( 'name' => $item_name, 'data_type' => $matches[1][ $key ], ); } $lookup[ $name ] = array( 'name' => $name, 'type' => $type, 'data_type' => $name, 'items' => $items, ); break; } } } array_walk( $lookup, function ( &$type, $key, $data ) { if ( !empty( $type['items'] ) ) { array_walk( $type['items'], function ( &$item, $key, $data ) { if ( !empty( $item['data_type'] ) ) { $old_data_type = $item['data_type']; $item['type'] = $data[ $old_data_type ]['type'] ?? 'atomic'; $item['data_type'] = $data[ $old_data_type ]['data_type'] ?? $old_data_type; $item['from'] = $data[ $old_data_type ]['name'] ?? ''; } }, $data ); } }, $lookup ); return array_reverse( $lookup ); } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.158.213 (proxied: 2001:861:5280:e280:5dc6:dee5:ab48:2d0c) ---- Manual Page -- https://php.net/manual/en/soapclient.gettypes.php Edit -- https://main.php.net/note/edit/128061 Del: integrated -- https://main.php.net/note/delete/128061/integrated Del: useless -- https://main.php.net/note/delete/128061/useless Del: bad code -- https://main.php.net/note/delete/128061/bad+code Del: spam -- https://main.php.net/note/delete/128061/spam Del: non-english -- https://main.php.net/note/delete/128061/non-english Del: in docs -- https://main.php.net/note/delete/128061/in+docs Del: other reasons-- https://main.php.net/note/delete/128061 Reject -- https://main.php.net/note/reject/128061 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220016) next »