Welcome, Guest. Please login or register.
Did you miss your activation email?
May. 22, 2012, 10:50:31 AM
55238 Posts in 12404 Topics by 73715 Members
Latest Member: cust11hw7jb3nn5n
News:
 
The PRADO Community » Prado v3.x » Feature Requests » XMLPRC « previous next »
Pages: [1] Print
Author Topic: XMLPRC  (Read 4312 times)
letux
Junior Member
**

Karma: 5
Offline Offline

Posts: 31



View Profile WWW
« on: Jun. 18, 2009, 12:38:26 PM »

Hi,

I do the XMLRPC implemention :

Code:
require_once( 'XML/RPC/Server.php' );
require_once( 'XML/RPC.php' );

class TXmlRpcService extends TService
{
const DEFAULT_XMLRPC_SERVER='TXmlRpcServer';
const CONFIG_FILE_EXT='.xml';
private $_servers=array();
private $_configFile=null;
private $_serverID=null;

/**
* Constructor.
* Sets default service ID to 'xmlrpc'.
*/
public function __construct()
{
$this->setID('xmlrpc');
}

/**
* Initializes this module.
* This method is required by the IModule interface.
* @param TXmlElement configuration for this module, can be null
* @throws TConfigurationException if {@link getConfigFile ConfigFile} is invalid.
*/
public function init($config)
{
if($this->_configFile!==null)
{
  if(is_file($this->_configFile))
  {
$dom=new TXmlDocument;
$dom->loadFromFile($this->_configFile);
$this->loadConfig($dom);
}
else
throw new TConfigurationException('xmlrpcservice_configfile_invalid',$this->_configFile);
}
$this->loadConfig($config);

$this->resolveRequest();
}

/**
* Resolves the request parameter.
* It identifies the server ID.
* @throws THttpException if the server ID cannot be found
* @see getServerID
*/
protected function resolveRequest()
{
$serverID=$this->getRequest()->getServiceParameter();
$this->_serverID=$serverID;

if(!isset($this->_servers[$serverID]))
throw new THttpException(400,'xmlrpcservice_request_invalid',$serverID);
}

/**
* Loads configuration from an XML element
* @param TXmlElement configuration node
* @throws TConfigurationException if soap server id is not specified or duplicated
*/
private function loadConfig($xml)
{
foreach($xml->getElementsByTagName('xmlrpc') as $serverXML)
{
$properties=$serverXML->getAttributes();
if(($id=$properties->remove('id'))===null)
throw new TConfigurationException('xmlrpcservice_serverid_required');
if(isset($this->_servers[$id]))
throw new TConfigurationException('xmlrpcservice_serverid_duplicated',$id);
$this->_servers[$id]=$properties;
}
}

/**
* @return string external configuration file. Defaults to null.
*/
public function getConfigFile()
{
return $this->_configFile;
}

/**
* @param string external configuration file in namespace format. The file
* must be suffixed with '.xml'.
* @throws TInvalidDataValueException if the file is invalid.
*/
public function setConfigFile($value)
{
if(($this->_configFile=Prado::getPathOfNamespace($value,self::CONFIG_FILE_EXT))===null)
throw new TConfigurationException('xmlrpcservice_configfile_invalid',$value);
}

/**
* Constructs a URL with specified page path and GET parameters.
* @param string soap server ID
* @param array list of GET parameters, null if no GET parameters required
* @param boolean whether to encode the ampersand in URL, defaults to true.
* @param boolean whether to encode the GET parameters (their names and values), defaults to true.
* @return string URL for the page and GET parameters
*/
public function constructUrl($serverID,$getParams=null,$encodeAmpersand=true,$encodeGetItems=true)
{
return $this->getRequest()->constructUrl($this->getID(),$serverID,$getParams,$encodeAmpersand,$encodeGetItems);
}

/**
* @return string the XMLRPC server ID
*/
public function getServerID()
{
return $this->_serverID;
}

/**
* Creates the requested XMLRPC server.
* The XMLRPC server is initialized with the property values specified
* in the configuration.
* @return TXmlRpcServer the XMLRPC server instance
*/
protected function createServer()
{
$properties=$this->_servers[$this->_serverID];
        if(($serverClass=$properties->remove('class'))===null)
$serverClass=self::DEFAULT_XMLRPC_SERVER;
Prado::using($serverClass);
$className=($pos=strrpos($serverClass,'.'))!==false?substr($serverClass,$pos+1):$serverClass;
if($className!==self::DEFAULT_XMLRPC_SERVER && !is_subclass_of($className,self::DEFAULT_XMLRPC_SERVER))
throw new TConfigurationException('xmlrpcservice_server_invalid',$serverClass);
$server=new $className;
$server->setID($this->_serverID);
foreach($properties as $name=>$value)
$server->setSubproperty($name,$value);
return $server;
}

/**
* Runs the service.
*/
public function run()
{
Prado::trace("Running XMLRPC service",'System.Web.Services.TXmlRpcService');
$server=$this->createServer();
$this->getResponse()->setContentType('text/xml');
$this->getResponse()->setCharset('UTF-8');
    // provide XMLRPC service
Prado::trace("Handling XMLRPC request",'System.Web.Services.TXmlRpcService');
$server->run();
}
}



