note 105172 added to function.xmlrpc-encode-request
| From: | phatkm-itdotde at osu1 dot php dot net | Date: | Mon, 01 Aug 2011 12:13:29 +0000 |
| Subject: | note 105172 added to function.xmlrpc-encode-request | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182041@lists.php.net to get a copy of this message | ||
<?php
/**
* A small Xml-Rpc Client class as simple as it can be.
* It uses PHP's magic overloads for a simple worklow.
*
* Example:
*
* $rpc = new XmlRpcClient( "http://www.example.com/xmlrpc/" );
* $data = $rpc->namespace->namespace->method(); // Will produce a method called
namespace.namespace.method
*
* var_dump( $data );
*/
class XmlRpcClient
{
protected $_url;
protected $_namespace;
protected $_clients;
public function __construct( $url, $namespace = '' )
{
$this->_url = (string)$url;
$this->_namespace = (string)$namespace;
$this->_clients = array();
}
public function __get( $namespace )
{
if( !key_exists( $namespace, $this->_clients ) )
$this->_clients[ $namespace ] = new XmlRpcClient( $this->_url, strlen( $this->_namespace
) > 0 ? "$this->_namespace.$namespace" : $namespace );
return $this->_clients[ $namespace ];
}
public function __call( $method, array $parameters = array() )
{
$request = xmlrpc_encode_request( strlen( $this->_namespace ) > 0 ?
"$this->_namespace.$method" : $method, $parameters );
$context = stream_context_create(
array(
'http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $request
)
)
);
$file = file_get_contents( $this->_url, false, $context );
$response = xmlrpc_decode( $file );
if( !$response )
throw new XmlRpcClientException( array( 'faultString' => 'Invalid response from
' . $this->_url ) );
if( xmlrpc_is_fault( $response ) )
throw new XmlRpcClientException( $response );
return $response;
}
}
/**
* Will be thrown by XmlRpcClient on faults.
*/
class XmlRpcClientException extends Exception
{
public function __construct( $response )
{
parent::__construct( $response[ 'faultString' ], $response[ 'faultCode' ] );
}
}
$rpc = new XmlRpcClient( "http://smartastro.de/astroportal/public/xmlrpc/"
);
$data = $rpc->tarocards->getCardData();
var_dump( $data );
?>
----
Server IP: 69.147.83.197
Probable Submitter: 92.198.15.96
----
Manual Page -- http://www.php.net/manual/en/function.xmlrpc-encode-request.php
Edit -- https://master.php.net/note/edit/105172
Del: integrated -- https://master.php.net/note/delete/105172/integrated
Del: useless -- https://master.php.net/note/delete/105172/useless
Del: bad code -- https://master.php.net/note/delete/105172/bad+code
Del: spam -- https://master.php.net/note/delete/105172/spam
Del: non-english -- https://master.php.net/note/delete/105172/non-english
Del: in docs -- https://master.php.net/note/delete/105172/in+docs
Del: other reasons-- https://master.php.net/note/delete/105172
Reject -- https://master.php.net/note/reject/105172
Search -- https://master.php.net/manage/user-notes.php