[Solar-talk] Web Services
Paul M Jones
pmjones at solarphp.com
Mon Oct 2 09:53:19 PDT 2006
On Oct 2, 2006, at 7:31 AM, Michael Caplan wrote:
> Perhaps this is related to the thread from this weakened on nested
> controllers, but I am looking for a way to integrate web services
> (xml-rpc primarily) as an interface that is callable by
> application. Architecturally, I am wondering how I can best
> leverage Solar to integrate this. Anyone have any pointers?
With the disclaimer that I have not actually done this, I can think
of one way offhand.
Add an actionXmlrpc() method to your page controllers, then use the
_forward() method to perform the related actions, and finally switch
to an XML-RPC view/layout combination instead of the web-browser
combination. This is sort of REST-ish, but I think the idea is
applicable:
public function actionXmlrpc()
{
// get all params passed into the method
$params = func_get_args();
// find the "real" action based on the first param
$action = array_shift($params);
// forward to the "real" action with remaining params
$this->_forward($action, $params);
// $this is now populated with all the data from the action.
// reset the view and layout for xml-rpc output.
$this->_view = "xmlrpc/" . $action;
$this->_layout = "xmlrpc";
// done!
}
Given a "docs" controller and a "read" action like this URL indicates...
http://example.com/index.php/docs/read/HomePage
... you would get the XML-RPC version with a URL like this:
http://example.com/index.php/xmlrpc/docs/read/HomePage
With the above code example, you need View/xmlrpc/*.php for each
action exposed via XML-RPC, and a Layouts/xmlrpc.php file for the
layout wrapping the view.
Of course, this is a very naive example. If you have XML-RPC usage
in mind, probably best to either design your public properties for
dual use (data-view and browser-page view), or create a special
$xmlrpc property and populate it properly in each "normal" action, or
have the actionXmlrpc() method look at all $this properties and
format them properly, or some other technique that I haven't thought of.
Hope this begins to help; as I said, it's very much an off-the-cuff
first pass at the problem.
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>
More information about the solar-talk
mailing list