PHP根據wsdl生成呼叫soapwebservice程式碼
PHP根據wsdl生成呼叫soap webservice程式碼
- <?php
- class soap_code_create {
- public $wsdl;
- public $root_dir;
- private $soap;
- private $class_pre;
- private $php_pre_separation;
- private $php_end_separation;
- private $br_separation;
- public function __construct($wsdl, $root_dir, $class_pre) {
- $this->wsdl = $wsdl;
- $this->root_dir = $root_dir;
- $this->soap = new SoapClient ( $wsdl );
- $this->class_pre = $class_pre;
- $this->php_pre_separation = “<?php “;
- $this->php_end_separation = “?>”;
- $this->br_separation = ”
“; - }
- public function getFunctions() {
- return $this->soap->__getFunctions ();
- }
- public function getTypes() {
- return $this->soap->__getTypes ();
- }
- public function write_file($file_path, $content) {
- $handle = fopen ( $file_path, `a` );
- fwrite ( $handle, $content );
- fclose ( $handle );
- }
- public function create_construct_pre() {
- return “public function __construct($parmas){“ . $this->br_separation;
- }
- public function create_construct_end() {
- return “}” . $this->br_separation;
- }
- public function create_base_class() {
- $types = $this->getTypes ();
- if (sizeof ( $types ) > 0) {
- foreach ( $types as $type ) {
- $type_array = split ( ”
“, $type ); - $x_size = sizeof ( $type_array );
- if ($x_size > 0) {
- $vars = array ();
- $class_content_string = “”;
- $class_name = “”;
- foreach ( $type_array as $k_x => $x_value ) {
- if ($k_x == 0) {
- //處理獲取檔名
- $class_name = str_ireplace ( ” {“, “”, $x_value );
- $class_name = str_ireplace ( “struct “, “”, $class_name );
- $class_name = str_ireplace ( ” “, “”, $class_name );
- //生成初始字串
- if($this->class_pre == “”){
- $class_name = $class_name;
- }else {
- $class_name = $this->class_pre . “_” . $class_name;
- }
- } elseif ($k_x == ($x_size – 1)) {
- //處理}沒有任何操作
- } else {
- $body = str_ireplace ( “;”, “”, $x_value );
- $body = $this->cut_first_letter ( $body, ” “ );
- $body = $this->cut_end_letter ( $body, ” “ );
- $var = split ( ” “, $body );
- $vars [] = $var;
- }
- }
- $class_content_string .= $this->php_pre_separation;
- $class_content_string .= $this->br_separation;
- $class_content_string .= “class “ . $class_name . ” { “;
- $class_content_string .= $this->br_separation;
- $content_var = “”;
- $content_fun = “”;
- if (sizeof ( $vars ) > 0) {
- foreach ( $vars as $v ) {
- $content_var .= “public $” . $v [1] . “; “ . $this->br_separation;
- }
- foreach ( $vars as $v2 ) {
- $content_fun .= “$” . “this->” . $v2 [1] . ” = “ . “$” . “parmas[`” . $v2 [1] . “`];”;
- $content_fun .= $this->br_separation;
- }
- }
- $class_content_string .= $content_var;
- $class_content_string .= $this->create_construct_pre ();
- $class_content_string .= $content_fun;
- $class_content_string .= $this->create_construct_end ();
- $class_content_string .= “}” . $this->br_separation;
- $class_content_string .= $this->php_end_separation;
- $class_file_name = $class_name . “.class.php”;
- $file_path = $this->root_dir . “/” . $class_file_name;
- $this->write_file ( $file_path, $class_content_string );
- }
- }
- }
- }
- /**
- * 去除字串前的特定字元
- */
- public function cut_first_letter($letters, $split) {
- $strlen = strlen ( $letters );
- $first_flag = false;
- $letters_cut_first = “”;
- for($i = 0; $i < $strlen; $i ++) {
- if ($first_flag) {
- continue;
- }
- $current_letter = substr ( $letters, $i, 1 );
- $next_i = ($i == $strlen – 1) ? $strlen – 1 : $i + 1;
- $next_letter = substr ( $letters, $next_i, 1 );
- if ($current_letter != $split) {
- $first_flag = true;
- $letters_cut_first = $letters;
- }
- if ($current_letter == $split && $next_letter != $split) {
- $first_flag = true;
- $letters_cut_first = substr ( $letters, $next_i, $strlen – $i );
- }
- }
- return $letters_cut_first;
- }
- /**
- * 去除字串尾部的指定字元
- */
- public function cut_end_letter($letters, $split) {
- $strlen = strlen ( $letters );
- $letters_cut_end = “”;
- $end_flag = false;
- for($j = $strlen; $j > 0; $j –) {
- if ($end_flag) {
- continue;
- }
- $end_letter = substr ( $letters, $j, 1 );
- $end_letter_pre = substr ( $letters, $j – 1, 1 );
- if ($end_letter != $split) {
- $end_flag = true;
- $letters_cut_end = $letters;
- }
- if ($end_letter == $split && $end_letter_pre != $split) {
- $end_flag = true;
- $letters_cut_end = substr ( $letters, 0, $j );
- }
- }
- return $letters_cut_end;
- }
- }
- ?>
本文轉自許琴 51CTO部落格,原文連結:http://blog.51cto.com/xuqin/925185,如需轉載請自行聯絡原作者
相關文章
- 根據api檔案生成程式碼API
- mybatis根據表逆向自動化生成程式碼MyBatis
- EF3.1 根據資料庫生成程式碼資料庫
- 根據URL地址生成二維碼
- PHP根據資料表自動生成CURD操作PHP
- Python 根據id生成唯一碼Python
- 機器學習根據文字生成圖片教程(附python程式碼)機器學習Python
- OpenAPI Generator,根據Swagger/OpenAPI生成程式碼的工具APISwagger
- 前端利器!讓AI根據手繪原型生成HTML | 教程+程式碼前端AI原型HTML
- 前端慌不慌?AI根據手繪原型生成HTML【附程式碼】前端AI原型HTML
- 使用cmd webservice wsdl網址生成客戶端程式碼Web客戶端
- perl根據函式名動態呼叫函式
- 一個根據程式碼自動生成UML的外掛,助你看原始碼事半功倍原始碼
- 根據現有 C#程式碼檔案生成擴充套件程式碼檔案的想法C#套件
- 根據表結構,自動生成匯入指令碼指令碼
- 根據事務程式碼找User exit
- PHP呼叫webservice遇到 Soap WSDL Error - "failed to load external entityPHPWebErrorAI
- 根據字元型別和密碼長度隨機生成密碼字元型別密碼隨機
- PHP5開發之WSDL,SOAP呼叫實現過程PHP
- dev 根據datatable動態生成gridviewdevView
- 根據DELTA自動生成SQL語句SQL
- 根據程式的ID取得該程式的SQL指令碼SQL指令碼
- JVM 模板直譯器之如何根據位元組碼生成彙編碼?JVM
- VS中根據實體生成資料庫資料庫
- php 陣列根據元素從小到大排序PHP陣列排序
- 前後端分離-根據程式碼講解思路後端
- city-picker根據縣區程式碼初始化
- Shell 指令碼 ,, 根據程式號退出 從而關機指令碼
- 根據TCODE找使用者出口的程式碼
- spring boot itextPdf根據模板生成pdf檔案Spring Boot
- 根據常用漢字生成雜亂的句子 --- javaJava
- EF:根據實體類生成表結構SQLSQL
- Oracle如何根據SQL_TEXT生成SQL_IDOracleSQL
- 根據時間範圍呼叫gitLab介面查詢Gitlab
- 根據身份證號碼獲取性別資訊程式碼例項
- Laravel根據使用者id生成四位數唯一邀請碼Laravel
- P001-根據編碼規則自動生成ID的函式函式
- linux 下根據埠kill 程式Linux