<!-- configure output -->
<QtClientOutput sourceDir="qtc" subDir="wob" priInclude="wob.pri" classPrefix="C" clean="yes" transactionBase="WTransaction"/>
+ <QtServerOutput sourceDir="qts" subDir="wob" priInclude="wob.pri" classPrefix="C" clean="yes" transactionBase="WTransaction"/>
+ <PHPClientOutput sourceDir="phpc" subDir="wob" extension=".php" clean="yes" transactionBase="WobTransaction"/>
<PHPServerOutput sourceDir="phps" subDir="wob" extension=".php" clean="yes" transactionBase="WobTransaction"/>
<HtmlOutput sourceDir="." subDir="html" clean="yes"/>
<!-- transaction -->
<Transaction name="GetTime" mode="open">
- <Input>
- </Input>
+ <Input/>
<Call lang="php" method="Session::login($this);"/>
<Output>
<Var name="time" type="Time"/>
QMap<QString,QString>map=cls.mapping(k[i]);
QStringList mapk=cls.mappingProperties(k[i]);
for(int j=0;j<mapk.size();j++){
- QString meth=cls.mapMethod(k[i],mapk[j],"php");
+ QString meth=cls.mapMethod(k[i],mapk[j],m_lang);
if(meth!="")code+="\t$data->prop_"+mapk[j]+"="+meth+";\n";
else code+="\t$data->prop_"+mapk[j]+"=$table->"+map[mapk[j]]+";\n";
}
code+="public function toTable"+k[i]+"(&$table){\n";
for(int j=0;j<mapk.size();j++){
//do not reverse translate method conversions
- QString meth=cls.mapMethod(k[i],mapk[j],"php").trimmed();
+ QString meth=cls.mapMethod(k[i],mapk[j],m_lang).trimmed();
if(meth!="")continue;
//check that column exists
if(tab.hasColumn(map[mapk[j]])){
#define abstractClassName m_parent->abstractClassName
#define trnClassName m_parent->trnClassName
#define addLoad m_parent->addLoad
+#define m_lang m_parent->m_lang
#endif
#endif
#include "phpconst.h"
-static const QByteArray TRANSACTCLASS("class WobTransaction extends WobTransactionBase\n{\n");
-static const QByteArray TRANSACTSTART(" static public function handle(){\n try{switch(WobTransactionBase::getTransactionName()){\n");
-static const QByteArray TRANSACTEND("\tdefault:WobTransactionBase::noSuchTransaction();break;\n }}catch(WobTransactionError $er){$er->printXml();}\n }\n");
-
-WocPHPClientTransaction::WocPHPClientTransaction(WocPHPOut*p ): WocPHPTransaction(p)
-{
- //create Transaction file
- m_transact.setFileName(m_basedir+"/"+m_subdir+"/transaction"+m_fileext);
- if(!m_transact.open(QIODevice::ReadWrite|QIODevice::Truncate)){
- qDebug("Error: PHP Server Generator - cannot create transaction processor file.");
- emit errorFound();
- return;
- }
- m_transact.write(PHPSTART);
- m_transact.write(TRANSACTCLASS);
- transInfo();
- m_transact.write(TRANSACTSTART);
- addLoad("WobTransaction","transaction");
-}
-
-void WocPHPClientTransaction::transInfo()
+WocPHPClientTransaction::WocPHPClientTransaction(WocPHPOut*p )
+ :WocPHPTransaction(p)
{
- WocProcessor*woc=WocProcessor::instance();
- m_transact.write(QString(" static public function commVersion(){return \""+woc->verComm()+"\";}\n").toAscii());
- m_transact.write(QString(" static public function needCommVersion(){return \""+woc->verNeedComm()+"\";}\n").toAscii());
- m_transact.write(QString(" static public function version(){return \""+woc->verHR()+"\";}\n").toAscii());
- m_transact.write(QString(" static public function svnVersion(){return \""+woc->svnRevision()+"\";}\n\n").toAscii());
- m_transact.write(QString(" static public function svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n\n").toAscii());
- m_transact.write(QString(" static public function svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii());
}
-void WocPHPClientTransaction::transInfo2()
-{
- WocProcessor*woc=WocProcessor::instance();
- //transaction names
- QString code=" static public function transactionNames(){\n\treturn array(";
- QStringList tns=woc->transactionNames();
- for(int i=0;i<tns.size();i++){
- if(i)code+=",";
- code+="\n\t\ttranslate(\"_TransactionNames\",\""+tns[i]+"\")";
- }
- code+=");\n }\n";
- //privilege names
- code+="static public function privilegeNames(){\n\treturn array(";
- QStringList priv=woc->privilegeNames();
- for(int i=0;i<priv.size();i++){
- if(i)code+=",\n\t\t";else code+="\n\t\t";
- code+="translate(\"_PrivilegeNames\",\""+priv[i]+"\")";
- }
- code+="\n\t);\n}\n";
-
- m_transact.write(code.toAscii());
-}
-
-void WocPHPClientTransaction::finalize()
-{
- if(m_transact.isOpen()){
- m_transact.write(TRANSACTEND);
- transInfo2();
- m_transact.write("};\n");
- m_transact.write(PHPEND);
- m_transact.close();
- }
-}
-
-
-void WocPHPClientTransaction::newTransaction(const WocTransaction&trn)
+QString WocPHPClientTransaction::trnHandlers(const WocTransaction&trn)
{
//create file
QString cn=trnClassName(trn);
QString fn="wtr_"+trn.name();
- addLoad(cn,fn);
- fn=m_subdir+"/"+fn+m_fileext;
- QFile tf(m_basedir+"/"+fn);
- if(!tf.open(QIODevice::ReadWrite|QIODevice::Truncate)){
- qDebug("Error: cannot create PHP object file %s.",fn.toAscii().data());
- emit errorFound();
- return;
- }
- tf.write(PHPSTART);
-
+
////
//generate code
- QString code="/* TRANSLATOR "+cn+" */\nclass "+cn+" extends "+m_transbase+"{\n";
- //constructor
- code+=trnConstruct(trn);
- tf.write(code.toAscii());
+ QString code;
//request handler:
code="public function handleRequest(){\n";
code+=trnInput(trn);
//call
- if(trn.hasCall("php")){
+ if(trn.hasCall(m_lang)){
code+="\t/*call actual functionality:*/\n";
- code+="\ttry{"+trn.callFunction("php")+"}catch(Exception $e){$this->handleException($e);}\n";
+ code+="\ttry{"+trn.callFunction(m_lang)+"}catch(Exception $e){$this->handleException($e);}\n";
}else{
code+="\t/*normally here would be the PHP call, but it is missing from the config*/\n";
code+="\t$this->abortNotImplemented();\nreturn;\n";
code+=trnOutput(trn);
code+="\t$this->commitTransaction();\n}\n";
- tf.write(code.toAscii());
-
- //getters/setters
- tf.write(trnGetSet(trn).toAscii());
-
- //direct execution
- tf.write(trnExecute(trn).toAscii());
-
- //privileges
- tf.write(trnPrivileges(trn).toAscii());
-
- //end
- code="\n//end of class\n}\n";
- tf.write(code.toAscii());
- tf.write(PHPEND);
- tf.close();
-
- ////
- //generate loader code
- code="\tcase \""+trn.name()+"\":$trn=new "+cn+";$trn->handleRequest();break;\n";
- m_transact.write(code.toAscii());
-}
-
-QString WocPHPClientTransaction::trnConstruct(const WocTransaction&trn)
-{
- QString code="public function __construct(){\n\tparent::__construct();\n";
- code+="\t$this->ainput=array(";
- QStringList sl=trn.inputNames();
- for(int i=0;i<sl.size();i++){
- if(i)code+=",";
- code+="\""+sl[i]+"\"=>";
- if(trn.isListType(trn.inputType(sl[i])))code+="array()";
- else code+="false";
- }
- code+=");\n";
- code+="\t$this->tinput=array(";
- for(int i=0;i<sl.size();i++){
- if(i)code+=",";
- code+="\""+sl[i]+"\"=>\"";
- code+=trn.inputType(sl[i]);
- code+="\"";
- }
- code+=");\n";
-
- code+="\t$this->aoutput=array(";
- sl=trn.outputNames();
- for(int i=0;i<sl.size();i++){
- if(i)code+=",";
- code+="\""+sl[i]+"\"=>";
- if(trn.isListType(trn.outputType(sl[i])))code+="array()";
- else code+="false";
- }
- code+=");\n";
- code+="\t$this->toutput=array(";
- for(int i=0;i<sl.size();i++){
- if(i)code+=",";
- code+="\""+sl[i]+"\"=>\"";
- code+=trn.outputType(sl[i]);
- code+="\"";
- }
- code+=");\n}\n";
return code;
}
code+="\t/*end of output*/\n";
return code;
}
-
-QString WocPHPClientTransaction::trnGetSet(const WocTransaction&trn)
-{
- QString code;
- //getters
- QStringList sl=trn.inputNames();
- for(int i=0;i<sl.size();i++){
- code+="public function get"+sl[i]+"(){return $this->ainput[\""+sl[i]+"\"];}\n";
- }
- //setters
- sl=trn.outputNames();
- for(int i=0;i<sl.size();i++){
- code+="public function result"+sl[i]+"(){return $this->aoutput[\""+sl[i]+"\"];}\n";
- QString add;
- QString t=trn.outputType(sl[i]);
- code+="public function set"+sl[i]+"($v){\n";
- if(trn.isListType(t)){
- add="public function add"+sl[i]+"($vv){\n";
- code+="\t$this->aoutput[\""+sl[i]+"\"]=array();\n";
- code+="\tforeach($v as $vv){\n";
- if(trn.isIntType(t)){
- code+="\t\tif(is_numeric($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv+0;\n";
- add+="\tif(is_numeric($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv+0;\n";
- }else
- if(trn.isBoolType(t)){
- code+="\t\tif(is_bool($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv!=false;\n";
- add+="\tif(is_bool($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv!=false;\n";
- }else
- if(trn.isObjectType(t)){
- code+="\t\tif(is_a($vv,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"][]=$vv;\n";
- add+="\tif(is_a($vv,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"][]=$vv;\n";
- }else{
- code+="\t\t$this->aoutput[\""+sl[i]+"\"][]=\"\".$vv;\n";
- add+="\t$this->aoutput[\""+sl[i]+"\"][]=\"\".$vv;\n";
- }
- code+="\t}\n";
- add+="}\n";
- }else{
- if(trn.isIntType(t)){
- code+="\tif(is_numeric($v))$this->aoutput[\""+sl[i]+"\"]=$v+0;\n";
- }else
- if(trn.isBoolType(t)){
- code+="\tif(is_bool($v))$this->aoutput[\""+sl[i]+"\"]=$v!=false;\n";
- }else
- if(trn.isObjectType(t)){
- code+="\tif(is_a($v,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"]=$v;\n";
- }else{
- code+="\t$this->aoutput[\""+sl[i]+"\"]=\"\".$v;\n";
- }
- }
- code+="}\n"+add;
- }
-
-
- return code;
-}
-
-QString WocPHPClientTransaction::trnExecute(const WocTransaction&trn)
-{
- //the execute function is split into a static and non-static part,
- //since the code from the wolf file assumes to be inside the instance
- QStringList in=trn.inputNames();
- //static wrapper for execution
- QString code="static public function execute(";
- for(int i=0;i<in.size();i++){
- if(i)code+=",";
- code+="$"+in[i];
- }
- code+=")\n{\n\t$inst=new "+trnClassName(trn)+";\n";
- code+="\t$inst->do_execute(";
- for(int i=0;i<in.size();i++){
- if(i)code+=",";
- code+="$"+in[i];
- }
- code+=");\n";
- code+="\treturn $inst;\n}\n";
- //actual non-static implementation
- code+="private function do_execute(";
- for(int i=0;i<in.size();i++){
- if(i)code+=",";
- code+="$"+in[i];
- }
- code+=")\n{\n";
- for(int i=0;i<in.size();i++)
- code+="\t$this->ainput[\""+in[i]+"\"]=$"+in[i]+";\n";
- code+="\tself::$running=\""+trn.name()+"\";\n";
- code+="\ttry{"+trn.callFunction("php")+"}\n\tcatch(Exception $ex){\n";
- code+="\t\tself::$running=\"\";\n\t\t$this->handleException($ex);\n\t}\n";
- code+="\tself::$running=\"\";\n}\n";
- return code;
-}
-
-QString WocPHPClientTransaction::trnPrivileges(const WocTransaction&trn)
-{
- //privilege inventory
- QString code;
- code+="static public function privileges(){\n\treturn array(";
- QString cn=trnClassName(trn);
- QStringList priv=trn.privileges();
- for(int i=0;i<priv.size();i++){
- if(i)code+=",\n\t\t";else code+="\n\t\t";
- code+="\""+priv[i]+"\"";
- }
- code+="\n\t);\n}\n";
- //constants for use by custom code
- for(int i=0;i<priv.size();i++)
- code+="const Priv_"+priv[i]+"=\""+priv[i]+"\";\n";
- //check method
- code+="public function havePrivilege($priv){\n";
- code+="\tif(!in_array($priv,self::privileges()))return false;\n";
- code+="\treturn $this->isAuthorized(\""+trn.name()+":\".$priv);\n}\n";
-
- return code;
-}
#ifndef WOC_PHPOUT_CTRANS_H
#define WOC_PHPOUT_CTRANS_H
-#include "phpout.h"
+#include "phptrans.h"
/**generates output for a PHP server side*/
public:
/**initializes the output object*/
WocPHPClientTransaction(WocPHPOut*);
- protected:
- /**writes any last words after parsing finished*/
- virtual void finalize();
- /**creates a transaction*/
- virtual void newTransaction(const WocTransaction&);
private:
-
- /**helper: create info functions (mainly version info) at the start*/
- void transInfo();
- /**helper: create info functions (mainly version info) at the end*/
- void transInfo2();
-
/**helper: create transaction constructor*/
- QString trnConstruct(const WocTransaction&);
+ QString trnHandlers(const WocTransaction&);
/**helper: create transaction input parser*/
QString trnInput(const WocTransaction&);
/**helper: create transaction output serializer*/
QString trnOutput(const WocTransaction&);
- /**helper: create getters and setters*/
- QString trnGetSet(const WocTransaction&);
- /**helper: create direct execution code for web interface*/
- QString trnExecute(const WocTransaction&);
- /**helper: create privilege check code for web interface*/
- QString trnPrivileges(const WocTransaction&);
};
#endif
//create newKey function
code+="public function newKey(){\n\tparent::newKey();\n";
for(int i=0;i<cols.size();i++){
- QString c=tbl.columnCall(cols[i],"php");
+ QString c=tbl.columnCall(cols[i],m_lang);
if(c=="")continue;
code+="\t$this->cdata[\""+cols[i]+"\"]="+c+";\n";
}
WocPHPServerOut::WocPHPServerOut(const QDomElement&el)
:WocPHPOut(el)
{
+ m_lang="php/server";
pclass=new WocPHPClass(this);
ptable=new WocPHPTable(this);
ptrans=new WocPHPServerTransaction(this);
}
+WocPHPClientOut::WocPHPClientOut(const QDomElement& el)
+ :WocPHPOut(el)
+{
+ m_lang="php/client";
+ pclass=new WocPHPClass(this);
+ ptrans=new WocPHPClientTransaction(this);
+}
+
+
WocPHPOut::WocPHPOut(const QDomElement&el)
{
pclass=0;ptable=0;ptrans=0;
{
if(ptable)ptable->newTable(tbl);
}
-
-WocPHPTransaction::WocPHPTransaction(WocPHPOut* p)
-{
- m_parent=p;
- connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound()));
-}
-
class WocPHPOut;
class WocPHPClass;
class WocPHPTable;
+class WocPHPTransaction;
class WocPHPClientTransaction;
class WocPHPServerTransaction;
-class WocPHPTransaction:public QObject
-{
- Q_OBJECT
- public:
- WocPHPTransaction(WocPHPOut*);
- virtual void finalize()=0;
- virtual void newTransaction(const WocTransaction&)=0;
- protected:
- WocPHPOut*m_parent;
- signals:
- void errorFound();
-};
-
/**generates output for a PHP server side*/
class WocPHPOut:public WocOutput
{
friend class WocPHPServerTransaction;
QString m_basedir,m_subdir,m_fileext;
- QString m_transbase;
+ QString m_transbase,m_lang;
QFile m_loader,m_schema,m_transact;
/**helper: adds a loader line for a class to autoload.php*/
WocPHPServerOut(const QDomElement&);
};
+class WocPHPClientOut:public WocPHPOut
+{
+ public:
+ /**initializes the output object*/
+ WocPHPClientOut(const QDomElement&);
+};
+
#endif
#include "phpconst.h"
-static const QByteArray TRANSACTCLASS("class WobTransaction extends WobTransactionBase\n{\n");
-static const QByteArray TRANSACTSTART(" static public function handle(){\n try{switch(WobTransactionBase::getTransactionName()){\n");
-static const QByteArray TRANSACTEND("\tdefault:WobTransactionBase::noSuchTransaction();break;\n }}catch(WobTransactionError $er){$er->printXml();}\n }\n");
-
-WocPHPServerTransaction::WocPHPServerTransaction(WocPHPOut*p ): WocPHPTransaction(p)
-{
- //create Transaction file
- m_transact.setFileName(m_basedir+"/"+m_subdir+"/transaction"+m_fileext);
- if(!m_transact.open(QIODevice::ReadWrite|QIODevice::Truncate)){
- qDebug("Error: PHP Server Generator - cannot create transaction processor file.");
- emit errorFound();
- return;
- }
- m_transact.write(PHPSTART);
- m_transact.write(TRANSACTCLASS);
- transInfo();
- m_transact.write(TRANSACTSTART);
- addLoad("WobTransaction","transaction");
-}
-
-void WocPHPServerTransaction::transInfo()
+WocPHPServerTransaction::WocPHPServerTransaction(WocPHPOut*p )
+ :WocPHPTransaction(p)
{
- WocProcessor*woc=WocProcessor::instance();
- m_transact.write(QString(" static public function commVersion(){return \""+woc->verComm()+"\";}\n").toAscii());
- m_transact.write(QString(" static public function needCommVersion(){return \""+woc->verNeedComm()+"\";}\n").toAscii());
- m_transact.write(QString(" static public function version(){return \""+woc->verHR()+"\";}\n").toAscii());
- m_transact.write(QString(" static public function svnVersion(){return \""+woc->svnRevision()+"\";}\n\n").toAscii());
- m_transact.write(QString(" static public function svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n\n").toAscii());
- m_transact.write(QString(" static public function svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii());
}
-void WocPHPServerTransaction::transInfo2()
-{
- WocProcessor*woc=WocProcessor::instance();
- //transaction names
- QString code=" static public function transactionNames(){\n\treturn array(";
- QStringList tns=woc->transactionNames();
- for(int i=0;i<tns.size();i++){
- if(i)code+=",";
- code+="\n\t\ttranslate(\"_TransactionNames\",\""+tns[i]+"\")";
- }
- code+=");\n }\n";
- //privilege names
- code+="static public function privilegeNames(){\n\treturn array(";
- QStringList priv=woc->privilegeNames();
- for(int i=0;i<priv.size();i++){
- if(i)code+=",\n\t\t";else code+="\n\t\t";
- code+="translate(\"_PrivilegeNames\",\""+priv[i]+"\")";
- }
- code+="\n\t);\n}\n";
-
- m_transact.write(code.toAscii());
-}
-
-void WocPHPServerTransaction::finalize()
-{
- if(m_transact.isOpen()){
- m_transact.write(TRANSACTEND);
- transInfo2();
- m_transact.write("};\n");
- m_transact.write(PHPEND);
- m_transact.close();
- }
-}
-
-
-void WocPHPServerTransaction::newTransaction(const WocTransaction&trn)
+QString WocPHPServerTransaction::trnHandlers(const WocTransaction&trn)
{
//create file
QString cn=trnClassName(trn);
QString fn="wtr_"+trn.name();
- addLoad(cn,fn);
- fn=m_subdir+"/"+fn+m_fileext;
- QFile tf(m_basedir+"/"+fn);
- if(!tf.open(QIODevice::ReadWrite|QIODevice::Truncate)){
- qDebug("Error: cannot create PHP object file %s.",fn.toAscii().data());
- emit errorFound();
- return;
- }
- tf.write(PHPSTART);
-
////
//generate code
- QString code="/* TRANSLATOR "+cn+" */\nclass "+cn+" extends "+m_transbase+"{\n";
- //constructor
- code+=trnConstruct(trn);
- tf.write(code.toAscii());
-
+ QString code;
//request handler:
code="public function handleRequest(){\n";
code+="\t$this->startTransaction("+QString(trn.isDbUpdating()?"true":"false")+");\n";
code+=trnInput(trn);
//call
- if(trn.hasCall("php")){
+ if(trn.hasCall(m_lang)){
code+="\t/*call actual functionality:*/\n";
- code+="\ttry{"+trn.callFunction("php")+"}catch(Exception $e){$this->handleException($e);}\n";
+ code+="\ttry{"+trn.callFunction(m_lang)+"}catch(Exception $e){$this->handleException($e);}\n";
}else{
code+="\t/*normally here would be the PHP call, but it is missing from the config*/\n";
code+="\t$this->abortNotImplemented();\nreturn;\n";
code+=trnOutput(trn);
code+="\t$this->commitTransaction();\n}\n";
- tf.write(code.toAscii());
-
- //getters/setters
- tf.write(trnGetSet(trn).toAscii());
//direct execution
- tf.write(trnExecute(trn).toAscii());
-
- //privileges
- tf.write(trnPrivileges(trn).toAscii());
-
- //end
- code="\n//end of class\n}\n";
- tf.write(code.toAscii());
- tf.write(PHPEND);
- tf.close();
-
- ////
- //generate loader code
- code="\tcase \""+trn.name()+"\":$trn=new "+cn+";$trn->handleRequest();break;\n";
- m_transact.write(code.toAscii());
-}
+ code+=trnExecute(trn).toAscii();
-QString WocPHPServerTransaction::trnConstruct(const WocTransaction&trn)
-{
- QString code="public function __construct(){\n\tparent::__construct();\n";
- code+="\t$this->ainput=array(";
- QStringList sl=trn.inputNames();
- for(int i=0;i<sl.size();i++){
- if(i)code+=",";
- code+="\""+sl[i]+"\"=>";
- if(trn.isListType(trn.inputType(sl[i])))code+="array()";
- else code+="false";
- }
- code+=");\n";
- code+="\t$this->tinput=array(";
- for(int i=0;i<sl.size();i++){
- if(i)code+=",";
- code+="\""+sl[i]+"\"=>\"";
- code+=trn.inputType(sl[i]);
- code+="\"";
- }
- code+=");\n";
-
-
- code+="\t$this->aoutput=array(";
- sl=trn.outputNames();
- for(int i=0;i<sl.size();i++){
- if(i)code+=",";
- code+="\""+sl[i]+"\"=>";
- if(trn.isListType(trn.outputType(sl[i])))code+="array()";
- else code+="false";
- }
- code+=");\n";
- code+="\t$this->toutput=array(";
- for(int i=0;i<sl.size();i++){
- if(i)code+=",";
- code+="\""+sl[i]+"\"=>\"";
- code+=trn.outputType(sl[i]);
- code+="\"";
- }
- code+=");\n}\n";
return code;
}
return code;
}
-QString WocPHPServerTransaction::trnGetSet(const WocTransaction&trn)
-{
- QString code;
- //getters
- QStringList sl=trn.inputNames();
- for(int i=0;i<sl.size();i++){
- code+="public function get"+sl[i]+"(){return $this->ainput[\""+sl[i]+"\"];}\n";
- }
- //setters
- sl=trn.outputNames();
- for(int i=0;i<sl.size();i++){
- code+="public function result"+sl[i]+"(){return $this->aoutput[\""+sl[i]+"\"];}\n";
- QString add;
- QString t=trn.outputType(sl[i]);
- code+="public function set"+sl[i]+"($v){\n";
- if(trn.isListType(t)){
- add="public function add"+sl[i]+"($vv){\n";
- code+="\t$this->aoutput[\""+sl[i]+"\"]=array();\n";
- code+="\tforeach($v as $vv){\n";
- if(trn.isIntType(t)){
- code+="\t\tif(is_numeric($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv+0;\n";
- add+="\tif(is_numeric($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv+0;\n";
- }else
- if(trn.isBoolType(t)){
- code+="\t\tif(is_bool($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv!=false;\n";
- add+="\tif(is_bool($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv!=false;\n";
- }else
- if(trn.isObjectType(t)){
- code+="\t\tif(is_a($vv,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"][]=$vv;\n";
- add+="\tif(is_a($vv,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"][]=$vv;\n";
- }else{
- code+="\t\t$this->aoutput[\""+sl[i]+"\"][]=\"\".$vv;\n";
- add+="\t$this->aoutput[\""+sl[i]+"\"][]=\"\".$vv;\n";
- }
- code+="\t}\n";
- add+="}\n";
- }else{
- if(trn.isIntType(t)){
- code+="\tif(is_numeric($v))$this->aoutput[\""+sl[i]+"\"]=$v+0;\n";
- }else
- if(trn.isBoolType(t)){
- code+="\tif(is_bool($v))$this->aoutput[\""+sl[i]+"\"]=$v!=false;\n";
- }else
- if(trn.isObjectType(t)){
- code+="\tif(is_a($v,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"]=$v;\n";
- }else{
- code+="\t$this->aoutput[\""+sl[i]+"\"]=\"\".$v;\n";
- }
- }
- code+="}\n"+add;
- }
-
-
- return code;
-}
-
QString WocPHPServerTransaction::trnExecute(const WocTransaction&trn)
{
//the execute function is split into a static and non-static part,
for(int i=0;i<in.size();i++)
code+="\t$this->ainput[\""+in[i]+"\"]=$"+in[i]+";\n";
code+="\tself::$running=\""+trn.name()+"\";\n";
- code+="\ttry{"+trn.callFunction("php")+"}\n\tcatch(Exception $ex){\n";
+ code+="\ttry{"+trn.callFunction(m_lang)+"}\n\tcatch(Exception $ex){\n";
code+="\t\tself::$running=\"\";\n\t\t$this->handleException($ex);\n\t}\n";
code+="\tself::$running=\"\";\n}\n";
return code;
}
-
-QString WocPHPServerTransaction::trnPrivileges(const WocTransaction&trn)
-{
- //privilege inventory
- QString code;
- code+="static public function privileges(){\n\treturn array(";
- QString cn=trnClassName(trn);
- QStringList priv=trn.privileges();
- for(int i=0;i<priv.size();i++){
- if(i)code+=",\n\t\t";else code+="\n\t\t";
- code+="\""+priv[i]+"\"";
- }
- code+="\n\t);\n}\n";
- //constants for use by custom code
- for(int i=0;i<priv.size();i++)
- code+="const Priv_"+priv[i]+"=\""+priv[i]+"\";\n";
- //check method
- code+="public function havePrivilege($priv){\n";
- code+="\tif(!in_array($priv,self::privileges()))return false;\n";
- code+="\treturn $this->isAuthorized(\""+trn.name()+":\".$priv);\n}\n";
-
- return code;
-}
#ifndef WOC_PHPOUT_STRANS_H
#define WOC_PHPOUT_STRANS_H
-#include "phpout.h"
+#include "phptrans.h"
/**generates output for a PHP server side*/
public:
/**initializes the output object*/
WocPHPServerTransaction(WocPHPOut*);
- protected:
- /**writes any last words after parsing finished*/
- virtual void finalize();
- /**creates a transaction*/
- virtual void newTransaction(const WocTransaction&);
private:
-
- /**helper: create info functions (mainly version info) at the start*/
- void transInfo();
- /**helper: create info functions (mainly version info) at the end*/
- void transInfo2();
-
- /**helper: create transaction constructor*/
- QString trnConstruct(const WocTransaction&);
+ /**helper: create handlers*/
+ virtual QString trnHandlers(const WocTransaction&);
/**helper: create transaction input parser*/
QString trnInput(const WocTransaction&);
/**helper: create transaction output serializer*/
QString trnOutput(const WocTransaction&);
- /**helper: create getters and setters*/
- QString trnGetSet(const WocTransaction&);
/**helper: create direct execution code for web interface*/
QString trnExecute(const WocTransaction&);
- /**helper: create privilege check code for web interface*/
- QString trnPrivileges(const WocTransaction&);
};
#endif
--- /dev/null
+//
+// C++ Implementation: phpout
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include "phpout.h"
+#include "phpctrans.h"
+
+#include <QDir>
+#include <QDomElement>
+
+#include "phpconst.h"
+
+static const QByteArray TRANSACTCLASS("class WobTransaction extends WobTransactionBase\n{\n");
+static const QByteArray TRANSACTSTART(" static public function handle(){\n try{switch(WobTransactionBase::getTransactionName()){\n");
+static const QByteArray TRANSACTEND("\tdefault:WobTransactionBase::noSuchTransaction();break;\n }}catch(WobTransactionError $er){$er->printXml();}\n }\n");
+
+WocPHPTransaction::WocPHPTransaction(WocPHPOut*p ): QObject(p)
+{
+ m_parent=p;
+ connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound()));
+ //create Transaction file
+ m_transact.setFileName(m_basedir+"/"+m_subdir+"/transaction"+m_fileext);
+ if(!m_transact.open(QIODevice::ReadWrite|QIODevice::Truncate)){
+ qDebug("Error: PHP Server Generator - cannot create transaction processor file.");
+ emit errorFound();
+ return;
+ }
+ m_transact.write(PHPSTART);
+ m_transact.write(TRANSACTCLASS);
+ transInfo();
+ m_transact.write(TRANSACTSTART);
+ addLoad("WobTransaction","transaction");
+}
+
+void WocPHPTransaction::transInfo()
+{
+ WocProcessor*woc=WocProcessor::instance();
+ m_transact.write(QString(" static public function commVersion(){return \""+woc->verComm()+"\";}\n").toAscii());
+ m_transact.write(QString(" static public function needCommVersion(){return \""+woc->verNeedComm()+"\";}\n").toAscii());
+ m_transact.write(QString(" static public function version(){return \""+woc->verHR()+"\";}\n").toAscii());
+ m_transact.write(QString(" static public function svnVersion(){return \""+woc->svnRevision()+"\";}\n\n").toAscii());
+ m_transact.write(QString(" static public function svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n\n").toAscii());
+ m_transact.write(QString(" static public function svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii());
+}
+
+void WocPHPTransaction::transInfo2()
+{
+ WocProcessor*woc=WocProcessor::instance();
+ //transaction names
+ QString code=" static public function transactionNames(){\n\treturn array(";
+ QStringList tns=woc->transactionNames();
+ for(int i=0;i<tns.size();i++){
+ if(i)code+=",";
+ code+="\n\t\ttranslate(\"_TransactionNames\",\""+tns[i]+"\")";
+ }
+ code+=");\n }\n";
+ //privilege names
+ code+="static public function privilegeNames(){\n\treturn array(";
+ QStringList priv=woc->privilegeNames();
+ for(int i=0;i<priv.size();i++){
+ if(i)code+=",\n\t\t";else code+="\n\t\t";
+ code+="translate(\"_PrivilegeNames\",\""+priv[i]+"\")";
+ }
+ code+="\n\t);\n}\n";
+
+ m_transact.write(code.toAscii());
+}
+
+void WocPHPTransaction::finalize()
+{
+ if(m_transact.isOpen()){
+ m_transact.write(TRANSACTEND);
+ transInfo2();
+ m_transact.write("};\n");
+ m_transact.write(PHPEND);
+ m_transact.close();
+ }
+}
+
+
+void WocPHPTransaction::newTransaction(const WocTransaction&trn)
+{
+ //create file
+ QString cn=trnClassName(trn);
+ QString fn="wtr_"+trn.name();
+ addLoad(cn,fn);
+ fn=m_subdir+"/"+fn+m_fileext;
+ QFile tf(m_basedir+"/"+fn);
+ if(!tf.open(QIODevice::ReadWrite|QIODevice::Truncate)){
+ qDebug("Error: cannot create PHP object file %s.",fn.toAscii().data());
+ emit errorFound();
+ return;
+ }
+ tf.write(PHPSTART);
+
+ ////
+ //generate code
+ QString code="/* TRANSLATOR "+cn+" */\nclass "+cn+" extends "+m_transbase+"{\n";
+ //constructor
+ code+=trnConstruct(trn);
+ tf.write(code.toAscii());
+
+ //request handler:
+ code+=trnHandlers(trn);
+
+ //getters/setters
+ tf.write(trnGetSet(trn).toAscii());
+
+ //privileges
+ tf.write(trnPrivileges(trn).toAscii());
+
+ //end
+ code="\n//end of class\n}\n";
+ tf.write(code.toAscii());
+ tf.write(PHPEND);
+ tf.close();
+
+ ////
+ //generate loader code
+ code="\tcase \""+trn.name()+"\":$trn=new "+cn+";$trn->handleRequest();break;\n";
+ m_transact.write(code.toAscii());
+}
+
+QString WocPHPTransaction::trnConstruct(const WocTransaction&trn)
+{
+ QString code="public function __construct(){\n\tparent::__construct();\n";
+ code+="\t$this->ainput=array(";
+ QStringList sl=trn.inputNames();
+ for(int i=0;i<sl.size();i++){
+ if(i)code+=",";
+ code+="\""+sl[i]+"\"=>";
+ if(trn.isListType(trn.inputType(sl[i])))code+="array()";
+ else code+="false";
+ }
+ code+=");\n";
+ code+="\t$this->tinput=array(";
+ for(int i=0;i<sl.size();i++){
+ if(i)code+=",";
+ code+="\""+sl[i]+"\"=>\"";
+ code+=trn.inputType(sl[i]);
+ code+="\"";
+ }
+ code+=");\n";
+
+
+ code+="\t$this->aoutput=array(";
+ sl=trn.outputNames();
+ for(int i=0;i<sl.size();i++){
+ if(i)code+=",";
+ code+="\""+sl[i]+"\"=>";
+ if(trn.isListType(trn.outputType(sl[i])))code+="array()";
+ else code+="false";
+ }
+ code+=");\n";
+ code+="\t$this->toutput=array(";
+ for(int i=0;i<sl.size();i++){
+ if(i)code+=",";
+ code+="\""+sl[i]+"\"=>\"";
+ code+=trn.outputType(sl[i]);
+ code+="\"";
+ }
+ code+=");\n}\n";
+ return code;
+}
+
+QString WocPHPTransaction::trnGetSet(const WocTransaction&trn)
+{
+ QString code;
+ //getters
+ QStringList sl=trn.inputNames();
+ for(int i=0;i<sl.size();i++){
+ code+="public function get"+sl[i]+"(){return $this->ainput[\""+sl[i]+"\"];}\n";
+ }
+ //setters
+ sl=trn.outputNames();
+ for(int i=0;i<sl.size();i++){
+ code+="public function result"+sl[i]+"(){return $this->aoutput[\""+sl[i]+"\"];}\n";
+ QString add;
+ QString t=trn.outputType(sl[i]);
+ code+="public function set"+sl[i]+"($v){\n";
+ if(trn.isListType(t)){
+ add="public function add"+sl[i]+"($vv){\n";
+ code+="\t$this->aoutput[\""+sl[i]+"\"]=array();\n";
+ code+="\tforeach($v as $vv){\n";
+ if(trn.isIntType(t)){
+ code+="\t\tif(is_numeric($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv+0;\n";
+ add+="\tif(is_numeric($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv+0;\n";
+ }else
+ if(trn.isBoolType(t)){
+ code+="\t\tif(is_bool($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv!=false;\n";
+ add+="\tif(is_bool($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv!=false;\n";
+ }else
+ if(trn.isObjectType(t)){
+ code+="\t\tif(is_a($vv,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"][]=$vv;\n";
+ add+="\tif(is_a($vv,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"][]=$vv;\n";
+ }else{
+ code+="\t\t$this->aoutput[\""+sl[i]+"\"][]=\"\".$vv;\n";
+ add+="\t$this->aoutput[\""+sl[i]+"\"][]=\"\".$vv;\n";
+ }
+ code+="\t}\n";
+ add+="}\n";
+ }else{
+ if(trn.isIntType(t)){
+ code+="\tif(is_numeric($v))$this->aoutput[\""+sl[i]+"\"]=$v+0;\n";
+ }else
+ if(trn.isBoolType(t)){
+ code+="\tif(is_bool($v))$this->aoutput[\""+sl[i]+"\"]=$v!=false;\n";
+ }else
+ if(trn.isObjectType(t)){
+ code+="\tif(is_a($v,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"]=$v;\n";
+ }else{
+ code+="\t$this->aoutput[\""+sl[i]+"\"]=\"\".$v;\n";
+ }
+ }
+ code+="}\n"+add;
+ }
+
+
+ return code;
+}
+
+QString WocPHPTransaction::trnPrivileges(const WocTransaction&trn)
+{
+ //privilege inventory
+ QString code;
+ code+="static public function privileges(){\n\treturn array(";
+ QString cn=trnClassName(trn);
+ QStringList priv=trn.privileges();
+ for(int i=0;i<priv.size();i++){
+ if(i)code+=",\n\t\t";else code+="\n\t\t";
+ code+="\""+priv[i]+"\"";
+ }
+ code+="\n\t);\n}\n";
+ //constants for use by custom code
+ for(int i=0;i<priv.size();i++)
+ code+="const Priv_"+priv[i]+"=\""+priv[i]+"\";\n";
+ //check method
+ code+="public function havePrivilege($priv){\n";
+ code+="\tif(!in_array($priv,self::privileges()))return false;\n";
+ code+="\treturn $this->isAuthorized(\""+trn.name()+":\".$priv);\n}\n";
+
+ return code;
+}
--- /dev/null
+//
+// C++ Interface: phpout
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#ifndef WOC_PHPOUT_TRANS_H
+#define WOC_PHPOUT_TRANS_H
+
+#include "phpout.h"
+
+
+/**generates output for a PHP server side*/
+class WocPHPTransaction:public QObject
+{
+ Q_OBJECT
+ public:
+ /**initializes the output object*/
+ WocPHPTransaction(WocPHPOut*);
+ /**writes any last words after parsing finished*/
+ virtual void finalize();
+ /**creates a transaction*/
+ virtual void newTransaction(const WocTransaction&);
+ private:
+
+ /**helper: create info functions (mainly version info) at the start*/
+ virtual void transInfo();
+ /**helper: create info functions (mainly version info) at the end*/
+ virtual void transInfo2();
+
+ /**helper: create transaction constructor*/
+ virtual QString trnConstruct(const WocTransaction&);
+ /**helper: create handlers*/
+ virtual QString trnHandlers(const WocTransaction&)=0;
+ /**helper: create getters and setters*/
+ virtual QString trnGetSet(const WocTransaction&);
+ /**helper: create privilege check code for web interface*/
+ virtual QString trnPrivileges(const WocTransaction&);
+ protected:
+ WocPHPOut*m_parent;
+ signals:
+ void errorFound();
+};
+
+#endif
for(int k=0;k<nl3.size();k++){
QDomElement el3=nl3.at(k).toElement();
if(el3.isNull())continue;
- QString lang=el3.attribute("lang");
+ QString lang=el3.attribute("lang").trimmed();
QString meth=el3.attribute("method","false");
sm.method.insert(lang,meth);
+ if(!lang.contains("/")){
+ sm.method.insert(lang+"/client",meth);
+ sm.method.insert(lang+"/server",meth);
+ }
}
map.append(sm);
}
nl=elementsByTagName(cls,"Abstract");
for(int i=0;i<nl.size();i++){
QString s=nl.at(i).toElement().attribute("lang").trimmed();
- if(s!="")m_cabstract<<s;
+ if(s!=""){
+ m_cabstract<<s;
+ if(!s.contains("/"))
+ m_cabstract<<(s+"/client")<<(s+"/server");
+ }
}
}
new WocQtClientOut(el);
if(m_error)return false;
}else
+ if(tn=="QtServerOutput"){
+ new WocQtServerOut(el);
+ if(m_error)return false;
+ }else
+ if(tn=="PHPClientOutput"){
+ new WocPHPClientOut(el);
+ if(m_error)return false;
+ }else
if(tn=="PHPServerOutput"){
new WocPHPServerOut(el);
if(m_error)return false;
QString lang=el2.attribute("lang");
QString meth=el2.attribute("method","false");
cl.methodcalls.insert(lang,meth);
+ if(!lang.contains("/")){
+ cl.methodcalls.insert(lang+"/client",meth);
+ cl.methodcalls.insert(lang+"/server",meth);
+ }
}
//docu
QDomNodeList nl3=el.childNodes();
}
QString mt=el.attribute("method");
m_call.insert(nm,mt);
+ if(!nm.contains("/")){
+ m_call.insert(nm+"/client",mt);
+ m_call.insert(nm+"/server",mt);
+ }
}
//output
nl=elementsByTagName(root,"Output");
{
QString cn=m_prefix+"O"+cls.name();
QString cna=cn;
- if(cls.isAbstract("qt"))cna+="Abstract";
+ if(cls.isAbstract(m_lang))cna+="Abstract";
addFile(cna);
MFile hdr(m_basedir+"/"+m_subdir+"/"+cna+".h");
MFile src(m_basedir+"/"+m_subdir+"/"+cna+".cpp");
#define qttype m_parent->qttype
#define qtobjtype m_parent->qtobjtype
#define addFile m_parent->addFile
+#define m_lang m_parent->m_lang
#endif
#endif
#include "qtout.h"
#include "qtdb.h"
+#include "qtconst.h"
+
WocQtTable::WocQtTable(WocQtOut*){}
WocQtTable::~WocQtTable(){}
void WocQtTable::finalize(){}
WocQtClientOut::WocQtClientOut(QDomElement&el)
:WocQtOut(el)
{
+ m_lang="qt/client";
qclass=new WocQtClass(this);
qtrans=new WocQtClientTransaction(this);
}
+WocQtServerOut::WocQtServerOut(QDomElement& el)
+ :WocQtOut(el)
+{
+ m_lang="qt/server";
+ qclass=new WocQtClass(this);
+ qtrans=new WocQtServerTransaction(this);
+ qtable=new WocQtTable(this);
+}
+
+
WocQtTransaction::WocQtTransaction(WocQtOut*p)
:m_parent(p)
{
friend class WocQtTransaction;
friend class WocQtTable;
- QString m_basedir,m_subdir,m_prefix,m_transbase;
+ QString m_basedir,m_subdir,m_prefix,m_transbase,m_lang;
MFile m_pri,m_iface,m_ifacecpp,m_hdr;
bool m_clean;
WocQtClientOut(QDomElement&);
};
+class WocQtServerOut:public WocQtOut
+{
+ public:
+ WocQtServerOut(QDomElement&);
+};
+
#endif
#include "qtout.h"
#include "qtstrans.h"
+#include "qtconst.h"
+
WocQtServerTransaction::WocQtServerTransaction(WocQtOut*p)
:WocQtTransaction(p)
{
qtstrans.cpp \
phpout.cpp \
phpclass.cpp \
+ phptrans.cpp \
phpctrans.cpp \
phpstrans.cpp \
phpdb.cpp \
phpout.h \
phpdb.h \
phpclass.h \
+ phptrans.h \
phpctrans.h \
phpstrans.h \
qtout.h \