class TXmlRpcServer extends TApplicationComponent
{
private $_id;
private $_provider;
private $_server;

/**
* @return string the ID of the XMLRPC server
*/
public function getID()
{
return $this->_id;
}

/**
* @param string the ID of the XMLRPC server
*/
public function setID($id)
{
$this->_id=$id;
}

/**
* Handles the XMLRPC request.
*/
public function run()
{
        $server=$this->createServer();
    }

/**
* Creates the SoapServer instance.
* @return SoapServer
*/
protected function createServer()
{
if($this->_server===null)
{
            $provider=$this->getProvider();
            $providerClass=($pos=strrpos($provider,'.'))!==false?substr($provider,$pos+1):$provider;
            Prado::using($provider);

            $providerClass = new $providerClass;

            $providerClass = $providerClass ? $providerClass : this;

$this->_server =  new XML_RPC_Server($providerClass->registerFunction() , 1 );
}
return $this->_server;
}

/**
* @return string the XMLRPC provider class (in namespace format)
*/
public function getProvider()
{
return $this->_provider;
}

/**
* @param string the XMLRPC provider class (in namespace format)
*/
public function setProvider($provider)
{
$this->_provider=$provider;
}


    protected function registerFunction()
    {
        return NULL;
    }

}

I started the code from SOAP.

in application.xml

Code:
<service id="xmlrpc" class="System.Web.Services.TXmlRpcService">
      <xmlrpc id="notification" provider="Application.webservice.MYXmlRpcServer" />
    </service>

Could be possible to integrate this in a next release?
Logged
tof06
PRADO v3.x Developer
Platinum Member
*****

Karma: 92
Offline Offline

Posts: 1084



View Profile
« Reply #1 on: Jun. 18, 2009, 01:25:12 PM »

Interesting.

Do you have some sample tests ?
Are XML/RPC/Server and XML/RPC.php PEAR class ? Do they depends on PEAR ? If yes, they should be rewritten to remove this dependency, like we did for other 3rd parties class
Logged
letux
Junior Member
**

Karma: 5
Offline Offline

Posts: 31



View Profile WWW
« Reply #2 on: Jun. 19, 2009, 04:22:41 AM »

Yes they depends on PEAR XML_RPC. I will modify it to use the the 3rd party and give you a sample on how to use it.
Logged
letux
Junior Member
**

Karma: 5
Offline Offline

Posts: 31



View Profile WWW
« Reply #3 on: Jun. 19, 2009, 01:23:30 PM »

ok, you can find a sample attach to this response.

Uncompress the file PradoXMLRPC.tar.gz on a directory named PradoXMLRPC and copy:

TXmlRpcService.php in the prado framework ./prado/framework/Web/Services/
PEAR.tar.gz in the prado framework ./prado/framework/3rdParty/

* PradoXMLRPC.tar.gz (1.85 KB - downloaded 95 times.)
* TXmlRpcService.php (7.68 KB - downloaded 112 times.)
* PEAR.tar.gz (26.42 KB - downloaded 85 times.)
Logged
tof06
PRADO v3.x Developer
Platinum Member
*****

Karma: 92
Offline Offline

Posts: 1084



View Profile
« Reply #4 on: Jun. 19, 2009, 01:41:13 PM »

Thanks, we'll certainly add this to 3.2.

I think we don't need the PEAR class. It's only used (not sure, but I think so) for error handling. So, we really should remove this class, and rewrite some method in RPC and RPCServer to throw exception instead of using Pear error.
Also, pear and often other classes uses a lot of deprecated function, essentially to stay compatible with PHP4. Function like "is_a" raises runtime notices, and should be replaced by their php5 equivalent (instance of for is_a)

So, your classes need some rewriting, but it's definitively a great enhancement. Can you post an enhancement issue on google code, milestone 3.2, and referring this thread ?

Thanks.
Logged
letux
Junior Member
**

Karma: 5
Offline Offline

Posts: 31



View Profile WWW
« Reply #5 on: Jun. 19, 2009, 01:55:37 PM »

it is done

http://code.google.com/p/prado3/issues/detail?id=180

But it was done for the Milestone-3.1.6 and 3.2, can you move it?
Logged
Pages: [1] Print 
« previous next »
Jump to: