How to map a javascript class to a php class?
I will write a parser in php that will convert the jqplot library to it's php equivalent OOP mapping. The goal is to allow jqplot configuration from php (using the js library of course)
Can you recommend a better way to parse this js code other then using regular expressions ?
sample code
/**
* Class: Axis
* An individual axis object. Cannot be instantiated directly, but created
* by the Plot oject. Axis properties can be set or overriden by the
* options passed in from the user.
*
*/
function Axis(name) {
$.jqplot.ElemContainer.call(this);
// Group: Properties
//
// Axes options are specified within an axes object at the top level of the
// plot options like so:
// > {
// > axes: {
// > xaxis: {min: 5},
// > yaxis: {min: 2, max: 8, numberTicks:4},
// > x2axis: {pad: 1.5},
// > y2axis: {ticks:[22, 44, 66, 88]}
// > }
// > }
// There are 4 axes, 'xaxis', 'yaxis', 'x2axis', 'y2axis'. Any or all of
// which may be specified.
this.name = name;
this._series = [];
// prop: show
// Wether to display the axis on the graph.
this.show = false;
// prop: tickRenderer
// A class of a rendering engine for creating the ticks labels displayed on the plot,
// See .
this.tickRenderer = $.jqplot.AxisTickRenderer;
// prop: tickOptions
开发者_Go百科 // Options that will be passed to the tickRenderer, see options.
this.tickOptions = {};
// prop: labelRenderer
// A class of a rendering engine for creating an axis label.
this.labelRenderer = $.jqplot.AxisLabelRenderer;
// prop: labelOptions
// Options passed to the label renderer.
this.labelOptions = {};
// prop: label
// Label for the axis
this.label = null;
// prop: showLabel
// true to show the axis label.
this.showLabel = true;
Here is the parser which might be useful for you. On the other hand I'm not sure that parsing JS in php for making valid configuration is the best way to go. Why don't you consider generating configuration JSON in php without parsing the actual JS code?
精彩评论