Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

Docs JsonRpc Proxies

Frank Kleine edited this page Apr 7, 2012 · 1 revision

Table of Contents

Generating static JSON-RPC proxy classes

In high performance applications, you may not want to generate the proxy classes for your service on-the-fly for each request. Stubbles provides a Phing task that can generate proxy classes for all services registered in the json-rpc-service.ini config file during the build process.

Target folder

The target folder for the JavaScript proxy files can be specified in the json-rpc-service.ini using the genjsdir configuration. This folder will always be relative to the docroot folder of your project.

JavaScript proxy namespace

The JavaScript proxy namespace for the JavaScript files can also be specified in the json-rpc-service.ini using the namespace property.

Starting the generation

The Stubbles build file build-stubbles.xml provides the generate-clients target, which will read the json-rpc-service.ini file and generate a JavaScript file per registered PHP class as well as a all-clients.js file that contains the proxy classes for all services.

To start the generation of the proxy clients you only need to type phing on the command line, after you set-up your project. If you changed the configuration, you only need to re-run phing to generate the clients based on the new configuration.

This will produce one file containing all proxies (allClient.js) and additionally separate files (one per proxy). If you are not using the allClients.js-file you have to initialize the (default or your own) namespace for yourself:

stubbles.json.proxy = {};
// XOR
var my.own.ns = {};

The Phing task

Of course, you can also use the Phing task in your own build file. The following XML snippet shows, how the task is used to generate proxy clients:

<stubGenerateJsonRpcProxies serviceFile="path/to/json-rpc-service.ini"
                            javaScriptNamespace="my.own.ns"/>

Clone this wiki locally