⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client_round2_interop.php

📁 PHP v6.0 For Linux 运行环境:Win9X/ WinME/ WinNT/ Win2K/ WinXP
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php//// +----------------------------------------------------------------------+// | PHP Version 4                                                        |// +----------------------------------------------------------------------+// | Copyright (c) 1997-2003 The PHP Group                                |// +----------------------------------------------------------------------+// | This source file is subject to version 2.02 of the PHP license,      |// | that is bundled with this package in the file LICENSE, and is        |// | available through the world-wide-web at                              |// | http://www.php.net/license/2_02.txt.                                 |// | If you did not receive a copy of the PHP license and are unable to   |// | obtain it through the world-wide-web, please send a note to          |// | license@php.net so we can mail you a copy immediately.               |// +----------------------------------------------------------------------+// | Authors: Shane Caraveo <Shane@Caraveo.com>                           |// +----------------------------------------------------------------------+//// $Id: client_round2_interop.php,v 1.19 2006/01/01 13:25:34 sniper Exp $//require_once 'DB.php'; // PEAR/DBrequire_once 'client_round2_params.php';require_once 'test.utility.php';require_once 'config.php';error_reporting(E_ALL ^ E_NOTICE);class Interop_Client{    // database DNS    var $DSN = "";    var $baseURL = "";    // our central interop server, where we can get the list of endpoints    var $interopServer = "http://www.whitemesa.net/wsdl/interopInfo.wsdl";    // our local endpoint, will always get added to the database for all tests    var $localEndpoint;    // specify testing    var $currentTest = 'base';      // see $tests above    var $paramType = 'php';     // 'php' or 'soapval'    var $useWSDL = 0;           // 1= do wsdl tests    var $numServers = 0;        // 0 = all    var $specificEndpoint = ''; // test only this endpoint    var $testMethod = '';       // test only this method    var $skipEndpointList = array(); // endpoints to skip    var $nosave = 0;    var $startAt = ''; // start in list at this endpoint    // debug output    var $show = 1;    var $debug = 0;    var $showFaults = 0; // used in result table output    // PRIVATE VARIABLES    var $dbc = NULL;    var $totals = array();    var $tests = array('base','GroupB', 'GroupC');    var $paramTypes = array('php', 'soapval');    var $endpoints = array();    var $html = 1;    function Interop_Client() {        global $interopConfig;        $this->DSN = $interopConfig['DSN'];        $this->baseURL = $interopConfig['baseURL'];        //$this->baseURL = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);        // set up the database connection        $this->dbc = DB::connect($this->DSN, true);        // if it errors out, just ignore it and rely on regular methods        if (DB::isError($this->dbc)) {            echo $this->dbc->getMessage();            $this->dbc = NULL;        }        // set up local endpoint        $this->localEndpoint['base'] = (object)array(                                'endpointName'=>'PHP ext/soap',                                'endpointURL'=>$this->baseURL.'/server_round2_base.php',                                'wsdlURL'=>$this->baseURL.'/interop.wsdl.php'                              );        $this->localEndpoint['GroupB'] = (object)array(                                'endpointName'=>'PHP ext/soap',                                'endpointURL'=>$this->baseURL.'/server_round2_groupB.php',                                'wsdlURL'=>$this->baseURL.'/interopB.wsdl.php'                              );        $this->localEndpoint['GroupC'] = (object)array(                                'endpointName'=>'PHP ext/soap',                                'endpointURL'=>$this->baseURL.'/server_round2_groupC.php',                                'wsdlURL'=>$this->baseURL.'/echoheadersvc.wsdl.php');    }    function _fetchEndpoints(&$soapclient, $test) {        $this->_getEndpoints($test, 1);        // retreive endpoints from the endpoint server        $endpointArray = $soapclient->__soapCall("GetEndpointInfo",array("groupName"=>$test),array('soapaction'=>"http://soapinterop.org/",'uri'=>"http://soapinterop.org/"));        if (is_soap_fault($endpointArray) || PEAR::isError($endpointArray)) {            if ($this->html) print "<pre>";            print $soapclient->wire."\n";            print_r($endpointArray);            if ($this->html) print "</pre>";            print "\n";            return;        }        // add our local endpoint        if ($this->localEndpoint[$test]) {          array_push($endpointArray, $this->localEndpoint[$test]);        }        if (!$endpointArray) return;        // reset the status to zero        $res = $this->dbc->query("update endpoints set status = 0 where class='$test'");        if (DB::isError($res)) {            die ($res->getMessage());        }        if (is_object($res)) $res->free();        // save new endpoints into database        foreach($endpointArray as $k => $v){            if (array_key_exists($v->endpointName,$this->endpoints)) {                $res = $this->dbc->query("update endpoints set endpointURL='{$v->endpointURL}', wsdlURL='{$v->wsdlURL}', status=1 where id={$this->endpoints[$v->endpointName]['id']}");            } else {                $res = $this->dbc->query("insert into endpoints (endpointName,endpointURL,wsdlURL,class) values('{$v->endpointName}','{$v->endpointURL}','{$v->wsdlURL}','$test')");            }            if (DB::isError($res)) {                die ($res->getMessage());            }            if (is_object($res)) $res->free();        }    }    /**    *  fetchEndpoints    * retreive endpoints interop server    *    * @return boolean result    * @access private    */    function fetchEndpoints($test = NULL) {        // fetch from the interop server        try {            $soapclient = new SoapClient($this->interopServer);            if ($test) {                $this->_fetchEndpoints($soapclient, $test);            } else {                foreach ($this->tests as $test) {                    $this->_fetchEndpoints($soapclient, $test);                }                $test = 'base';            }        } catch (SoapFault $fault) {            if ($this->html) {                echo "<pre>$fault</pre>\n";            } else {                echo "$fault\n";            }            return NULL;        }        // retreive all endpoints now        $this->currentTest = $test;        $x = $this->_getEndpoints($test);        return $x;    }    /**    *  getEndpoints    * retreive endpoints from either database or interop server    *    * @param string base (see local var $tests)    * @param boolean all (if false, only get valid endpoints, status=1)    * @return boolean result    * @access private    */    function getEndpoints($base = 'base', $all = 0) {        if (!$this->_getEndpoints($base, $all)) {            return $this->fetchEndpoints($base);        }        return TRUE;    }    /**    *  _getEndpoints    * retreive endpoints from database    *    * @param string base (see local var $tests)    * @param boolean all (if false, only get valid endpoints, status=1)    * @return boolean result    * @access private    */    function _getEndpoints($base = "", $all = 0) {        $this->endpoints = array();        // build sql        $sql = "select * from endpoints ";        if ($base) {            $sql .= "where class='$base' ";            if (!$all) $sql .= "and status=1";        } else        if (!$all) $sql .= "where status=1";        $sql .= " order by endpointName";                $db_ep = $this->dbc->getAll($sql,NULL, DB_FETCHMODE_ASSOC );        if (DB::isError($db_ep)) {            echo $sql."\n";            echo $db_ep->getMessage();            return FALSE;        }        // rearange the array        foreach ($db_ep as $entry) {            $this->endpoints[$entry['endpointName']] = $entry;        }        if (count($this->endpoints) > 0) {            $this->currentTest = $base;            return TRUE;        }        return FALSE;    }    /**    *  getResults    * retreive results from the database, stuff them into the endpoint array    *    * @access private    */    function getResults($test = 'base', $type = 'php', $wsdl = 0) {        // be sure we have the right endpoints for this test result        $this->getEndpoints($test);        // retreive the results and put them into the endpoint info        $sql = "select * from results where class='$test' and type='$type' and wsdl=$wsdl";        $results = $this->dbc->getAll($sql,NULL, DB_FETCHMODE_ASSOC );        foreach ($results as $result) {            // find the endpoint            foreach ($this->endpoints as $epn => $epi) {                if ($epi['id'] == $result['endpoint']) {                    // store the info                    $this->endpoints[$epn]['methods'][$result['function']] = $result;                    break;                }            }        }    }    /**    *  saveResults    * save the results of a method test into the database    *    * @access private    */    function _saveResults($endpoint_id, &$soap_test) {        if ($this->nosave) return;        $result = $soap_test->result;        $wire = $result['wire'];        if ($result['success']) {            $success = 'OK';            $error = '';        } else {            $success = $result['fault']->faultcode;            $pos = strpos($success,':');            if ($pos !== false) {              $success = substr($success,$pos+1);                             }            $error = $result['fault']->faultstring;            if (!$wire) $wire= $result['fault']->detail;        }        $test_name = $soap_test->test_name;        $sql = "delete from results where endpoint=$endpoint_id ".                    "and class='$this->currentTest' and type='$this->paramType' ".                    "and wsdl=$this->useWSDL and function=".                    $this->dbc->quote($test_name);        #echo "\n".$sql;        $res = $this->dbc->query($sql);        if (DB::isError($res)) {            die ($res->getMessage());        }        if (is_object($res)) $res->free();        $sql = "insert into results (endpoint,stamp,class,type,wsdl,function,result,error,wire) ".                    "values($endpoint_id,".time().",'$this->currentTest',".                    "'$this->paramType',$this->useWSDL,".                    $this->dbc->quote($test_name).",".                    $this->dbc->quote($success).",".                    $this->dbc->quote($error).",".                    ($wire?$this->dbc->quote($wire):"''").")";        #echo "\n".$sql;        $res = $this->dbc->query($sql);        if (DB::isError($res)) {            die ($res->getMessage());        }        if (is_object($res)) $res->free();    }    /**    *  decodeSoapval    * decodes a soap value to php type, used for test result comparisions    *    * @param SOAP_Value soapval    * @return mixed result    * @access public    */    function decodeSoapval($soapval)    {        if (gettype($soapval) == "object" &&            (strcasecmp(get_class($soapval),"SoapParam") == 0 ||             strcasecmp(get_class($soapval),"SoapVar") == 0)) {                if (strcasecmp(get_class($soapval),"SoapParam") == 0)                    $val = $soapval->param_data->enc_value;                else                    $val = $soapval->enc_value;        } else {            $val = $soapval;        }        if (is_array($val)) {            foreach($val as $k => $v) {                if (gettype($v) == "object" &&                    (strcasecmp(get_class($soapval),"SoapParam") == 0 ||                    strcasecmp(get_class($soapval),"SoapVar") == 0)) {                    $val[$k] = $this->decodeSoapval($v);                }            }        }        return $val;    }    /**    *  compareResult    * compare two php types for a match    *    * @param string expect    * @param string test_result    * @return boolean result    * @access public    */    function compareResult($expect, $result, $type = NULL)    {      return compare($expect, $result);    }    /**    *  doEndpointMethod    *  run a method on an endpoint and store it's results to the database    *    * @param array endpoint_info    * @param SOAP_Test test    * @return boolean result    * @access public    */    function doEndpointMethod(&$endpoint_info, &$soap_test) {        $ok = FALSE;        // prepare a holder for the test results        $soap_test->result['class'] = $this->currentTest;        $soap_test->result['type'] = $this->paramType;        $soap_test->result['wsdl'] = $this->useWSDL;        if ($this->useWSDL) {            if (array_key_exists('wsdlURL',$endpoint_info)) {                if (!array_key_exists('client',$endpoint_info)) {                    try {                        $endpoint_info['client'] = new SoapClient($endpoint_info['wsdlURL'], array("trace"=>1));                    } catch (SoapFault $ex) {                        $endpoint_info['client']->wsdl->fault = $ex;                    }                }                $soap =& $endpoint_info['client'];                # XXX how do we determine a failure on retreiving/parsing wsdl?                if ($soap->wsdl->fault) {                    $fault = $soap->wsdl->fault;                    $soap_test->setResult(0,'WSDL',                                          $fault->faultstring."\n\n".$fault->detail,                                          $fault->faultstring,                                          $fault                                          );                    return FALSE;                }            } else {                $fault = new SoapFault('WSDL',"no WSDL defined for $endpoint");                $soap_test->setResult(0,'WSDL',                                      $fault->faultstring,                                      $fault->faultstring,                                      $fault                                      );                return FALSE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -