2016-05-20 7 views
0

私はPHPで開発中ですが、PHPのコアクラスから拡張する必要はありません。PHPでのコアクラスの拡張について(例SOAPクライアント)

私はSoap WebサービスプロバイダにSOA​​Pサービスを書いているとの問題があります。そのため、PHP-CLIENTクラスでは多くの検証エラーが発生します。いずれにせよ、彼らのSOAPは "機能する"ものであり、そうではありません。

私がやりたかったのは、このクラスから拡張し、targetNamespaceがその場所と異なる名前を持つなど、検証を変更することでした。私はこれをしてはならないことを知っていますが、私はゼロからSOAPクラスを作成したくありません。

このクラス(SoapClient)から拡張しようとしていたときに、メソッドにコードが全くないことに気がつきましたが、その理由を見つけることができませんでした。私は、これらのメソッドが "C"環境下で動作するか、すでに高速化されているので、多分考えていました。これが当てはまらない場合は、このクラスのコードを見て、私のニーズに合わせて変更することが大好きです。

提案、ヒントまたは説明を歓迎します。私はSoapClientコードを添付しています。

class SoapClient { 

/** 
* (PHP 5 &gt;= 5.0.1)<br/> 
* SoapClient constructor 
* @link http://php.net/manual/en/soapclient.soapclient.php 
* @param mixed $wsdl <p> 
* URI of the WSDL file or <b>NULL</b> if working in 
* non-WSDL mode. 
* </p> 
* <p> 
* During development, WSDL caching may be disabled by the 
* use of the soap.wsdl_cache_ttl <i>php.ini</i> setting 
* otherwise changes made to the WSDL file will have no effect until 
* soap.wsdl_cache_ttl is expired. 
* </p> 
* @param array $options [optional] <p> 
* An array of options. If working in WSDL mode, this parameter is optional. 
* If working in non-WSDL mode, the location and 
* uri options must be set, where location 
* is the URL of the SOAP server to send the request to, and uri 
* is the target namespace of the SOAP service. 
* </p> 
* <p> 
* The style and use options only work in 
* non-WSDL mode. In WSDL mode, they come from the WSDL file. 
* </p> 
* <p> 
* The soap_version option should be one of either 
* <b>SOAP_1_1</b> or <b>SOAP_1_2</b> to 
* select SOAP 1.1 or 1.2, respectively. If omitted, 1.1 is used. 
* </p> 
* <p> 
* For HTTP authentication, the login and 
* password options can be used to supply credentials. 
* For making an HTTP connection through 
* a proxy server, the options proxy_host, 
* proxy_port, proxy_login 
* and proxy_password are also available. 
* For HTTPS client certificate authentication use 
* local_cert and passphrase options. An 
* authentication may be supplied in the authentication 
* option. The authentication method may be either 
* <b>SOAP_AUTHENTICATION_BASIC</b> (default) or 
* <b>SOAP_AUTHENTICATION_DIGEST</b>. 
* </p> 
* <p> 
* The compression option allows to use compression 
* of HTTP SOAP requests and responses. 
* </p> 
* <p> 
* The encoding option defines internal character 
* encoding. This option does not change the encoding of SOAP requests (it is 
* always utf-8), but converts strings into it. 
* </p> 
* <p> 
* The trace option enables tracing of request so faults 
* can be backtraced. This defaults to <b>FALSE</b> 
* </p> 
* <p> 
* The classmap option can be used to map some WSDL 
* types to PHP classes. This option must be an array with WSDL types 
* as keys and names of PHP classes as values. 
* </p> 
* <p> 
* Setting the boolean trace option enables use of the 
* methods 
* SoapClient->__getLastRequest, 
* SoapClient->__getLastRequestHeaders, 
* SoapClient->__getLastResponse and 
* SoapClient->__getLastResponseHeaders. 
* </p> 
* <p> 
* The exceptions option is a boolean value defining whether 
* soap errors throw exceptions of type 
* SoapFault. 
* </p> 
* <p> 
* The connection_timeout option defines a timeout in seconds 
* for the connection to the SOAP service. This option does not define a timeout 
* for services with slow responses. To limit the time to wait for calls to finish the 
* default_socket_timeout setting 
* is available. 
* </p> 
* <p> 
* The typemap option is an array of type mappings. 
* Type mapping is an array with keys type_name, 
* type_ns (namespace URI), from_xml 
* (callback accepting one string parameter) and to_xml 
* (callback accepting one object parameter). 
* </p> 
* <p> 
* The cache_wsdl option is one of 
* <b>WSDL_CACHE_NONE</b>, 
* <b>WSDL_CACHE_DISK</b>, 
* <b>WSDL_CACHE_MEMORY</b> or 
* <b>WSDL_CACHE_BOTH</b>. 
* </p> 
* <p> 
* The user_agent option specifies string to use in 
* User-Agent header. 
* </p> 
* <p> 
* The stream_context option is a resource 
* for context. 
* </p> 
* <p> 
* The features option is a bitmask of 
* <b>SOAP_SINGLE_ELEMENT_ARRAYS</b>, 
* <b>SOAP_USE_XSI_ARRAY_TYPE</b>, 
* <b>SOAP_WAIT_ONE_WAY_CALLS</b>. 
* </p> 
* <p> 
* The keep_alive option is a boolean value defining whether 
* to send the Connection: Keep-Alive header or 
* Connection: close. 
* </p> 
* <p> 
* The ssl_method option is one of 
* <b>SOAP_SSL_METHOD_TLS</b>, 
* <b>SOAP_SSL_METHOD_SSLv2</b>, 
* <b>SOAP_SSL_METHOD_SSLv3</b> or 
* <b>SOAP_SSL_METHOD_SSLv23</b>. 
* </p> 
*/ 
public function SoapClient ($wsdl, array $options = null) {} 

/** 
* (PHP 5 &gt;= 5.0.1)<br/> 
* Calls a SOAP function (deprecated) 
* @link http://php.net/manual/en/soapclient.call.php 
* @param string $function_name 
* @param string $arguments 
* @return mixed 
*/ 
public function __call ($function_name, $arguments) {} 

/** 
* (PHP 5 &gt;= 5.0.1)<br/> 
* Calls a SOAP function 
* @link http://php.net/manual/en/soapclient.soapcall.php 
* @param string $function_name <p> 
* The name of the SOAP function to call. 
* </p> 
* @param array $arguments <p> 
* An array of the arguments to pass to the function. This can be either 
* an ordered or an associative array. Note that most SOAP servers require 
* parameter names to be provided, in which case this must be an 
* associative array. 
* </p> 
* @param array $options [optional] <p> 
* An associative array of options to pass to the client. 
* </p> 
* <p> 
* The location option is the URL of the remote Web service. 
* </p> 
* <p> 
* The uri option is the target namespace of the SOAP service. 
* </p> 
* <p> 
* The soapaction option is the action to call. 
* </p> 
* @param mixed $input_headers [optional] <p> 
* An array of headers to be sent along with the SOAP request. 
* </p> 
* @param array $output_headers [optional] <p> 
* If supplied, this array will be filled with the headers from the SOAP response. 
* </p> 
* @return mixed SOAP functions may return one, or multiple values. If only one value is returned 
* by the SOAP function, the return value of __soapCall will be 
* a simple value (e.g. an integer, a string, etc). If multiple values are 
* returned, __soapCall will return 
* an associative array of named output parameters. 
* </p> 
* <p> 
* On error, if the SoapClient object was constructed with the exceptions 
* option set to <b>FALSE</b>, a SoapFault object will be returned. 
*/ 
public function __soapCall ($function_name, array $arguments, array $options = null, $input_headers = null, array &$output_headers = null) {} 

/** 
* (PHP 5 &gt;= 5.0.1)<br/> 
* Returns last SOAP request 
* @link http://php.net/manual/en/soapclient.getlastrequest.php 
* @return string The last SOAP request, as an XML string. 
*/ 
public function __getLastRequest() {} 

/** 
* (PHP 5 &gt;= 5.0.1)<br/> 
* Returns last SOAP response 
* @link http://php.net/manual/en/soapclient.getlastresponse.php 
* @return string The last SOAP response, as an XML string. 
*/ 
public function __getLastResponse() {} 

/** 
* (PHP 5 &gt;= 5.0.1)<br/> 
* Returns the SOAP headers from the last request 
* @link http://php.net/manual/en/soapclient.getlastrequestheaders.php 
* @return string The last SOAP request headers. 
*/ 
public function __getLastRequestHeaders() {} 

/** 
* (PHP 5 &gt;= 5.0.1)<br/> 
* Returns the SOAP headers from the last response 
* @link http://php.net/manual/en/soapclient.getlastresponseheaders.php 
* @return string The last SOAP response headers. 
*/ 
public function __getLastResponseHeaders() {} 

/** 
* (PHP 5 &gt;= 5.0.1)<br/> 
* Returns list of available SOAP functions 
* @link http://php.net/manual/en/soapclient.getfunctions.php 
* @return array The array of SOAP function prototypes, detailing the return type, 
* the function name and type-hinted paramaters. 
*/ 
public function __getFunctions() {} 

/** 
* (PHP 5 &gt;= 5.0.1)<br/> 
* Returns a list of SOAP types 
* @link http://php.net/manual/en/soapclient.gettypes.php 
* @return array The array of SOAP types, detailing all structures and types. 
*/ 
public function __getTypes() {} 

/** 
* (PHP 5 &gt;= 5.0.1)<br/> 
* Performs a SOAP request 
* @link http://php.net/manual/en/soapclient.dorequest.php 
* @param string $request <p> 
* The XML SOAP request. 
* </p> 
* @param string $location <p> 
* The URL to request. 
* </p> 
* @param string $action <p> 
* The SOAP action. 
* </p> 
* @param int $version <p> 
* The SOAP version. 
* </p> 
* @param int $one_way [optional] <p> 
* If one_way is set to 1, this method returns nothing. 
* Use this where a response is not expected. 
* </p> 
* @return string The XML SOAP response. 
*/ 
public function __doRequest ($request, $location, $action, $version, $one_way = 0) {} 

/** 
* (PHP 5 &gt;= 5.0.4)<br/> 
* The __setCookie purpose 
* @link http://php.net/manual/en/soapclient.setcookie.php 
* @param string $name <p> 
* The name of the cookie. 
* </p> 
* @param string $value [optional] <p> 
* The value of the cookie. If not specified, the cookie will be deleted. 
* </p> 
* @return void No value is returned. 
*/ 
public function __setCookie ($name, $value = null) {} 

public function __getCookies() {} 

/** 
* (PHP 5 &gt;= 5.0.1)<br/> 
* Sets the location of the Web service to use 
* @link http://php.net/manual/en/soapclient.setlocation.php 
* @param string $new_location [optional] <p> 
* The new endpoint URL. 
* </p> 
* @return string The old endpoint URL. 
*/ 
public function __setLocation ($new_location = null) {} 

/** 
* (PHP 5 &gt;= 5.0.5)<br/> 
* Sets SOAP headers for subsequent calls 
* @link http://php.net/manual/en/soapclient.setsoapheaders.php 
* @param mixed $soapheaders [optional] <p> 
* The headers to be set. It could be <b>SoapHeader</b> 
* object or array of <b>SoapHeader</b> objects. 
* If not specified or set to <b>NULL</b>, the headers will be deleted. 
* </p> 
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure. 
*/ 
public function __setSoapHeaders ($soapheaders = null) {} 

}

+0

クラスを拡張して、これは単なるドキュメントです。 – anwerj

+0

私はちょうどそれを拡張することができることを知っていますが、私は検証プロセスを変更する必要があり、この理由から、それがどのように行われるかを知る必要があります。 – CTala

答えて

0

最終的には、解決策は全くありませんでした。

SOAPクラスを問題の多いサービスに接続する場合は、WSDL構造をダウンロードして必要なものに合わせて修正してください。

私はこの解決策が気に入らないのは、APIサプライヤが何かを変更した場合、それについて知る知識がないからです。

次のコードでは、SOAP呼び出しが固定XMLに対して呼び出され、サービスについて質問することができます。

$urlXML = "FIXEDXML.xml"; 
    $cliente = new SoapClient($urlXML, array(
     "trace" => true, 
     'soap_version' => SOAP_1_1, 
     'cache_wsdl' => WSDL_CACHE_NONE 
    )); 

    var_dump($cliente); 

    echo "<h1> FUNCIONES DISPONIBLES </h1>"; 
    echo '<pre>'; 
    $functiones = $cliente->__getFunctions(); 
    var_dump($functiones); 
    echo '</pre>'; 
} catch (Exception $exc) { 
    var_dump($exc); 
    echo $exc->getTraceAsString(); 
} 

これは誰かにとって役に立ちそうです。私はそれを機能させるために長い時間をかけていました。

0

あなたが任意のPHPクラスで行うようにするだけの操作を行います。

class mySoapClient extends SoapClient { 
    //override parent function 
    public function nativeFunction() { 
      //...some logic ... 
    } 
} 

ポイントは、あなたがあなたが望むほど簡単になりますかどうかを知る必要があるということです。サードパーティのライブラリを使用する方が簡単な場合もあります。コードにアクセスしてコードを変更する方法がわかります。

+0

私はそれを理解しています。しかし、私はそれを変更するためにコードを知る必要があります:) – CTala

+1

幸運:https://github.com/php/php-src:D –

関連する問題